Last active
August 29, 2015 14:08
-
-
Save tsprates/7574c3822bb32c6dd2a2 to your computer and use it in GitHub Desktop.
Checks if the google.maps.Polygon.Path is inside the polygon, to determine if exists "holes" inside the google.maps.Polygon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks if the google.maps.Polygon.Path is inside the polygon. | |
* | |
* @see {@link https://developers.google.com/maps/documentation/javascript/overlays#Polygons} | |
* @see {@link http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/pentagon.html} | |
* @see {@link http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm} | |
* @see {@link http://en.wikipedia.org/wiki/Curve_orientation} | |
* @param {google.maps.Polygon.Path} path | |
* @returns {boolean} | |
*/ | |
google.maps.prototype.isCounterClokwise = function(path) { | |
var j, k, z, | |
p = path, | |
count = 0; | |
for (var i = 0, n = p.length; i < n; i++) { | |
j = (i + 1) % n; | |
k = (i + 2) % n; | |
z = (p[j].lat() - p[i].lat()) * (p[k].lng() - p[j].lng()); | |
z -= (p[j].lng() - p[i].lng()) * (p[k].lat() - p[j].lat()); | |
if (z < 0) { | |
count--; | |
} else if (z > 0) { | |
count++; | |
} | |
} | |
return (count > 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment