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.
Type Parameters
Section titled “Type Parameters”TEntry
Section titled “TEntry”TEntry
Parameters
Section titled “Parameters”entries
Section titled “entries”Iterable<TEntry>
Read once; later mutation of the source is not observed.
colorOf
Section titled “colorOf”(entry) => Oklab
Where an entry keeps its colour.
Returns
Section titled “Returns”NearestColorFinder<TEntry>
Throws
Section titled “Throws”When entries is empty.