@pbroom/color-kit/planeOperations

differenceRegions

Returns the area of a that is not covered by b (a − b).

functionimport { differenceRegions } from '@pbroom/color-kit/plane';operations.ts:376
function differenceRegions(
  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
Region to subtract from.
bPlaneRegion
Region to subtract.
options?PlaneBooleanOptionsdefault {}
Raster resolution.

Returns

PlaneRegionA new region; { paths: [] } when b covers all of a.

Example

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

const view = sense({ model: 'oklch', fixed: { h: 250 } });
const p3 = view.gamutRegion({ gamut: 'display-p3' }).visibleRegion;
const srgb = view.gamutRegion({ gamut: 'srgb' }).visibleRegion;
const p3Only = differenceRegions(p3, srgb); // colors P3 can show but sRGB cannot

containsPoint(p3Only, { x: 0.6, y: 0.5 }); // → true
containsPoint(p3Only, { x: 0.6, y: 0.9 }); // → false

See also

Also exported from