Use XS Point everywhere
This commit is contained in:
parent
d0701cdcd4
commit
9af2a1c007
37 changed files with 238 additions and 303 deletions
|
@ -4,13 +4,11 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 5;
|
||||
|
||||
my $point = Slic3r::Point::XS->new(10, 15);
|
||||
my $point = Slic3r::Point->new(10, 15);
|
||||
is_deeply [ @$point ], [10, 15], 'point roundtrip';
|
||||
|
||||
isa_ok $point->arrayref, 'Slic3r::Point', 'Perl point is blessed';
|
||||
|
||||
my $point2 = $point->clone;
|
||||
$point2->scale(2);
|
||||
is_deeply [ @$point2 ], [20, 30], 'scale';
|
||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 13;
|
||||
use Test::More tests => 15;
|
||||
|
||||
use constant PI => 4 * atan2(1, 1);
|
||||
|
||||
|
@ -22,15 +22,19 @@ my $hole_in_square = [ # cw
|
|||
];
|
||||
|
||||
my $expolygon = Slic3r::ExPolygon::XS->new($square, $hole_in_square);
|
||||
is_deeply [ @$expolygon ], [$square, $hole_in_square], 'expolygon roundtrip';
|
||||
is_deeply [ @{$expolygon->arrayref_pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
|
||||
|
||||
isa_ok $expolygon->arrayref, 'Slic3r::ExPolygon', 'Perl expolygon is blessed';
|
||||
isa_ok $expolygon->[0], 'Slic3r::Polygon', 'Perl polygons are blessed';
|
||||
isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
||||
my $arrayref = $expolygon->arrayref;
|
||||
isa_ok $arrayref, 'Slic3r::ExPolygon', 'Perl expolygon is blessed';
|
||||
|
||||
my $arrayref_pp = $expolygon->arrayref_pp;
|
||||
isa_ok $arrayref_pp, 'Slic3r::ExPolygon', 'Perl expolygon is blessed';
|
||||
isa_ok $arrayref_pp->[0], 'Slic3r::Polygon', 'Perl polygons are blessed';
|
||||
isnt ref($arrayref_pp->[0][0]), 'Slic3r::Point', 'Perl polygon points are not blessed';
|
||||
|
||||
{
|
||||
my $clone = $expolygon->clone;
|
||||
is_deeply [ @$clone ], [$square, $hole_in_square], 'clone';
|
||||
is_deeply [ @{$clone->arrayref_pp} ], [$square, $hole_in_square], 'clone';
|
||||
# The following tests implicitely check that modifying clones
|
||||
# does not modify the original one.
|
||||
}
|
||||
|
@ -38,7 +42,7 @@ isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
|||
{
|
||||
my $expolygon2 = $expolygon->clone;
|
||||
$expolygon2->scale(2.5);
|
||||
is_deeply [ @$expolygon2 ], [
|
||||
is_deeply [ @{$expolygon2->arrayref_pp} ], [
|
||||
[map [ 2.5*$_->[0], 2.5*$_->[1] ], @$square],
|
||||
[map [ 2.5*$_->[0], 2.5*$_->[1] ], @$hole_in_square]
|
||||
], 'scale';
|
||||
|
@ -47,7 +51,7 @@ isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
|||
{
|
||||
my $expolygon2 = $expolygon->clone;
|
||||
$expolygon2->translate(10, -5);
|
||||
is_deeply [ @$expolygon2 ], [
|
||||
is_deeply [ @{$expolygon2->arrayref_pp} ], [
|
||||
[map [ $_->[0]+10, $_->[1]-5 ], @$square],
|
||||
[map [ $_->[0]+10, $_->[1]-5 ], @$hole_in_square]
|
||||
], 'translate';
|
||||
|
@ -55,17 +59,17 @@ isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
|||
|
||||
{
|
||||
my $expolygon2 = $expolygon->clone;
|
||||
$expolygon2->rotate(PI/2, Slic3r::Point::XS->new(150,150));
|
||||
is_deeply [ @$expolygon2 ], [
|
||||
$expolygon2->rotate(PI/2, Slic3r::Point->new(150,150));
|
||||
is_deeply [ @{$expolygon2->arrayref_pp} ], [
|
||||
[ @$square[1,2,3,0] ],
|
||||
[ @$hole_in_square[3,0,1,2] ]
|
||||
], 'rotate around Point::XS';
|
||||
], 'rotate around Point';
|
||||
}
|
||||
|
||||
{
|
||||
my $expolygon2 = $expolygon->clone;
|
||||
$expolygon2->rotate(PI/2, [150,150]);
|
||||
is_deeply [ @$expolygon2 ], [
|
||||
is_deeply [ @{$expolygon2->arrayref_pp} ], [
|
||||
[ @$square[1,2,3,0] ],
|
||||
[ @$hole_in_square[3,0,1,2] ]
|
||||
], 'rotate around pure-Perl Point';
|
||||
|
@ -74,17 +78,19 @@ isa_ok $expolygon->[0][0], 'Slic3r::Point', 'Perl polygon points are blessed';
|
|||
{
|
||||
my $expolygon2 = $expolygon->clone;
|
||||
$expolygon2->scale(2);
|
||||
my $collection = Slic3r::ExPolygon::Collection->new($expolygon->arrayref, $expolygon2->arrayref);
|
||||
is_deeply [ @$collection ], [ $expolygon->arrayref, $expolygon2->arrayref ],
|
||||
my $collection = Slic3r::ExPolygon::Collection->new($expolygon->arrayref_pp, $expolygon2->arrayref_pp);
|
||||
is_deeply [ @{$collection->arrayref_pp} ], [ $expolygon->arrayref_pp, $expolygon2->arrayref_pp ],
|
||||
'expolygon collection';
|
||||
my $collection2 = Slic3r::ExPolygon::Collection->new($expolygon, $expolygon2);
|
||||
is_deeply [ @$collection ], [ @$collection2 ],
|
||||
is_deeply [ @{$collection->arrayref_pp} ], [ @{$collection2->arrayref_pp} ],
|
||||
'expolygon collection with XS expolygons';
|
||||
|
||||
$collection->clear;
|
||||
is scalar(@$collection), 0, 'clear collection';
|
||||
$collection->append($expolygon);
|
||||
is scalar(@$collection), 1, 'append to collection';
|
||||
|
||||
is_deeply $collection->[0]->clone->arrayref_pp, $expolygon->arrayref_pp, 'clone collection item';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
@ -28,7 +28,7 @@ my $surface = Slic3r::Surface->new(
|
|||
$surface = $surface->clone;
|
||||
|
||||
isa_ok $surface->expolygon, 'Slic3r::ExPolygon::XS', 'expolygon';
|
||||
is_deeply [ @{$surface->expolygon} ], [$square, $hole_in_square], 'expolygon roundtrip';
|
||||
is_deeply [ @{$surface->expolygon->arrayref_pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
|
||||
|
||||
is $surface->surface_type, Slic3r::Surface::S_TYPE_INTERNAL, 'surface_type';
|
||||
$surface->surface_type(Slic3r::Surface::S_TYPE_BOTTOM);
|
||||
|
@ -43,7 +43,7 @@ is $surface->extra_perimeters, 2, 'extra_perimeters';
|
|||
{
|
||||
my $collection = Slic3r::Surface::Collection->new($surface, $surface->clone);
|
||||
is scalar(@$collection), 2, 'collection has the right number of items';
|
||||
is_deeply $collection->[0]->expolygon->arrayref, [$square, $hole_in_square],
|
||||
is_deeply $collection->[0]->expolygon->arrayref_pp, [$square, $hole_in_square],
|
||||
'collection returns a correct surface expolygon';
|
||||
$collection->clear;
|
||||
is scalar(@$collection), 0, 'clear collection';
|
||||
|
|
|
@ -14,9 +14,10 @@ my $square = [ # ccw
|
|||
];
|
||||
|
||||
my $polygon = Slic3r::Polygon::XS->new(@$square);
|
||||
is_deeply [ @$polygon ], [ @$square ], 'polygon roundtrip';
|
||||
is_deeply [ @{$polygon->arrayref_pp} ], [ @$square ], 'polygon roundtrip';
|
||||
|
||||
isa_ok $polygon->arrayref, 'Slic3r::Polygon', 'Perl polygon is blessed';
|
||||
isa_ok $polygon->[0], 'Slic3r::Point', 'Perl points are blessed';
|
||||
my $arrayref = $polygon->arrayref;
|
||||
isa_ok $arrayref, 'Slic3r::Polygon', 'Perl polygon is blessed';
|
||||
isa_ok $arrayref->[0], 'Slic3r::Point', 'Perl points are blessed';
|
||||
|
||||
__END__
|
||||
|
|
|
@ -17,10 +17,10 @@ my $path = Slic3r::ExtrusionPath->new(
|
|||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
);
|
||||
isa_ok $path->as_polyline, 'Slic3r::Polyline::XS', 'path polyline';
|
||||
is_deeply [ @{ $path->as_polyline } ], [ @$points ], 'path points roundtrip';
|
||||
is_deeply [ @{ $path->as_polyline->arrayref_pp } ], [ @$points ], 'path points roundtrip';
|
||||
|
||||
$path->reverse;
|
||||
is_deeply [ @{ $path->as_polyline } ], [ reverse @$points ], 'reverse path';
|
||||
is_deeply [ @{ $path->as_polyline->arrayref_pp } ], [ reverse @$points ], 'reverse path';
|
||||
|
||||
$path->append([ 150, 150 ]);
|
||||
is scalar(@{ $path }), 4, 'append to path';
|
||||
|
|
|
@ -18,7 +18,7 @@ my $loop = Slic3r::ExtrusionLoop->new(
|
|||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
);
|
||||
isa_ok $loop->as_polygon, 'Slic3r::Polygon::XS', 'loop polygon';
|
||||
is_deeply [ @{ $loop->as_polygon } ], [ @$square ], 'polygon points roundtrip';
|
||||
is_deeply [ @{ $loop->as_polygon->arrayref_pp } ], [ @$square ], 'polygon points roundtrip';
|
||||
|
||||
$loop = $loop->clone;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue