From b414c50b68c516078fac8d2d9db5aea251280e43 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 20 Jun 2013 18:48:11 +0200 Subject: [PATCH] Optimization: use Boost.Geometry for point in polygon --- lib/Slic3r/ExPolygon.pm | 10 ++++------ lib/Slic3r/Polygon.pm | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index c2a4cea07..3056d7053 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -104,18 +104,16 @@ sub noncollapsing_offset_ex { sub encloses_point { my $self = shift; my ($point) = @_; - return $self->contour->encloses_point($point) - && (!grep($_->encloses_point($point), $self->holes) - || grep($_->point_on_segment($point), $self->holes)); + return Boost::Geometry::Utils::point_covered_by_polygon($point, $self); } # A version of encloses_point for use when hole borders do not matter. -# Useful because point_on_segment is slow +# Useful because point_on_segment is probably slower (this was true +# before the switch to Boost.Geometry, not sure about now) sub encloses_point_quick { my $self = shift; my ($point) = @_; - return $self->contour->encloses_point($point) - && !grep($_->encloses_point($point), $self->holes); + return Boost::Geometry::Utils::point_within_polygon($point, $self); } sub encloses_line { diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index 18d4494d5..c69b9e00b 100644 --- a/lib/Slic3r/Polygon.pm +++ b/lib/Slic3r/Polygon.pm @@ -65,7 +65,7 @@ sub point_on_segment { sub encloses_point { my $self = shift; my ($point) = @_; - return point_in_polygon($point, $self); + return Boost::Geometry::Utils::point_covered_by_polygon($point, [$self]); } sub area {