aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
Cylindrical.cppm
Go to the documentation of this file.
1
8module;
9#include <concepts>
10#include <string_view>
11export module aest.colors:cylindrical;
12
13import :color;
14import :gamut;
15
16export namespace aest::colors
17{
31template <BoundedRGBSpace RGB>
32class BasicHSL final : public ColorBase<BasicHSL<RGB>>
33{
35 static constexpr std::string_view MODEL = "HSL";
36
38 static constexpr auto QUALIFIED_CHARS =
39 join_names<MODEL.size() + RGB::TYPE.size() + 2>({MODEL, "<", RGB::TYPE, ">"});
40
41public:
43 static constexpr std::string_view TYPE =
44 std::same_as<RGB, SRGB> ? MODEL
45 : std::string_view{QUALIFIED_CHARS.data(), QUALIFIED_CHARS.size()};
46
48 constexpr BasicHSL()
49 : ColorBase<BasicHSL>(1.0f, 0.0f, 0.0f, 0.0f)
50 {}
51
60 constexpr BasicHSL(const float h, const float s, const float l, const float a = 1.0f)
61 : ColorBase<BasicHSL>(a, wrap_hue(h), clamp(s), clamp(l))
62 {}
63
66
70 [[nodiscard]] constexpr float hue() const noexcept { return this->_ch1; }
71
76 [[nodiscard]] constexpr float saturation() const noexcept { return this->_ch2; }
77
82 [[nodiscard]] constexpr float lightness() const noexcept { return this->_ch3; }
84};
85
98template <BoundedRGBSpace RGB>
99class BasicHSV final : public ColorBase<BasicHSV<RGB>>
100{
102 static constexpr std::string_view MODEL = "HSV";
103
105 static constexpr auto QUALIFIED_CHARS =
106 join_names<MODEL.size() + RGB::TYPE.size() + 2>({MODEL, "<", RGB::TYPE, ">"});
107
108public:
110 static constexpr std::string_view TYPE =
111 std::same_as<RGB, SRGB> ? MODEL
112 : std::string_view{QUALIFIED_CHARS.data(), QUALIFIED_CHARS.size()};
113
115 constexpr BasicHSV()
116 : ColorBase<BasicHSV>(1.0f, 0.0f, 0.0f, 0.0f)
117 {}
118
127 constexpr BasicHSV(const float h, const float s, const float v, const float a = 1.0f)
128 : ColorBase<BasicHSV>(a, wrap_hue(h), clamp(s), clamp(v))
129 {}
130
133
137 [[nodiscard]] constexpr float hue() const noexcept { return this->_ch1; }
138
143 [[nodiscard]] constexpr float saturation() const noexcept { return this->_ch2; }
144
149 [[nodiscard]] constexpr float brightness() const noexcept { return this->_ch3; }
151};
152
155
158} // namespace aest::colors
constexpr float clamp(const float value)
Clamp a floating-point value to the 0-1 range.
Definition Color.cppm:29
constexpr std::array< char, Size > join_names(const std::initializer_list< std::string_view > parts)
Concatenate names into a character array, for a color space name built at compile time.
Definition Color.cppm:100
constexpr float wrap_hue(const float hue)
Wrap a hue angle to the [0, 360) range.
Definition Color.cppm:118
BasicHSL< SRGB > HSL
HSL over sRGB, the HSL of CSS.
BasicHSV< SRGB > HSV
HSV over sRGB.
A color as hue, saturation and lightness, over the encoded RGB space RGB.
static constexpr auto QUALIFIED_CHARS
static constexpr std::string_view TYPE
constexpr BasicHSL()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
static constexpr std::string_view MODEL
constexpr BasicHSL(const float h, const float s, const float l, const float a=1.0f)
Construct a color from floating-point HSLA values.
constexpr float lightness() const noexcept
Get the lightness value in the 0-1 range.
constexpr float saturation() const noexcept
Get the saturation value in the 0-1 range.
constexpr float hue() const noexcept
Get the hue value in the 0-360 range.
A color as hue, saturation and value (brightness), over the encoded RGB space RGB.
constexpr float brightness() const noexcept
Get the brightness value in the 0-1 range.
constexpr BasicHSV()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
constexpr BasicHSV(const float h, const float s, const float v, const float a=1.0f)
Construct a color from floating-point HSVA values.
static constexpr std::string_view MODEL
constexpr float saturation() const noexcept
Get the saturation value in the 0-1 range.
constexpr float hue() const noexcept
Get the hue value in the 0-360 range.
static constexpr std::string_view TYPE
static constexpr auto QUALIFIED_CHARS
constexpr ColorBase(const float alpha, const float channel1, const float channel2, const float channel3)
Definition Color.cppm:158