chromatism icon indicating copy to clipboard operation
chromatism copied to clipboard

Conversion of HSV fails when V = 0

Open bdoss opened this issue 7 years ago • 6 comments

This appears to be caused by division by zero, resulting in the saturation component evaluating to NaN.

Line 12 seems to be where the division by zero occurs: https://github.com/toish/chromatism/blob/488020a1553d5aa0a0ffb1fbd98fc19a6be6503d/src/conversions/hsv.js#L9-L17

bdoss avatar Oct 23 '17 20:10 bdoss

Only seems to impact the HSV case.

HSL conversion:

let { hex } = chroma.convert({ h: 0, s: 0, l: 0 });
// hex = #000000

HSV conversion:

let { hex } = chroma.convert({ h: 0, s: 0, v: 0 });
// hex = #NaNNaNNaN

bdoss avatar Oct 23 '17 20:10 bdoss

Good catch!

TehShrike avatar Oct 23 '17 21:10 TehShrike

Fix published upstream in [email protected]. Can be cherry-picked/merged from https://github.com/TehShrike/chromatism/commit/436d8b09bc435845c3d31aff004cf77b83d91cc4

TehShrike avatar Oct 23 '17 21:10 TehShrike

Thanks for the quick fix!

bdoss avatar Oct 23 '17 21:10 bdoss

Awesome! Thanks for the patch @TehShrike, and sorry for the radio silence on my end, this will be in a patch release as soon as I can get to my laptop today.

graypegg avatar Nov 04 '17 18:11 graypegg

Oh wait, @TehShrike, when you’re able to, would you be able to make a pull request? Thanks!

graypegg avatar Nov 04 '17 18:11 graypegg