(point: Point, polygon: Polygon)
| 979 | // Determine if a point is inside of a polygon. |
| 980 | // Based on https://github.com/substack/point-in-polygon |
| 981 | function 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 | |
| 998 | function isPointerInGraceArea(event: React.PointerEvent, area?: Polygon) { |
| 999 | if (!area) return false |
no outgoing calls
no test coverage detected
searching dependent graphs…