From 2eca0941704ceae88a061db70284b6e0d91853ae Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 22 Feb 2015 17:03:23 +0100 Subject: [PATCH] Added failing test case for Clipper regression causing extra points in polyline intersection, thus crash with circular bed shape --- lib/Slic3r/GUI/BedShapeDialog.pm | 14 +++++++++++-- xs/t/11_clipper.t | 35 ++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/GUI/BedShapeDialog.pm b/lib/Slic3r/GUI/BedShapeDialog.pm index a055dad24..56f219a9d 100644 --- a/lib/Slic3r/GUI/BedShapeDialog.pm +++ b/lib/Slic3r/GUI/BedShapeDialog.pm @@ -299,14 +299,24 @@ sub _repaint_canvas { my $step = 10; # 1cm grid my @polylines = (); for (my $x = $bb->x_min - ($bb->x_min % $step) + $step; $x < $bb->x_max; $x += $step) { - push @polylines, Slic3r::Polyline->new_scale([$x, $bb->y_min], [$x, $bb->y_max]); + push @polylines, Slic3r::Polyline->new_scale([$x, $bb->y_min], [$x, $bb->y_max]);last; } for (my $y = $bb->y_min - ($bb->y_min % $step) + $step; $y < $bb->y_max; $y += $step) { push @polylines, Slic3r::Polyline->new_scale([$bb->x_min, $y], [$bb->x_max, $y]); - } + }my @orig = @polylines; @polylines = @{intersection_pl(\@polylines, [$bed_polygon])}; $dc->SetPen(Wx::Pen->new(Wx::Colour->new(230,230,230), 1, wxSOLID)); + use Slic3r::SVG; + Slic3r::SVG::output( + "grid.svg", + no_arrows => 1, + polylines => \@polylines, + ); + use XXX; YYY [ + [map $_->dump_perl, @orig], + $bed_polygon->dump_perl, + ]; $dc->DrawLine(map @{$to_pixel->([map unscale($_), @$_])}, @$_) for @polylines; } diff --git a/xs/t/11_clipper.t b/xs/t/11_clipper.t index ba12568ed..8709c0108 100644 --- a/xs/t/11_clipper.t +++ b/xs/t/11_clipper.t @@ -3,6 +3,7 @@ use strict; use warnings; +use List::Util qw(sum); use Slic3r::XS; use Test::More tests => 23; @@ -192,8 +193,8 @@ if (0) { # Clipper does not preserve polyline orientation is scalar(@{$result->[0]}), 5, 'intersection_pl - result is not empty'; } -if (1) { - # Disabled until Clipper bug #126 is fixed +{ + # Clipper bug #126 my $subject = Slic3r::Polyline->new( [200000,19799999],[200000,200000],[24304692,200000],[15102879,17506106],[13883200,19799999],[200000,19799999], ); @@ -205,4 +206,34 @@ if (1) { is $result->[0]->length, $subject->length, 'intersection_pl - result has same length as subject polyline'; } +if (0) { + # Disabled until Clipper bug #127 is fixed + my $subject = [ + Slic3r::Polyline->new([-90000000,-100000000],[-90000000,100000000]), # vertical + Slic3r::Polyline->new([-100000000,-10000000],[100000000,-10000000]), # horizontal + Slic3r::Polyline->new([-100000000,0],[100000000,0]), # horizontal + Slic3r::Polyline->new([-100000000,10000000],[100000000,10000000]), # horizontal + ]; + my $clip = Slic3r::Polygon->new( # a circular, convex, polygon + [99452190,10452846],[97814760,20791169],[95105652,30901699],[91354546,40673664],[86602540,50000000], + [80901699,58778525],[74314483,66913061],[66913061,74314483],[58778525,80901699],[50000000,86602540], + [40673664,91354546],[30901699,95105652],[20791169,97814760],[10452846,99452190],[0,100000000], + [-10452846,99452190],[-20791169,97814760],[-30901699,95105652],[-40673664,91354546], + [-50000000,86602540],[-58778525,80901699],[-66913061,74314483],[-74314483,66913061], + [-80901699,58778525],[-86602540,50000000],[-91354546,40673664],[-95105652,30901699], + [-97814760,20791169],[-99452190,10452846],[-100000000,0],[-99452190,-10452846], + [-97814760,-20791169],[-95105652,-30901699],[-91354546,-40673664],[-86602540,-50000000], + [-80901699,-58778525],[-74314483,-66913061],[-66913061,-74314483],[-58778525,-80901699], + [-50000000,-86602540],[-40673664,-91354546],[-30901699,-95105652],[-20791169,-97814760], + [-10452846,-99452190],[0,-100000000],[10452846,-99452190],[20791169,-97814760], + [30901699,-95105652],[40673664,-91354546],[50000000,-86602540],[58778525,-80901699], + [66913061,-74314483],[74314483,-66913061],[80901699,-58778525],[86602540,-50000000], + [91354546,-40673664],[95105652,-30901699],[97814760,-20791169],[99452190,-10452846],[100000000,0] + ); + my $result = Slic3r::Geometry::Clipper::intersection_pl($subject, [$clip]); + is scalar(@$result), scalar(@$subject), 'intersection_pl - expected number of polylines'; + is sum(map scalar(@$_), @$result), scalar(@$subject)*2, + 'intersection_pl - expected number of points in polylines'; +} + __END__