From bd69bff90b424f5274acf3b9bc7085f0557b3d33 Mon Sep 17 00:00:00 2001 From: Chessing234 Date: Sun, 17 May 2026 07:26:08 +0530 Subject: [PATCH] fix(color): guard against NaN saturation in _hslaToHSBA when lightness is 0 When the HSL lightness is 0, the branch 'val = (1 + sat) * li' on line 110 makes val = 0, and the next line computes 'sat = 2 * (val - li) / val' which divides by zero and yields NaN. Pure-black HSL colors then round-tripped through HSB with sat = NaN. The inverse helper _hsbaToHSLA already guards its corresponding division with 'if (li !== 0)'; apply the symmetric guard here so val === 0 short-circuits to sat = 0 (the correct saturation for a black color). --- src/color/color_conversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/color/color_conversion.js b/src/color/color_conversion.js index 850d24918b..d08225924a 100644 --- a/src/color/color_conversion.js +++ b/src/color/color_conversion.js @@ -113,7 +113,7 @@ p5.ColorConversion = { } // Convert saturation. - sat = 2 * (val - li) / val; + sat = val === 0 ? 0 : 2 * (val - li) / val; // Hue and alpha stay the same. return [hue, sat, val, hsla[3]];