Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2013-11-21 17:15:38 +0400
committerAlessandro Ranellucci <aar@cpan.org>2013-11-21 17:15:38 +0400
commit3025c7767538cd671acbf81ce5e5f673a9a98e32 (patch)
tree3ad273c6e14a516526e361d0665b6aefea2e95ad /t/polyclip.t
parent1d6a18071a48d4c03f310b77cc88e5969906ee93 (diff)
Use Clipper for line clipping
Diffstat (limited to 't/polyclip.t')
-rw-r--r--t/polyclip.t78
1 files changed, 28 insertions, 50 deletions
diff --git a/t/polyclip.t b/t/polyclip.t
index 548b6ba65..772a9eebc 100644
--- a/t/polyclip.t
+++ b/t/polyclip.t
@@ -2,7 +2,7 @@ use Test::More;
use strict;
use warnings;
-plan tests => 24;
+plan tests => 23;
BEGIN {
use FindBin;
@@ -31,24 +31,6 @@ my $square = Slic3r::Polygon->new( # ccw
my $line = Slic3r::Line->new([50, 150], [300, 150]);
-my $intersection = Slic3r::Geometry::clip_segment_polygon($line, $square);
-is_deeply $intersection, [ [100, 150], [200, 150] ], 'line is clipped to square';
-
-#==========================================================
-
-$intersection = Slic3r::Geometry::clip_segment_polygon(Slic3r::Line->new([0, 150], [80, 150]), $square);
-is $intersection, undef, 'external lines are ignored 1';
-
-#==========================================================
-
-$intersection = Slic3r::Geometry::clip_segment_polygon(Slic3r::Line->new([300, 150], [400, 150]), $square);
-is $intersection, undef, 'external lines are ignored 2';
-
-#==========================================================
-
-$intersection = Slic3r::Geometry::clip_segment_polygon(Slic3r::Line->new([120, 120], [180, 160]), $square);
-is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserved';
-
#==========================================================
{
@@ -64,42 +46,38 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv
is $expolygon->encloses_point(Slic3r::Point->new(140, 150)), 1, 'point on hole contour is recognized';
is $expolygon->encloses_point(Slic3r::Point->new(140, 140)), 1, 'point on hole corner is recognized';
{
- my $intersections = $expolygon->clip_line(Slic3r::Line->new([150,180], [150,150]));
- is_deeply [ map $_->pp, @$intersections ], [
- [ [150, 180], [150, 160] ],
- ], 'line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line(Slic3r::Line->new([150,180], [150,150]));
+ is $intersection->[0]->length, Slic3r::Line->new([150, 180], [150, 160])->length,
+ 'line is clipped to square with hole';
}
{
- my $intersections = $expolygon->clip_line(Slic3r::Line->new([150,150], [150,120]));
- is_deeply [ map $_->pp, @$intersections ], [
- [ [150, 140], [150, 120] ],
- ], 'line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line(Slic3r::Line->new([150,150], [150,120]));
+ is $intersection->[0]->length, Slic3r::Line->new([150, 140], [150, 120])->length,
+ 'line is clipped to square with hole';
}
{
- my $intersections = $expolygon->clip_line(Slic3r::Line->new([120,180], [180,180]));
- is_deeply [ map $_->pp, @$intersections ], [
- [ [120,180], [180,180] ],
- ], 'line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line(Slic3r::Line->new([120,180], [180,180]));
+ is $intersection->[0]->length, Slic3r::Line->new([120,180], [180,180])->length,
+ 'line is clipped to square with hole';
}
{
- my $intersections = $expolygon->clip_line($line);
- is_deeply [ map $_->pp, @$intersections ], [
- [ [100, 150], [140, 150] ],
- [ [160, 150], [200, 150] ],
- ], 'line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line($line);
+ is $intersection->[0]->length, Slic3r::Line->new([100, 150], [140, 150])->length,
+ 'line is clipped to square with hole';
+ is $intersection->[1]->length, Slic3r::Line->new([160, 150], [200, 150])->length,
+ 'line is clipped to square with hole';
}
{
- my $intersections = $expolygon->clip_line(Slic3r::Line->new(reverse @$line));
- is_deeply [ map $_->pp, @$intersections ], [
- [ [200, 150], [160, 150] ],
- [ [140, 150], [100, 150] ],
- ], 'reverse line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line(Slic3r::Line->new(reverse @$line));
+ is $intersection->[0]->length, Slic3r::Line->new([200, 150], [160, 150])->length,
+ 'reverse line is clipped to square with hole';
+ is $intersection->[1]->length, Slic3r::Line->new([140, 150], [100, 150])->length,
+ 'reverse line is clipped to square with hole';
}
{
- my $intersections = $expolygon->clip_line(Slic3r::Line->new([100,180], [200,180]));
- is_deeply [ map $_->pp, @$intersections ], [
- [ [100, 180], [200, 180] ],
- ], 'tangent line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line(Slic3r::Line->new([100,180], [200,180]));
+ is $intersection->[0]->length, Slic3r::Line->new([100,180], [200,180])->length,
+ 'tangent line is clipped to square with hole';
}
{
my $polyline = Slic3r::Polyline->new([50, 180], [250, 180], [250, 150], [150, 150], [150, 120], [120, 120], [120, 50]);
@@ -141,11 +119,11 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv
my $expolygon = Slic3r::ExPolygon->new($large_circle, $small_circle);
$line = Slic3r::Line->new_scale([152.742,288.086671142818], [152.742,34.166466971035]);
- my $intersections = $expolygon->clip_line($line);
- is_deeply [ map $_->pp, @$intersections ], [
- [ [152742000, 288086661], [152742000, 215178843], ],
- [ [152742000, 108087507], [152742000, 35166477] ],
- ], 'line is clipped to square with hole';
+ my $intersection = $expolygon->clip_line($line);
+ is $intersection->[0]->length, Slic3r::Line->new([152742000, 288086661], [152742000, 215178843])->length,
+ 'line is clipped to square with hole';
+ is $intersection->[1]->length, Slic3r::Line->new([152742000, 108087507], [152742000, 35166477])->length,
+ 'line is clipped to square with hole';
}
#==========================================================