Browse Source

Ported make_clockwise() and make_counter_clockwise()

Alessandro Ranellucci 11 years ago
parent
commit
f7ada2b5db
5 changed files with 29 additions and 19 deletions
  1. 0 18
      lib/Slic3r/Polygon.pm
  2. 20 0
      xs/src/Polygon.cpp
  3. 2 0
      xs/src/Polygon.hpp
  4. 5 1
      xs/t/06_polygon.t
  5. 2 0
      xs/xsp/Polygon.xsp

+ 0 - 18
lib/Slic3r/Polygon.pm

@@ -15,24 +15,6 @@ sub wkt {
     return sprintf "POLYGON((%s))", join ',', map "$_->[0] $_->[1]", @$self;
 }
 
-sub make_counter_clockwise {
-    my $self = shift;
-    if (!$self->is_counter_clockwise) {
-        $self->reverse;
-        return 1;
-    }
-    return 0;
-}
-
-sub make_clockwise {
-    my $self = shift;
-    if ($self->is_counter_clockwise) {
-        $self->reverse;
-        return 1;
-    }
-    return 0;
-}
-
 sub merge_continuous_lines {
     my $self = shift;
     

+ 20 - 0
xs/src/Polygon.cpp

@@ -52,4 +52,24 @@ Polygon::is_counter_clockwise()
     return orientation;
 }
 
+bool
+Polygon::make_counter_clockwise()
+{
+    if (!this->is_counter_clockwise()) {
+        this->reverse();
+        return true;
+    }
+    return false;
+}
+
+bool
+Polygon::make_clockwise()
+{
+    if (this->is_counter_clockwise()) {
+        this->reverse();
+        return true;
+    }
+    return false;
+}
+
 }

+ 2 - 0
xs/src/Polygon.hpp

@@ -16,6 +16,8 @@ class Polygon : public MultiPoint {
     Polyline* split_at_index(int index);
     Polyline* split_at_first_point();
     bool is_counter_clockwise();
+    bool make_counter_clockwise();
+    bool make_clockwise();
 };
 
 typedef std::vector<Polygon> Polygons;

+ 5 - 1
xs/t/06_polygon.t

@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use Slic3r::XS;
-use Test::More tests => 8;
+use Test::More tests => 10;
 
 my $square = [  # ccw
     [100, 100],
@@ -35,6 +35,10 @@ ok $polygon->is_counter_clockwise, 'is_counter_clockwise';
     my $clone = $polygon->clone;
     $clone->reverse;
     ok !$clone->is_counter_clockwise, 'is_counter_clockwise';
+    $clone->make_counter_clockwise;
+    ok $clone->is_counter_clockwise, 'make_counter_clockwise';
+    $clone->make_counter_clockwise;
+    ok $clone->is_counter_clockwise, 'make_counter_clockwise';
 }
 
 __END__

+ 2 - 0
xs/xsp/Polygon.xsp

@@ -22,6 +22,8 @@
     Polyline* split_at_first_point()
         %code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
     bool is_counter_clockwise();
+    bool make_counter_clockwise();
+    bool make_clockwise();
 %{
 
 Polygon*