From 660b56acb5cbdd05c989473a0a863c88376cd54a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 26 Mar 2016 12:21:54 +0100 Subject: [PATCH] Fixed type error --- xs/src/libslic3r/Line.cpp | 12 ++++++------ xs/t/06_polygon.t | 13 ++++++++++++- xs/xsp/Polygon.xsp | 6 ++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index 1940402ed..c98750e84 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -182,14 +182,14 @@ Line::extend_start(double distance) bool Line::intersection(const Line& line, Point* intersection) const { - double denom = ((line.b.y - line.a.y)*(this->b.x - this->a.x)) - - ((line.b.x - line.a.x)*(this->b.y - this->a.y)); + double denom = ((double)(line.b.y - line.a.y)*(this->b.x - this->a.x)) - + ((double)(line.b.x - line.a.x)*(this->b.y - this->a.y)); - double nume_a = ((line.b.x - line.a.x)*(this->a.y - line.a.y)) - - ((line.b.y - line.a.y)*(this->a.x - line.a.x)); + double nume_a = ((double)(line.b.x - line.a.x)*(this->a.y - line.a.y)) - + ((double)(line.b.y - line.a.y)*(this->a.x - line.a.x)); - double nume_b = ((this->b.x - this->a.x)*(this->a.y - line.a.y)) - - ((this->b.y - this->a.y)*(this->a.x - line.a.x)); + double nume_b = ((double)(this->b.x - this->a.x)*(this->a.y - line.a.y)) - + ((double)(this->b.y - this->a.y)*(this->a.x - line.a.x)); if (fabs(denom) < EPSILON) { if (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON) { diff --git a/xs/t/06_polygon.t b/xs/t/06_polygon.t index 116919a74..779c7deec 100644 --- a/xs/t/06_polygon.t +++ b/xs/t/06_polygon.t @@ -5,7 +5,7 @@ use warnings; use List::Util qw(first); use Slic3r::XS; -use Test::More tests => 20; +use Test::More tests => 21; use constant PI => 4 * atan2(1, 1); @@ -73,6 +73,17 @@ ok $cw_polygon->contains_point(Slic3r::Point->new(150,150)), 'cw contains_point' is_deeply $polygon->centroid->pp, [150,150], 'centroid'; } +{ + my $polygon = Slic3r::Polygon->new( + [50000000, 100000000], + [300000000, 102000000], + [50000000, 104000000], + ); + my $line = Slic3r::Line->new([175992032,102000000], [47983964,102000000]); + my $intersection = $polygon->intersection($line); + is_deeply $intersection->pp, [50000000, 102000000], 'polygon-line intersection'; +} + # this is not a test: this just demonstrates bad usage, where $polygon->clone gets # DESTROY'ed before the derived object ($point), causing bad memory access if (0) { diff --git a/xs/xsp/Polygon.xsp b/xs/xsp/Polygon.xsp index ec97aabcf..f569a899d 100644 --- a/xs/xsp/Polygon.xsp +++ b/xs/xsp/Polygon.xsp @@ -42,6 +42,12 @@ std::string wkt(); Points concave_points(double angle); Points convex_points(double angle); + Clone intersection(Line* line) + %code{% + Point p; + (void)THIS->intersection(*line, &p); + RETVAL = p; + %}; %{ Polygon*