The point to check, represented as [x, y]
.
The polygon, represented as an array of points [T_Point, T_Point, ...]
, where
each point is [x, y]
.
true
if the point is inside the polygon; otherwise, false
.
// Define a point
const point: T_Point = [5, 5];
// Define a polygon
const polygon: T_Path = [
[0, 0],
[10, 0],
[10, 10],
[0, 10],
];
// Check if the point is inside the polygon
const isInside = pointInPolygon(point, polygon); // Returns true
// Check a point outside the polygon
const outsidePoint: T_Point = [15, 5];
const isOutside = pointInPolygon(outsidePoint, polygon); // Returns false
Determines whether a point is inside a polygon using the ray-casting algorithm.
This function checks if a given point lies within the bounds of a polygon by casting a ray from the point and counting the number of times it intersects the edges of the polygon.
The polygon is defined as an array of points, and the algorithm assumes the polygon is non-self-intersecting.