New ->scale() method for ExPolygon::XS

This commit is contained in:
Alessandro Ranellucci 2013-07-11 14:08:11 +02:00
parent 5409c27852
commit e0052b01d3
3 changed files with 24 additions and 1 deletions

View File

@ -19,8 +19,24 @@ class ExPolygon
Polygon contour; Polygon contour;
Polygons holes; Polygons holes;
SV* arrayref(); SV* arrayref();
void scale(double factor);
}; };
#define scale_polygon(poly, factor) \
for (Polygon::iterator pit = (poly).begin(); pit != (poly).end(); ++pit) { \
(*pit).x *= factor; \
(*pit).y *= factor; \
}
void
ExPolygon::scale(double factor)
{
scale_polygon(contour, factor);
for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
scale_polygon(*it, factor);
}
}
void void
perl2polygon(SV* poly_sv, Polygon& poly) perl2polygon(SV* poly_sv, Polygon& poly)
{ {

View File

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 5; use Test::More tests => 6;
my $square = [ # ccw my $square = [ # ccw
[100, 100], [100, 100],
@ -30,4 +30,10 @@ my $clone = $expolygon->clone;
is_deeply [ @$clone ], [$square, $hole_in_square], 'clone'; is_deeply [ @$clone ], [$square, $hole_in_square], 'clone';
# TODO: check that modifying the clone doesn't modify the original one # TODO: check that modifying the clone doesn't modify the original one
$expolygon->scale(1.5);
is_deeply [ @$expolygon ], [
[map [ 1.5*$_->[0], 1.5*$_->[1] ], @$square],
[map [ 1.5*$_->[0], 1.5*$_->[1] ], @$hole_in_square]
], 'scale';
__END__ __END__

View File

@ -8,6 +8,7 @@
%name{Slic3r::ExPolygon::XS} class ExPolygon { %name{Slic3r::ExPolygon::XS} class ExPolygon {
%name{_clone} ExPolygon(ExPolygon& self); %name{_clone} ExPolygon(ExPolygon& self);
~ExPolygon(); ~ExPolygon();
void scale(double factor);
%{ %{
ExPolygon* ExPolygon*