(point: Point, polygon: Polygon)
| 43 | // Determine if a point is inside of a polygon. |
| 44 | // Based on https://github.com/substack/point-in-polygon |
| 45 | function 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…