contains static method
Tests if a point lies within a polygon using the ray casting algorithm.
Implementation based on the PNPOLY algorithm. Reference: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
latLongs Vertices of the polygon
latLong Point to test
Returns true if the point is inside the polygon
Implementation
static bool contains(List<ILatLong> latLongs, ILatLong latLong) {
bool result = false;
for (int i = 0, j = latLongs.length - 1; i < latLongs.length; j = i++) {
if ((latLongs[i].latitude > latLong.latitude) != (latLongs[j].latitude > latLong.latitude) &&
(latLong.longitude <
(latLongs[j].longitude - latLongs[i].longitude) * (latLong.latitude - latLongs[i].latitude) / (latLongs[j].latitude - latLongs[i].latitude) +
latLongs[i].longitude)) {
result = !result;
}
}
return result;
}