const rgbToHsv = (r, g, b)=>{
    const max = Math.max(r, g, b);
    const min = Math.min(r, g, b);
    let h;
    const v = max;
    const d = max - min;
    const s = 0 === max ? 0 : d / max;
    if (max === min) h = 0;
    else {
        switch(max){
            case r:
                h = (g - b) / d + (g < b ? 6 : 0);
                break;
            case g:
                h = (b - r) / d + 2;
                break;
            default:
                h = (r - g) / d + 4;
                break;
        }
        h /= 6;
    }
    return {
        h,
        s,
        v
    };
};
const hsvToRgb = (h, s, v)=>{
    let r, g, b;
    const i = Math.floor(6 * h);
    const f = 6 * h - i;
    const p = v * (1 - s);
    const q = v * (1 - f * s);
    const t = v * (1 - (1 - f) * s);
    switch(i % 6){
        case 0:
            r = v;
            g = t;
            b = p;
            break;
        case 1:
            r = q;
            g = v;
            b = p;
            break;
        case 2:
            r = p;
            g = v;
            b = t;
            break;
        case 3:
            r = p;
            g = q;
            b = v;
            break;
        case 4:
            r = t;
            g = p;
            b = v;
            break;
        default:
            r = v;
            g = p;
            b = q;
            break;
    }
    return {
        r: Math.round(r),
        g: Math.round(g),
        b: Math.round(b)
    };
};
export { hsvToRgb, rgbToHsv };
