Optimization: use Boost.Geometry for point in polygon

This commit is contained in:
Alessandro Ranellucci 2013-06-20 18:48:11 +02:00
parent f7be746599
commit b414c50b68
2 changed files with 5 additions and 7 deletions

View File

@ -104,18 +104,16 @@ sub noncollapsing_offset_ex {
sub encloses_point { sub encloses_point {
my $self = shift; my $self = shift;
my ($point) = @_; my ($point) = @_;
return $self->contour->encloses_point($point) return Boost::Geometry::Utils::point_covered_by_polygon($point, $self);
&& (!grep($_->encloses_point($point), $self->holes)
|| grep($_->point_on_segment($point), $self->holes));
} }
# A version of encloses_point for use when hole borders do not matter. # 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 { sub encloses_point_quick {
my $self = shift; my $self = shift;
my ($point) = @_; my ($point) = @_;
return $self->contour->encloses_point($point) return Boost::Geometry::Utils::point_within_polygon($point, $self);
&& !grep($_->encloses_point($point), $self->holes);
} }
sub encloses_line { sub encloses_line {

View File

@ -65,7 +65,7 @@ sub point_on_segment {
sub encloses_point { sub encloses_point {
my $self = shift; my $self = shift;
my ($point) = @_; my ($point) = @_;
return point_in_polygon($point, $self); return Boost::Geometry::Utils::point_covered_by_polygon($point, [$self]);
} }
sub area { sub area {