source: node_modules/d3-contour/src/contains.js@ a762898

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

Prototype 1.1

  • Property mode set to 100644
File size: 871 bytes
Line 
1export default function(ring, hole) {
2 var i = -1, n = hole.length, c;
3 while (++i < n) if (c = ringContains(ring, hole[i])) return c;
4 return 0;
5}
6
7function ringContains(ring, point) {
8 var x = point[0], y = point[1], contains = -1;
9 for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
10 var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
11 if (segmentContains(pi, pj, point)) return 0;
12 if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
13 }
14 return contains;
15}
16
17function segmentContains(a, b, c) {
18 var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
19}
20
21function collinear(a, b, c) {
22 return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
23}
24
25function within(p, q, r) {
26 return p <= q && q <= r || r <= q && q <= p;
27}
Note: See TracBrowser for help on using the repository browser.