@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
29 lines (28 loc) • 668 B
JavaScript
;
const index = require("../../utils/index.cjs");
const unpack = require("../../utils/unpack.cjs");
const { min, sqrt, acos } = Math;
const rgb2hsi = (...args) => {
let [r, g, b] = unpack(args, "rgb");
r /= 255;
g /= 255;
b /= 255;
let h;
const min_ = min(r, g, b);
const i = (r + g + b) / 3;
const s = i > 0 ? 1 - min_ / i : 0;
if (s === 0) {
h = NaN;
} else {
h = (r - g + (r - b)) / 2;
h /= sqrt((r - g) * (r - g) + (r - b) * (g - b));
h = acos(h);
if (b > g) {
h = index.TWOPI - h;
}
h /= index.TWOPI;
}
return [h * 360, s, i];
};
module.exports = rgb2hsi;
//# sourceMappingURL=rgb2hsi.cjs.map