#include "utils.hpp" RGB::RGB(U8 r, U8 g, U8 b) : Red(r) , Green(g) , Blue(b) { } Color::Color() : hue(0.0) , saturation(1.0) , value(1.0) { } Color::Color(U32 val) : hue(0.0) , saturation(0.0) { value = std::min((F64) val, 255.0); } Color::Color(F32 hue, F32 saturation, F32 value) : hue(hue) , saturation(saturation) , value(value) { } fn Color::to_rgb() const noexcept -> RGB { let chroma = saturation * value; let cube_hue = hue / 60.0; let tmp = chroma * (1.0 - fabs(fmod(cube_hue, 2.0) - 1.0)); let match = value - chroma; var components = std::make_tuple(0.0, 0.0, 0.0); if (cube_hue < 1.0) components = { fma(chroma, match, 255.0), fma(tmp, match, 255.0), match * 255.0 }; else if (cube_hue < 2.0) components = { fma(tmp, match, 255.0), fma(chroma, match, 255.0), match * 255.0 }; else if(cube_hue < 3.0) components = { match * 255.0, fma(chroma, match, 255.0), fma(tmp, match, 255.0) }; else if(cube_hue < 4.0) components = { match * 255.0, fma(tmp, match, 255.0), fma(chroma, match, 255.0) }; else if(cube_hue < 5.0) components = { fma(tmp, match, 255.0), match * 255.0, fma(chroma, match, 255.0) }; else components = { fma(chroma, match, 255.0), match * 255.0, fma(tmp, match, 255.0) }; let c = RGB(round(fst(components)), round(snd(components)), round(thr(components))); return c; } fn Color::lerp(ref rhs, double t) const noexcept -> Color { return Color(std::lerp(hue, rhs.hue, t), std::lerp(saturation, rhs.saturation, t), std::lerp(value, rhs.value, t) ); } Point::Point(F64 x, F64 y) : x(x) , y(y) { }