Added failing test case for Clipper regression causing extra points in polyline intersection, thus crash with circular bed shape

This commit is contained in:
Alessandro Ranellucci 2015-02-22 17:03:23 +01:00
parent edbc11477c
commit 2eca094170
2 changed files with 45 additions and 4 deletions

View file

@ -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;
}

View file

@ -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__