Skip to content

createNearestColorFinder

createNearestColorFinder<TEntry>(entries, colorOf): NearestColorFinder<TEntry>

Defined in: packages/math-color/src/nearest-color.ts:34

Binds a palette to a nearest-member lookup, converting it once.

The conversion belongs to the registration, not to the query: a palette is fixed and a lookup is called per pixel or per cell, so converting inside the search makes every call pay for the whole table. Building the finder once and keeping it is the whole point of the shape.

O(n) per query in the entry count, with no allocation. A palette large enough for that to hurt wants a spatial index instead, which this deliberately is not.

Ordering uses squared distance: monotonic in the distance, so the winner is the same one, without a square root per entry per call.

TEntry

Iterable<TEntry>

Read once; later mutation of the source is not observed.

(entry) => Oklab

Where an entry keeps its colour.

NearestColorFinder<TEntry>

When entries is empty.