perf: remove unnecssary Math.sqrt for comparision in findClosestColorIndex

This commit is contained in:
CrazyboyQCD 2025-09-01 11:52:52 +08:00
parent b8769ff619
commit c4c7649c82

View file

@ -42,11 +42,10 @@ function findClosestColorIndex(r: number, g: number, b: number) {
let index = 0;
for (let i = 0; i < ALL_COLORS.length; i++) {
const color = ALL_COLORS[i];
const distance = Math.sqrt(
const distance =
Math.pow(r - color[0], 2) +
Math.pow(g - color[1], 2) +
Math.pow(b - color[2], 2)
);
Math.pow(b - color[2], 2);
if (distance < minDistance) {
minDistance = distance;
index = i;