@pbroom/color-kit/planeOperations
containsPoint
Returns whether a point lies inside a region, using the even-odd fill rule.
import { containsPoint } from '@pbroom/color-kit/plane';operations.ts:72function containsPoint( region: PlaneRegion, , point: PlanePoint,): boolean;Each path is treated as a closed polygon (the last point connects back to the first, so a repeated closing point is optional) and every path toggles inside/outside. A path nested inside another therefore cuts a hole, which matches the compound paths returned by plane queries and region booleans and SVG fill-rule="evenodd". Coordinates are compared as-is, so region and point must share a space (plane-normalized [0, 1] for query results). Points exactly on an edge may resolve either way.
Parameters
- region
PlaneRegion - Region whose
pathsform one compound polygon. - point
PlanePoint - Point to test, in the same coordinate space as
region.
Returns
booleantrue when the point is inside an odd number of paths.
Example
import { containsPoint } from '@pbroom/color-kit/plane';
const outer = [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 }];
const hole = [{ x: 0.25, y: 0.25 }, { x: 0.75, y: 0.25 }, { x: 0.75, y: 0.75 }, { x: 0.25, y: 0.75 }];
const frame = { paths: [outer, hole] };
containsPoint(frame, { x: 0.1, y: 0.1 }); // → true
containsPoint(frame, { x: 0.5, y: 0.5 }); // → false (inside the hole)See also
Also exported from
@pbroom/color-kitthe same declaration, re-exported