diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index 30318ce25..1d1ef3eae 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -15,15 +15,6 @@ package Slic3r::ExPolygon::XS; use overload '@{}' => sub { $_[0]->arrayref }; -# to handle legacy code -sub rotate { - my $self = shift; - my ($angle, $center) = @_; - - $center = Slic3r::Point::XS->new(@$center) if ref($center) ne 'Slic3r::Point::XS'; - $self->_rotate($angle, $center); -} - package Slic3r::ExPolygon::Collection; use overload '@{}' => sub { $_[0]->arrayref }; diff --git a/xs/src/ExPolygon.hpp b/xs/src/ExPolygon.hpp index 27cea9e3f..b339bfdc7 100644 --- a/xs/src/ExPolygon.hpp +++ b/xs/src/ExPolygon.hpp @@ -20,7 +20,7 @@ class ExPolygon SV* arrayref(); void scale(double factor); void translate(double x, double y); - void _rotate(double angle, Point* center); + void rotate(double angle, Point* center); }; typedef std::vector ExPolygons; @@ -44,11 +44,11 @@ ExPolygon::translate(double x, double y) } void -ExPolygon::_rotate(double angle, Point* center) +ExPolygon::rotate(double angle, Point* center) { - contour._rotate(angle, center); + contour.rotate(angle, center); for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) { - (*it)._rotate(angle, center); + (*it).rotate(angle, center); } } diff --git a/xs/src/ExPolygonCollection.hpp b/xs/src/ExPolygonCollection.hpp index e9a4a2915..92527afc6 100644 --- a/xs/src/ExPolygonCollection.hpp +++ b/xs/src/ExPolygonCollection.hpp @@ -42,7 +42,7 @@ void ExPolygonCollection::rotate(double angle, Point* center) { for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) { - (*it)._rotate(angle, center); + (*it).rotate(angle, center); } } diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp index 0225c5203..d8511b4c2 100644 --- a/xs/src/Point.hpp +++ b/xs/src/Point.hpp @@ -40,6 +40,14 @@ point2perl(Point& point) { return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Point", GV_ADD)); } +void +perl2point(SV* point_sv, Point& point) +{ + AV* point_av = (AV*)SvRV(point_sv); + point.x = (unsigned long)SvIV(*av_fetch(point_av, 0, 0)); + point.y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0)); +} + } #endif diff --git a/xs/src/Polygon.hpp b/xs/src/Polygon.hpp index 78524f5aa..2dca5da9d 100644 --- a/xs/src/Polygon.hpp +++ b/xs/src/Polygon.hpp @@ -18,7 +18,7 @@ class Polygon Points points; void scale(double factor); void translate(double x, double y); - void _rotate(double angle, Point* center); + void rotate(double angle, Point* center); }; typedef std::vector Polygons; @@ -42,7 +42,7 @@ Polygon::translate(double x, double y) } void -Polygon::_rotate(double angle, Point* center) +Polygon::rotate(double angle, Point* center) { for (Points::iterator it = points.begin(); it != points.end(); ++it) { (*it).rotate(angle, center); @@ -58,10 +58,7 @@ perl2polygon(SV* poly_sv, Polygon& poly) for (unsigned int i = 0; i < num_points; i++) { SV** point_sv = av_fetch(poly_av, i, 0); - AV* point_av = (AV*)SvRV(*point_sv); - Point& p = poly.points[i]; - p.x = (unsigned long)SvIV(*av_fetch(point_av, 0, 0)); - p.y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0)); + perl2point(*point_sv, poly.points[i]); } } diff --git a/xs/xsp/ExPolygon.xsp b/xs/xsp/ExPolygon.xsp index b12d8c0b6..93eef621e 100644 --- a/xs/xsp/ExPolygon.xsp +++ b/xs/xsp/ExPolygon.xsp @@ -13,7 +13,6 @@ %code{% RETVAL = expolygon2perl(*THIS); %}; void scale(double factor); void translate(double x, double y); - void _rotate(double angle, Point* center); %{ ExPolygon* @@ -29,6 +28,22 @@ ExPolygon::new(...) OUTPUT: RETVAL +void +ExPolygon::rotate(angle, center_sv) + double angle; + SV* center_sv; + CODE: + Point* center; + if (sv_isobject(center_sv) && (SvTYPE(SvRV(center_sv)) == SVt_PVMG)) { + center = (Point*)SvIV((SV*)SvRV( center_sv )); + THIS->rotate(angle, center); + } else { + center = new Point; + perl2point(center_sv, *center); + THIS->rotate(angle, center); + delete center; + } + %} };