MCPcopy Create free account
hub / github.com/idank/explainshell / insidePolygon

Function insidePolygon

explainshell/web/static/js/d3.v3.js:2676–2690  ·  view source on GitHub ↗
(p)

Source from the content-addressed store, hash-verified

2674 return i;
2675 }
2676 function insidePolygon(p) {
2677 var wn = 0, n = polygon.length, y = p[1];
2678 for (var i = 0; i < n; ++i) {
2679 for (var j = 1, v = polygon[i], m = v.length, a = v[0]; j < m; ++j) {
2680 b = v[j];
2681 if (a[1] <= y) {
2682 if (b[1] > y && isLeft(a, b, p) > 0) ++wn;
2683 } else {
2684 if (b[1] <= y && isLeft(a, b, p) < 0) --wn;
2685 }
2686 a = b;
2687 }
2688 }
2689 return wn !== 0;
2690 }
2691 function isLeft(a, b, c) {
2692 return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]);
2693 }

Callers 2

d3_geo_clipViewFunction · 0.85
insideFunction · 0.85

Calls 1

isLeftFunction · 0.85

Tested by

no test coverage detected