Bugfix: Douglas-Peucker used perpendicular distance instead of shortest distance, thus clipping more than it should. #2474

This commit is contained in:
Alessandro Ranellucci 2015-01-03 15:03:53 +01:00
parent 69da8b0999
commit d8be67c28b
7 changed files with 64 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 14;
use Test::More tests => 16;
my $points = [
[100, 100],
@ -34,6 +34,14 @@ is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
ok abs($polyline->length - ($len-($len/3))) < 1, 'clip_end';
}
{
my $polyline = Slic3r::Polyline->new(
[0,0], [20,0], [50,0], [80,0], [100,0],
);
$polyline->simplify(2);
is_deeply $polyline->pp, [ [0,0], [100,0] ], 'Douglas-Peucker';
}
{
my $polyline = Slic3r::Polyline->new(
[0,0], [50,50], [100,0], [125,-25], [150,50],
@ -42,6 +50,14 @@ is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
is_deeply $polyline->pp, [ [0, 0], [50, 50], [125, -25], [150, 50] ], 'Douglas-Peucker';
}
{
my $polyline = Slic3r::Polyline->new(
[0,0], [100,0], [50,10],
);
$polyline->simplify(25);
is_deeply $polyline->pp, [ [0,0], [100,0], [50,10] ], 'Douglas-Peucker uses shortest distance instead of perpendicular distance';
}
{
my $polyline = Slic3r::Polyline->new(@$points);
is $polyline->length, 100*2, 'length';