Fix overflow in Point::ccw() affecting convex hull generation. Includes regression test

This commit is contained in:
Alessandro Ranellucci 2014-01-17 14:49:51 +01:00
parent 0d7f0705f0
commit 90194ee581
4 changed files with 11 additions and 3 deletions

View file

@ -1057,7 +1057,6 @@ sub repaint {
if (@{$parent->{objects}} && $parent->{config}->skirts) { if (@{$parent->{objects}} && $parent->{config}->skirts) {
my @points = map @{$_->contour}, map @$_, map @{$_->instance_thumbnails}, @{$parent->{objects}}; my @points = map @{$_->contour}, map @$_, map @{$_->instance_thumbnails}, @{$parent->{objects}};
if (@points >= 3) { if (@points >= 3) {
my @o = @{Slic3r::Geometry::Clipper::simplify_polygons([convex_hull(\@points)])};
my ($convex_hull) = @{offset([convex_hull(\@points)], scale($parent->{config}->skirt_distance), 1, JT_ROUND, scale(0.1))}; my ($convex_hull) = @{offset([convex_hull(\@points)], scale($parent->{config}->skirt_distance), 1, JT_ROUND, scale(0.1))};
$dc->SetPen($parent->{skirt_pen}); $dc->SetPen($parent->{skirt_pen});
$dc->SetBrush($parent->{transparent_brush}); $dc->SetBrush($parent->{transparent_brush});

View file

@ -125,7 +125,7 @@ Point::distance_to(const Line &line) const
double double
Point::ccw(const Point &p1, const Point &p2) const Point::ccw(const Point &p1, const Point &p2) const
{ {
return (p2.x - p1.x)*(this->y - p1.y) - (p2.y - p1.y)*(this->x - p1.x); return (double)(p2.x - p1.x)*(double)(this->y - p1.y) - (double)(p2.y - p1.y)*(double)(this->x - p1.x);
} }
double double

View file

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 9; use Test::More tests => 10;
my $point = Slic3r::Point->new(10, 15); my $point = Slic3r::Point->new(10, 15);
is_deeply [ @$point ], [10, 15], 'point roundtrip'; is_deeply [ @$point ], [10, 15], 'point roundtrip';
@ -39,4 +39,11 @@ ok !$point->coincides_with($point2), 'coincides_with';
is $point->distance_to_line($line), 16671685, 'distance_to_line() does not overflow'; is $point->distance_to_line($line), 16671685, 'distance_to_line() does not overflow';
} }
{
my $p0 = Slic3r::Point->new(76975850,89989996);
my $p1 = Slic3r::Point->new(76989990,109989991);
my $p2 = Slic3r::Point->new(76989987,89989994);
ok $p0->ccw($p1, $p2) < 0, 'ccw() does not overflow';
}
__END__ __END__

View file

@ -25,6 +25,8 @@
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %}; %code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %};
double distance_to(Point* point); double distance_to(Point* point);
%name{distance_to_line} double distance_to(Line* line); %name{distance_to_line} double distance_to(Line* line);
double ccw(Point* p1, Point* p2)
%code{% RETVAL = THIS->ccw(*p1, *p2); %};
%{ %{