From f1b509de97c1e624eac4a9acfa6986274fe2c6c0 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Thu, 9 Feb 2023 14:32:28 +0100 Subject: [PATCH] feat(color): add distLch() --- packages/color/src/distance.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/color/src/distance.ts b/packages/color/src/distance.ts index 9d980b6852..bd2230ff24 100644 --- a/packages/color/src/distance.ts +++ b/packages/color/src/distance.ts @@ -33,6 +33,20 @@ export const distHsv: ColorDistance = (a, b) => { return hypot(aa[0] - bb[0], aa[1] - bb[1], a[2] - b[2]); }; +/** + * Similar to {@link distHsv}, but computes distance between two LCH colors + * (with different channel order), i.e. the eucledian distance between points in + * a cyclinder. + * + * @param a - + * @param b - + */ +export const distLch: ColorDistance = (a, b) => { + const aa = cossin(a[2] * TAU, a[1]); + const bb = cossin(b[2] * TAU, b[1]); + return hypot(aa[0] - bb[0], aa[1] - bb[1], a[0] - b[0]); +}; + /** * Computes difference in saturation between two HSV colors. *