From 038caddcdae26a44bb0b68c952570319cd0ab42c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 13 Nov 2011 18:14:02 +0100 Subject: New fill types (hilbertcurve, archimedeanchords, octagramspiral) and ability to use different patterns for solid layers. #20 --- t/polyclip.t | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 9 deletions(-) (limited to 't/polyclip.t') diff --git a/t/polyclip.t b/t/polyclip.t index b7d4d58f6..205f036c8 100644 --- a/t/polyclip.t +++ b/t/polyclip.t @@ -2,7 +2,7 @@ use Test::More; use strict; use warnings; -plan tests => 14; +plan tests => 24; BEGIN { use FindBin; @@ -59,11 +59,57 @@ is_deeply $intersection, [ [12, 12], [18, 16] ], 'internal lines are preserved'; [16, 16], [16, 14], ]; - my $intersections = Slic3r::Geometry::clip_segment_complex_polygon($line, [ $square, $hole_in_square ]); - is_deeply $intersections, [ - [ [10, 15], [14, 15] ], - [ [16, 15], [20, 15] ], - ], 'line is clipped to square with hole'; + my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square); + is $expolygon->encloses_point([10, 10]), 1, 'corner point is recognized'; + is $expolygon->encloses_point([10, 18]), 1, 'point on contour is recognized'; + is $expolygon->encloses_point([14, 15]), 1, 'point on hole contour is recognized'; + is $expolygon->encloses_point([14, 14]), 1, 'point on hole corner is recognized'; + { + my $intersections = $expolygon->clip_line([ [15,18], [15,15] ]); + is_deeply $intersections, [ + [ [15, 18], [15, 16] ], + ], 'line is clipped to square with hole'; + } + { + my $intersections = $expolygon->clip_line([ [15,15], [15,12] ]); + is_deeply $intersections, [ + [ [15, 14], [15, 12] ], + ], 'line is clipped to square with hole'; + } + { + my $intersections = $expolygon->clip_line([ [12,18], [18,18] ]); + is_deeply $intersections, [ + [ [12,18], [18,18] ], + ], 'line is clipped to square with hole'; + } + { + my $intersections = $expolygon->clip_line($line); + is_deeply $intersections, [ + [ [10, 15], [14, 15] ], + [ [16, 15], [20, 15] ], + ], 'line is clipped to square with hole'; + } + { + my $intersections = $expolygon->clip_line([ reverse @$line ]); + is_deeply $intersections, [ + [ [20, 15], [16, 15] ], + [ [14, 15], [10, 15] ], + ], 'reverse line is clipped to square with hole'; + } + { + my $intersections = $expolygon->clip_line([ [10,18], [20,18] ]); + is_deeply $intersections, [ + [ [10, 18], [20, 18] ], + ], 'tangent line is clipped to square with hole'; + } + { + my $polyline = Slic3r::Polyline->cast([ [5, 18], [25, 18], [25, 15], [15, 15], [15, 12], [12, 12], [12, 5] ]); + is_deeply [ map $_->p, $polyline->clip_with_expolygon($expolygon) ], [ + [ [10, 18], [20, 18] ], + [ [20, 15], [16, 15] ], + [ [15, 14], [15, 12], [12, 12], [12, 10] ], + ], 'polyline is clipped to square with hole'; + } } #========================================================== @@ -93,11 +139,14 @@ is_deeply $intersection, [ [12, 12], [18, 16] ], 'internal lines are preserved'; ]; is is_counter_clockwise($small_circle), 0, "hole is clockwise"; + my $expolygon = Slic3r::ExPolygon->new($large_circle, $small_circle); $line = [ [152.741724,288.086671142818], [152.741724,34.166466971035] ]; - my $intersections = Slic3r::Geometry::clip_segment_complex_polygon($line, [ $large_circle, $small_circle ]); + my $intersections = $expolygon->clip_line($line); is_deeply $intersections, [ - [ [152.741724, 35.166466971035], [152.741724, 108.087543109156] ], - [ [152.741724, 215.178806915206], [152.741724, 288.086671142818] ], + [ [152.741724, 288.086671142818], [152.741724, 215.178806915206], ], + [ [152.741724, 108.087543109156], [152.741724, 35.166466971035] ], ], 'line is clipped to square with hole'; } + +#========================================================== -- cgit v1.2.3