diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2013-07-16 19:13:01 +0400 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2013-07-16 19:13:01 +0400 |
commit | 9458c7db973eb7dac832a4a47b9bf6ea4aceac0c (patch) | |
tree | 339711fc0af7fe1576d72ee1e8ec6e4d4244bbc4 /t | |
parent | 9b582a11ff80bcf08da2fefd958904d14a702c7b (diff) |
Fix integration of XS containers
Diffstat (limited to 't')
-rw-r--r-- | t/geometry.t | 25 | ||||
-rw-r--r-- | t/perimeters.t | 4 | ||||
-rw-r--r-- | t/polyclip.t | 42 |
3 files changed, 36 insertions, 35 deletions
diff --git a/t/geometry.t b/t/geometry.t index ac808fa1d..cdec8eb95 100644 --- a/t/geometry.t +++ b/t/geometry.t @@ -29,37 +29,38 @@ isnt Slic3r::Geometry::line_intersection($line1, $line2, 1), undef, 'line_inters #========================================================== { - my $polyline = [ + my $polygon = Slic3r::Polygon->new( [459190000, 5152739000], [147261000, 4612464000], [147261000, 3487535000], [339887000, 3153898000], [437497000, 3438430000], [454223000, 3522515000], [523621000, 3626378000], [627484000, 3695776000], [750000000, 3720147000], [872515000, 3695776000], [976378000, 3626378000], [1045776000, 3522515000], [1070147000, 3400000000], [1045776000, 3277484000], [976378000, 3173621000], [872515000, 3104223000], [827892000, 3095347000], [698461000, 2947261000], [2540810000, 2947261000], [2852739000, 3487535000], [2852739000, 4612464000], [2540810000, 5152739000], - ]; + ); # this points belongs to $polyline - my $point = [2797980957.103410,3392691792.513960]; + # note: it's actually a vertex, while we should better check an intermediate point + my $point = Slic3r::Point->new(1045776000, 3277484000); local $Slic3r::Geometry::epsilon = 1E-5; - is_deeply Slic3r::Geometry::polygon_segment_having_point($polyline, $point), - [ [2540810000, 2947261000], [2852739000, 3487535000] ], + is_deeply Slic3r::Geometry::polygon_segment_having_point($polygon, $point)->pp, + [ [1070147000, 3400000000], [1045776000, 3277484000] ], 'polygon_segment_having_point'; } #========================================================== { - my $point = [ 736310778.185108, 5017423926.8924 ]; - my $line = [ [627484000, 3695776000], [750000000, 3720147000] ]; + my $point = Slic3r::Point->new(736310778.185108, 5017423926.8924); + my $line = Slic3r::Line->new([627484000, 3695776000], [750000000, 3720147000]); is Slic3r::Geometry::point_in_segment($point, $line), 0, 'point_in_segment'; } #========================================================== { - my $point = [ 736310778.185108, 5017423926.8924 ]; - my $line = [ [627484000, 3695776000], [750000000, 3720147000] ]; + my $point = Slic3r::Point->new(736310778.185108, 5017423926.8924); + my $line = Slic3r::Line->new([627484000, 3695776000], [750000000, 3720147000]); is Slic3r::Geometry::point_in_segment($point, $line), 0, 'point_in_segment'; } @@ -158,7 +159,7 @@ is Slic3r::Geometry::can_connect_points(@$points, $polygons), 0, 'can_connect_po { my $polyline = Slic3r::Polyline->new([0, 0], [10, 0], [20, 0]); - is_deeply [ map $_->pp, $polyline->lines ], [ + is_deeply [ map $_->pp, @{$polyline->lines} ], [ [ [0, 0], [10, 0] ], [ [10, 0], [20, 0] ], ], 'polyline_lines'; @@ -167,8 +168,8 @@ is Slic3r::Geometry::can_connect_points(@$points, $polygons), 0, 'can_connect_po #========================================================== { - my $polyline = Slic3r::Polygon->new([0, 0], [10, 0], [5, 5]); - my $result = $polyline->split_at_index(1); + my $polygon = Slic3r::Polygon->new([0, 0], [10, 0], [5, 5]); + my $result = $polygon->split_at_index(1); is ref($result), 'Slic3r::Polyline', 'split_at_index returns polyline'; is_deeply $result->pp, [ [10, 0], [5, 5], [0, 0], [10, 0] ], 'split_at_index'; } diff --git a/t/perimeters.t b/t/perimeters.t index 1dacd31c0..9ff53f01a 100644 --- a/t/perimeters.t +++ b/t/perimeters.t @@ -57,10 +57,10 @@ use Slic3r::Test; if ($cur_loop) { $has_cw_loops = 1 if !Slic3r::Geometry::Clipper::is_counter_clockwise($cur_loop); if ($self->F == $config->external_perimeter_speed*60) { - my $move_dest = [ @$info{qw(new_X new_Y)} ]; + my $move_dest = Slic3r::Point->new_scale(@$info{qw(new_X new_Y)}); $external_loops{$self->Z}++; $has_outwards_move = 1 - if !Slic3r::Polygon->new(@$cur_loop)->encloses_point($move_dest) + if !Slic3r::Polygon->new_scale(@$cur_loop)->encloses_point($move_dest) ? ($external_loops{$self->Z} == 2) # contour should include destination : ($external_loops{$self->Z} == 1); # hole should not } diff --git a/t/polyclip.t b/t/polyclip.t index 4882892bd..2cfe6951f 100644 --- a/t/polyclip.t +++ b/t/polyclip.t @@ -14,21 +14,21 @@ use Slic3r; #========================================================== -is Slic3r::Geometry::point_in_segment([10, 10], [ [5, 10], [20, 10] ]), 1, 'point in horizontal segment'; -is Slic3r::Geometry::point_in_segment([30, 10], [ [5, 10], [20, 10] ]), 0, 'point not in horizontal segment'; -is Slic3r::Geometry::point_in_segment([10, 10], [ [10, 5], [10, 20] ]), 1, 'point in vertical segment'; -is Slic3r::Geometry::point_in_segment([10, 30], [ [10, 5], [10, 20] ]), 0, 'point not in vertical segment'; -is Slic3r::Geometry::point_in_segment([15, 15], [ [10, 10], [20, 20] ]), 1, 'point in diagonal segment'; -is Slic3r::Geometry::point_in_segment([20, 15], [ [10, 10], [20, 20] ]), 0, 'point not in diagonal segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 10), Slic3r::Line->new([5, 10], [20, 10])), 1, 'point in horizontal segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(30, 10), Slic3r::Line->new([5, 10], [20, 10])), 0, 'point not in horizontal segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 10), Slic3r::Line->new([10, 5], [10, 20])), 1, 'point in vertical segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(10, 30), Slic3r::Line->new([10, 5], [10, 20])), 0, 'point not in vertical segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(15, 15), Slic3r::Line->new([10, 10], [20, 20])), 1, 'point in diagonal segment'; +is Slic3r::Geometry::point_in_segment(Slic3r::Point->new(20, 15), Slic3r::Line->new([10, 10], [20, 20])), 0, 'point not in diagonal segment'; #========================================================== -my $square = [ # ccw +my $square = Slic3r::Polygon->new( # ccw [100, 100], [200, 100], [200, 200], [100, 200], -]; +); my $line = Slic3r::Line->new([50, 150], [300, 150]); @@ -37,17 +37,17 @@ is_deeply $intersection, [ [100, 150], [200, 150] ], 'line is clipped to square' #========================================================== -$intersection = Slic3r::Geometry::clip_segment_polygon([ [0, 150], [80, 150] ], $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([ [300, 150], [400, 150] ], $square); +$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([ [120, 120], [180, 160] ], $square); +$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'; #========================================================== @@ -66,45 +66,45 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv 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 $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [150, 180], [150, 160] ], ], 'line is clipped to square with hole'; } { my $intersections = $expolygon->clip_line(Slic3r::Line->new([150,150], [150,120])); - is_deeply $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [150, 140], [150, 120] ], ], 'line is clipped to square with hole'; } { my $intersections = $expolygon->clip_line(Slic3r::Line->new([120,180], [180,180])); - is_deeply $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [120,180], [180,180] ], ], 'line is clipped to square with hole'; } { my $intersections = $expolygon->clip_line($line); - is_deeply $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [100, 150], [140, 150] ], [ [160, 150], [200, 150] ], ], 'line is clipped to square with hole'; } { my $intersections = $expolygon->clip_line(Slic3r::Line->new(reverse @$line)); - is_deeply $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [200, 150], [160, 150] ], [ [140, 150], [100, 150] ], ], 'reverse line is clipped to square with hole'; } { my $intersections = $expolygon->clip_line(Slic3r::Line->new([100,180], [200,180])); - is_deeply $intersections, [ + is_deeply [ map $_->pp, @$intersections ], [ [ [100, 180], [200, 180] ], ], '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]); - is_deeply [ map $_, $polyline->clip_with_expolygon($expolygon) ], [ + is_deeply [ map $_->pp, $polyline->clip_with_expolygon($expolygon) ], [ [ [100, 180], [200, 180] ], [ [200, 150], [160, 150] ], [ [150, 140], [150, 120], [120, 120], [120, 100] ], @@ -143,9 +143,9 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv $line = Slic3r::Line->new([152.742,288.086671142818], [152.742,34.166466971035]); my $intersections = $expolygon->clip_line($line); - is_deeply $intersections, [ - [ [152.742, 287.908315789474], [152.742, 214.522], ], - [ [152.742, 107.478], [152.742, 35] ], + is_deeply [ map $_->pp, @$intersections ], [ + [ [152, 287], [152, 214], ], + [ [152, 107], [152, 35] ], ], 'line is clipped to square with hole'; } |