MCPcopy Create free account
hub / github.com/adobe/react-spectrum / isPointInPolygon

Function isPointInPolygon

packages/react-aria/src/tooltip/useSafeArea.ts:155–169  ·  view source on GitHub ↗
(point: Point, polygon: Point[])

Source from the content-addressed store, hash-verified

153
154// Ray casting point-in-polygon test.
155function isPointInPolygon(point: Point, polygon: Point[]): boolean {
156 let {x, y} = point;
157 let inside = false;
158 for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
159 let xi = polygon[i].x;
160 let yi = polygon[i].y;
161 let xj = polygon[j].x;
162 let yj = polygon[j].y;
163 let intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
164 if (intersect) {
165 inside = !inside;
166 }
167 }
168 return inside;
169}

Callers 1

isPointInSafeAreaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected