MCPcopy Create free account
hub / github.com/editablejs/editable / isPointInPolygon

Function isPointInPolygon

packages/ui/src/hooks/use-pointer-in-transit.ts:45–60  ·  view source on GitHub ↗
(point: Point, polygon: Polygon)

Source from the content-addressed store, hash-verified

43// Determine if a point is inside of a polygon.
44// Based on https://github.com/substack/point-in-polygon
45function isPointInPolygon(point: Point, polygon: Polygon) {
46 const { x, y } = point
47 let inside = false
48 for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
49 const xi = polygon[i].x
50 const yi = polygon[i].y
51 const xj = polygon[j].x
52 const yj = polygon[j].y
53
54 // prettier-ignore
55 const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
56 if (intersect) inside = !inside
57 }
58
59 return inside
60}
61
62// Returns a new array of points representing the convex hull of the given set of points.
63// https://www.nayuki.io/page/convex-hull-algorithm

Callers 1

handleTrackPointerGraceFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…