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

Function isPointInPolygon

packages/ui/src/menu.tsx:981–996  ·  view source on GitHub ↗
(point: Point, polygon: Polygon)

Source from the content-addressed store, hash-verified

979// Determine if a point is inside of a polygon.
980// Based on https://github.com/substack/point-in-polygon
981function isPointInPolygon(point: Point, polygon: Polygon) {
982 const { x, y } = point
983 let inside = false
984 for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
985 const xi = polygon[i].x
986 const yi = polygon[i].y
987 const xj = polygon[j].x
988 const yj = polygon[j].y
989
990 // prettier-ignore
991 const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
992 if (intersect) inside = !inside
993 }
994
995 return inside
996}
997
998function isPointerInGraceArea(event: React.PointerEvent, area?: Polygon) {
999 if (!area) return false

Callers 1

isPointerInGraceAreaFunction · 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…