From 849d69d1784029175ac78cc5c4fba4a029ac2509 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 2 Nov 2013 18:00:55 +0100 Subject: [PATCH] Fix regression in chained_path() introduced in fb763b01879f6943bf8f601f37e03947ccbf7511. Includes regression test. #1184 --- lib/Slic3r/Geometry.pm | 2 +- t/geometry.t | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 6e77e9b4a..17383f18a 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -800,7 +800,7 @@ sub chained_path { } while (@points) { my $idx = $start_near->nearest_point_index(\@points); - my ($start_near) = splice @points, $idx, 1; + ($start_near) = splice @points, $idx, 1; push @result, $indices{$start_near}; } diff --git a/t/geometry.t b/t/geometry.t index ad4a09156..20736b50d 100644 --- a/t/geometry.t +++ b/t/geometry.t @@ -2,7 +2,7 @@ use Test::More; use strict; use warnings; -plan tests => 25; +plan tests => 26; BEGIN { use FindBin; @@ -12,7 +12,8 @@ BEGIN { use Slic3r; use Slic3r::Geometry qw(PI polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices polygon_remove_acute_vertices - polygon_remove_parallel_continuous_edges polygon_is_convex); + polygon_remove_parallel_continuous_edges polygon_is_convex + chained_path_points epsilon scale); #========================================================== @@ -190,3 +191,13 @@ is Slic3r::Geometry::can_connect_points(@$points, $polygons), 0, 'can_connect_po } #========================================================== + +{ + # if chained_path() works correctly, these points should be joined with no diagonal paths + # (thus 26 units long) + my @points = map Slic3r::Point->new_scale(@$_), [26,26],[52,26],[0,26],[26,52],[26,0],[0,52],[52,52],[52,0]; + my @ordered = @{chained_path_points(\@points, $points[0])}; + ok !(grep { abs($ordered[$_]->distance_to($ordered[$_+1]) - scale 26) > epsilon } 0..$#ordered-1), 'chained_path'; +} + +#==========================================================