From c4c7649c82a7a5d0ac332a55e7217701bd04d7d3 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Mon, 1 Sep 2025 11:52:52 +0800 Subject: [PATCH] perf: remove unnecssary `Math.sqrt` for comparision in `findClosestColorIndex` --- src/core/overlay.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/overlay.ts b/src/core/overlay.ts index 7fd740a..c63a0c0 100644 --- a/src/core/overlay.ts +++ b/src/core/overlay.ts @@ -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;