source: node_modules/d3-polygon/src/contains.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 411 bytes
Line 
1export default function(polygon, point) {
2 var n = polygon.length,
3 p = polygon[n - 1],
4 x = point[0], y = point[1],
5 x0 = p[0], y0 = p[1],
6 x1, y1,
7 inside = false;
8
9 for (var i = 0; i < n; ++i) {
10 p = polygon[i], x1 = p[0], y1 = p[1];
11 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
12 x0 = x1, y0 = y1;
13 }
14
15 return inside;
16}
Note: See TracBrowser for help on using the repository browser.