@pbroom/color-kit/planeOperations

intersectRegions

Returns the area covered by both regions (a ∩ b).

functionimport { intersectRegions } from '@pbroom/color-kit/plane';operations.ts:336
function intersectRegions(
  a: PlaneRegion,
  b: PlaneRegion,
  options?: PlaneBooleanOptions,
): PlaneRegion;

Both regions are rasterized with the even-odd rule (see containsPoint) on a resolution × resolution grid covering their combined bounding box plus one cell of padding, and the result is traced back into closed paths with marching squares. Output is therefore approximate: edges can be off by up to about one cell, corners are bevelled, and where the two boundaries run within a cell of each other the result can contain tiny one-cell fragments. Each output path repeats its first point at the end; holes are separate paths. Works in any coordinate space shared by both inputs (plane-normalized for query results).

Parameters

aPlaneRegion
First region.
bPlaneRegion
Second region.
options?PlaneBooleanOptionsdefault {}
Raster resolution.

Returns

PlaneRegionA new region; { paths: [] } when the regions do not overlap.

Example

TypeScript
import { containsPoint, intersectRegions, sense } from '@pbroom/color-kit/plane';

// Default OKLCH plane: x = lightness, y = chroma (0.4 at the top, 0 at the bottom).
const srgb = sense({ model: 'oklch', fixed: { h: 250 } }).gamutRegion({ gamut: 'srgb' });
const darkHalf = { paths: [[{ x: 0, y: 0 }, { x: 0.5, y: 0 }, { x: 0.5, y: 1 }, { x: 0, y: 1 }]] };
const darkInGamut = intersectRegions(srgb.visibleRegion, darkHalf);

containsPoint(darkInGamut, { x: 0.3, y: 0.9 }); // → true
containsPoint(darkInGamut, { x: 0.7, y: 0.9 }); // → false

See also

Also exported from