MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / findNearest

Method findNearest

tools/buildclut.js:110–127  ·  view source on GitHub ↗
(clut, r, g, b)

Source from the content-addressed store, hash-verified

108 }
109
110 findNearest(clut, r, g, b) {
111 let bestDelta = 1000000;
112 let nearest;
113
114 for (let i = 0, c = 0; i < 16; i++, c += 3) {
115 let dr = clut[c + 0] - r;
116 let dg = clut[c + 1] - g;
117 let db = clut[c + 2] - b;
118 let delta = Math.sqrt((dr * dr) + (dg * dg) + (db * db));
119// let delta = ((clut[c + 0] - r) ^ 2) + ((clut[c + 1] - g) ^ 2) + ((clut[c + 2] - b) ^ 2);
120 if (delta < bestDelta) {
121 nearest = i;
122 bestDelta = delta;
123 }
124 }
125
126 return nearest;
127 }
128
129 // prepare to truncate 8 bits to 4 bits
130 roundComponent(c) {

Callers 1

runMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected