| 1 | package Politics::AU::Geo::Polygons; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Storable (); | ||
| 5 | use Params::Util qw{_INSTANCE}; | ||
| 6 | use Math::Polygon (); | ||
| 7 | |||
| 8 | our $VERSION = '0.01'; | ||
| 9 | |||
| 10 | sub point_in_polygon { | ||
| 11 | my $self = shift; | ||
| 12 | my $latitude = shift; | ||
| 13 | my $longitude = shift; | ||
| 14 | |||
| 15 | # Inflate | ||
| 16 | my $polygon = Storable::thaw($self->points); | ||
| 17 | unless ( _INSTANCE($polygon, 'Math::Polygon') ) { | ||
| 18 | die("Failed to deserialize the Math::Polygon object"); | ||
| 19 | } | ||
| 20 | |||
| 21 | # Check | ||
| 22 | if ( $polygon->contains([ $longitude, $latitude ]) ) { | ||
| 23 | return 1; | ||
| 24 | } else { | ||
| 25 | return ''; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | __END__ |