@pbroom/color-kit/planeMapping
projectRegionBetweenPlanes
Re-expresses a region drawn on one plane in the coordinates of another.
import { projectRegionBetweenPlanes } from '@pbroom/color-kit/plane';transforms.ts:165function projectRegionBetweenPlanes(
sourcePlaneDefinition: PlaneDefinition,
targetPlaneDefinition: PlaneDefinition,
region: PlaneRegion,
): PlaneRegion;Each point is converted to a color on the source plane (axis channels from the point, other channels from the source plane's fixed values) and then projected onto the target plane's axes; the target plane's own fixed values are ignored. This keeps the same colors under a different axis range, orientation or channel order. Both steps clamp to the plane viewport, so points outside [0, 1] on the source plane are clamped first and colors outside the target ranges land on the target's edge. Paths keep their point count; nothing is resampled, so strongly non-linear mappings (for example between models) only bend the outline at its existing vertices.
Parameters
- sourcePlaneDefinition
PlaneDefinition - Plane the region's points are expressed in.
- targetPlaneDefinition
PlaneDefinition - Plane to express them in.
- region
PlaneRegion - Region in source-plane normalized coordinates.
Returns
PlaneRegionThe region in target-plane normalized coordinates.
Example
import { projectRegionBetweenPlanes, type PlaneDefinition } from '@pbroom/color-kit/plane';
const full: PlaneDefinition = { model: 'oklch', fixed: { h: 250 } };
// Same plane zoomed to lightness 0.5–1.
const zoomed: PlaneDefinition = { model: 'oklch', x: { channel: 'l', range: [0.5, 1] }, fixed: { h: 250 } };
const line = { paths: [[{ x: 0.25, y: 0.5 }, { x: 0.75, y: 0.5 }, { x: 1, y: 0.5 }]] };
projectRegionBetweenPlanes(full, zoomed, line).paths[0];
// → [{ x: 0, y: 0.5 }, { x: 0.5, y: 0.5 }, { x: 1, y: 0.5 }] (l = 0.25 clamps to the edge)See also
Also exported from
@pbroom/color-kitthe same declaration, re-exported