Math::Polygon::Tree - Class for fast check if point is inside polygon
Math::Polygon::Tree creates a B-tree of polygon parts for fast check if object is inside this polygon. This method is effective if polygon has hundreds or more segments.
use Math::Polygon::Tree; my $poly = [ [0,0], [0,2], [2,2], ... ]; my $bound = Math::Polygon::Tree->new( $poly ); if ( $bound->contains( [1,1] ) ) { ... }
Takes polygons (at least one) and creates a tree structure. All polygons are outer, inners in not implemented. Polygon is a reference to array of points
my $poly1 = [ [0,0], [0,2], [2,2], ... ]; ... my $bound = Math::Polygon::Tree->new( $poly1, $poly2, ... );
or a .poly file
my $bound = Math::Polygon::Tree->new( 'boundary.poly' );
Checks if point is inside bound polygon. Returns 1 if point is inside polygon or 0 otherwise.
if ( $bound->contains( [1,1] ) ) { ...
Checks if points are inside bound polygon. Returns 1 if all points are inside polygon, 0 if all outside, or undef.
if ( $bound->contains_points( [1,1], [2,2] ... ) ) { ...
Checks if box is inside bound polygon. Returns 1 if box is inside polygon, 0 if box is outside polygon or undef if it 'doubts'.
my ($xmin, $ymin, $xmax, $ymax) = ( 1, 1, 2, 2 ); if ( $bound->contains_bbox_rough( $xmin, $ymin, $xmax, $ymax ) ) { ... }
Checks if polygon is inside bound polygon. Returns 1 if inside, 0 if outside or undef if 'doubts'.
if ( $bound->contains_polygon_rough( [ [1,1], [1,2], [2,2], ... ] ) ) { ... }
Returns polygon's bounding box.
my ( $xmin, $ymin, $xmax, $ymax ) = $bound->bbox();
Function that returns polygon's bbox.
my ( $xmin, $ymin, $xmax, $ymax ) = polygon_bbox( [1,1], [1,2], [2,2], ... );
Function that returns polygon's weightened center.
my ( $x, $y ) = polygon_centroid( [1,1], [1,2], [2,2], ... );
Function that tests if polygon contains point (modified one from Math::Polygon::Calc). Returns -1 if point lays on polygon's boundary
liosha, <liosha at cpan.org>
<liosha at cpan.org>
Please report any bugs or feature requests to bug-math-polygon-tree at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Polygon-Tree. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-math-polygon-tree at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Math::Polygon::Tree
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Polygon-Tree
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Math-Polygon-Tree
CPAN Ratings
http://cpanratings.perl.org/d/Math-Polygon-Tree
Search CPAN
http://search.cpan.org/dist/Math-Polygon-Tree/
Copyright 2009 liosha.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Math::Polygon::Tree, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Polygon::Tree
CPAN shell
perl -MCPAN -e shell install Math::Polygon::Tree
For more information on module installation, please visit the detailed CPAN module installation guide.