From 90194ee581ada784835d9c1d869d00d7cc741579 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 17 Jan 2014 14:49:51 +0100 Subject: [PATCH] Fix overflow in Point::ccw() affecting convex hull generation. Includes regression test --- lib/Slic3r/GUI/Plater.pm | 1 - xs/src/Point.cpp | 2 +- xs/t/03_point.t | 9 ++++++++- xs/xsp/Point.xsp | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index b55bb81fd..8fd9ed5bb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1057,7 +1057,6 @@ sub repaint { if (@{$parent->{objects}} && $parent->{config}->skirts) { my @points = map @{$_->contour}, map @$_, map @{$_->instance_thumbnails}, @{$parent->{objects}}; 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))}; $dc->SetPen($parent->{skirt_pen}); $dc->SetBrush($parent->{transparent_brush}); diff --git a/xs/src/Point.cpp b/xs/src/Point.cpp index ff63eae58..9b95c6fb8 100644 --- a/xs/src/Point.cpp +++ b/xs/src/Point.cpp @@ -125,7 +125,7 @@ Point::distance_to(const Line &line) const double 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 diff --git a/xs/t/03_point.t b/xs/t/03_point.t index 39a2313ec..e1c88977f 100644 --- a/xs/t/03_point.t +++ b/xs/t/03_point.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 9; +use Test::More tests => 10; my $point = Slic3r::Point->new(10, 15); 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'; } +{ + 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__ diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 8afcf1838..79439d099 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -25,6 +25,8 @@ %code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %}; double distance_to(Point* point); %name{distance_to_line} double distance_to(Line* line); + double ccw(Point* p1, Point* p2) + %code{% RETVAL = THIS->ccw(*p1, *p2); %}; %{