gka / chroma.js

JavaScript library for all kinds of color manipulations
https://vis4.net/chromajs/
Other
9.94k stars 543 forks source link

HSL to RGB forces rounding even with rgb(false) #333

Open KeyboardDanni opened 3 months ago

KeyboardDanni commented 3 months ago

The code in hsl2rgb.js is forcing the RGB components to be rounded to the nearest integer:

https://github.com/gka/chroma.js/blob/cd1b3c0926c7a85cbdc3b1453b3a94006de91a92/src/io/hsl/hsl2rgb.js#L31

This means that even if you pass false to rgb(), the resulting color gets rounded. The issue does not occur with HSV.

Minimal reproduction:

import chroma from "chroma-js";

let color = chroma.hsv(260, 0.5, 0.5);
let colorRgb = color.rgb(false); // [ 84.99999999999999, 63.75, 127.5 ]

color = chroma.hsl(260, 0.3333333333333333, 0.375);
colorRgb = color.rgb(false); // [ 85, 64, 128 ]