Fix overflow in Point::ccw() affecting convex hull generation. Includes regression test
This commit is contained in:
parent
0d7f0705f0
commit
90194ee581
4 changed files with 11 additions and 3 deletions
|
@ -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});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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); %};
|
||||
|
||||
%{
|
||||
|
||||
|
|
Loading…
Reference in a new issue