diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index e810ca384..36b3dbe9b 100644 --- a/lib/Slic3r/Polygon.pm +++ b/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; diff --git a/xs/src/Polygon.cpp b/xs/src/Polygon.cpp index 9937668dc..8f6d51fd5 100644 --- a/xs/src/Polygon.cpp +++ b/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; +} + } diff --git a/xs/src/Polygon.hpp b/xs/src/Polygon.hpp index 43c4c7e9f..37754af08 100644 --- a/xs/src/Polygon.hpp +++ b/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 Polygons; diff --git a/xs/t/06_polygon.t b/xs/t/06_polygon.t index 913440944..76e4c1554 100644 --- a/xs/t/06_polygon.t +++ b/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__ diff --git a/xs/xsp/Polygon.xsp b/xs/xsp/Polygon.xsp index 1d454eb9b..7e96af24d 100644 --- a/xs/xsp/Polygon.xsp +++ b/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*