graypegg / chromatism

:rainbow: A simple set of utility functions for colours.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion of HSV fails when V = 0

bdoss opened this issue · 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

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

Good catch!

Fix published upstream in chromatism2@3.0.2. Can be cherry-picked/merged from TehShrike@436d8b0

Thanks for the quick fix!

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.

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