Browse Source

Fix regression in chained_path() introduced in fb763b01879f6943bf8f601f37e03947ccbf7511. Includes regression test. #1184

Alessandro Ranellucci 11 years ago
parent
commit
849d69d178
2 changed files with 14 additions and 3 deletions
  1. 1 1
      lib/Slic3r/Geometry.pm
  2. 13 2
      t/geometry.t

+ 1 - 1
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};
     }
     

+ 13 - 2
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';
+}
+
+#==========================================================