opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
rgb.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <concepts>
7#include <cstddef>
8#include <utility>
9
10namespace osc
11{
12 template<ColorComponent T>
13 struct Rgb final {
14
15 using value_type = T;
20 using const_iterator = const value_type*;
21
22 static constexpr Rgb white() { return {1.f, 1.f, 1.f }; }
23 static constexpr Rgb lightest_grey() { return {0.95f, 0.95f, 0.95f}; }
24 static constexpr Rgb lighter_grey() { return {0.85f, 0.85f, 0.85f}; }
25 static constexpr Rgb light_grey() { return {0.70f, 0.70f, 0.70f}; }
26 static constexpr Rgb dark_grey() { return {0.50f, 0.50f, 0.50f}; }
27 static constexpr Rgb darker_grey() { return {0.35f, 0.35f, 0.35f}; }
28 static constexpr Rgb darkest_grey() { return {0.05f, 0.05f, 0.05f}; }
29 static constexpr Rgb black() { return {0.f, 0.f, 0.f }; }
30 static constexpr Rgb muted_red() { return {1.f, 0.5f, 0.5f }; }
31 static constexpr Rgb red() { return {1.f, 0.f, 0.f }; }
32 static constexpr Rgb muted_green() { return {0.5f, 1.f, 0.5f }; }
33 static constexpr Rgb green() { return {0.f, 1.f, 0.f }; }
34 static constexpr Rgb dark_green() { return {0.f, 0.6f, 0.f }; }
35 static constexpr Rgb muted_blue() { return {0.06f, 0.53f, 0.98f}; }
36 static constexpr Rgb blue() { return {0.f, 0.f, 1.f }; }
37 static constexpr Rgb cyan() { return {0.f, 1.f, 1.f }; }
38 static constexpr Rgb magenta() { return {1.f, 0.f, 1.f }; }
39 static constexpr Rgb muted_yellow() { return {1.f, 1.f, 0.6f }; }
40 static constexpr Rgb yellow() { return {1.f, 1.f, 0.f }; }
41 static constexpr Rgb orange() { return {1.f, 0.65f, 0.f }; }
42 static constexpr Rgb purple() { return {0.75f, 0.33f, 0.93f}; }
43
44 Rgb() = default;
45
46 explicit constexpr Rgb(value_type v) : r{v}, g{v}, b{v} {}
47
48 constexpr Rgb(value_type r_, value_type g_, value_type b_) : r{r_}, g{g_}, b{b_} {}
49
50 explicit constexpr Rgb(const Vector<value_type, 3>& v) : r{v.x()}, g{v.y()}, b{v.z()} {}
51
52 template<ColorComponent U>
53 requires std::constructible_from<T, const U&>
54 explicit constexpr Rgb(const Vector<U, 3>& v) :
55 r{static_cast<T>(v.x())},
56 g{static_cast<T>(v.y())},
57 b{static_cast<T>(v.z())}
58 {}
59
60 template<ColorComponent U>
61 requires std::constructible_from<T, const U&>
62 explicit (not (std::convertible_to<U, T>))
63 constexpr Rgb(const Rgb<U>& v) :
64 r{static_cast<T>(v.r)},
65 g{static_cast<T>(v.g)},
66 b{static_cast<T>(v.b)}
67 {}
68
69 constexpr reference operator[](size_type pos) { return *(begin() + pos); }
70 constexpr const_reference operator[](size_type pos) const { return *(begin() + pos); }
71
72 constexpr size_t size() const { return 3; }
73
74 constexpr iterator begin() { return &r; }
75 constexpr const_iterator begin() const { return &r; }
76
77 constexpr iterator end() { return &r + size(); }
78 constexpr const_iterator end() const { return &r + size(); }
79
80 friend bool operator==(const Rgb&, const Rgb&) = default;
81
85 };
86
87 template<size_t I, typename T>
88 constexpr const T& get(const Rgb<T>& v) { return v[I]; }
89
90 template<size_t I, typename T>
91 constexpr T& get(Rgb<T>& v) { return v[I]; }
92
93 template<size_t I, typename T>
94 constexpr T&& get(Rgb<T>&& v) { return std::move(v[I]); }
95
96 template<size_t I, typename T>
97 constexpr const T&& get(const Rgb<T>&& v) { return std::move(v[I]); }
98}
99
100template<osc::ColorComponent T>
101struct std::tuple_size<osc::Rgb<T>> {
102 static inline constexpr size_t value = 3;
103};
104
105template<size_t I, osc::ColorComponent T>
106struct std::tuple_element<I, osc::Rgb<T>> {
107 using type = T;
108};
Definition vector.h:63
Definition custom_decoration_generator.h:5
constexpr const T & get(const Rgb< T > &v)
Definition rgb.h:88
constexpr U to(T &&value)
Definition conversion.h:56
Definition rgb.h:13
friend bool operator==(const Rgb &, const Rgb &)=default
Rgb()=default
static constexpr Rgb muted_yellow()
Definition rgb.h:39
static constexpr Rgb dark_grey()
Definition rgb.h:26
value_type r
Definition rgb.h:82
constexpr Rgb(value_type r_, value_type g_, value_type b_)
Definition rgb.h:48
constexpr Rgb(const Vector< value_type, 3 > &v)
Definition rgb.h:50
static constexpr Rgb muted_green()
Definition rgb.h:32
static constexpr Rgb muted_blue()
Definition rgb.h:35
static constexpr Rgb magenta()
Definition rgb.h:38
value_type g
Definition rgb.h:83
constexpr Rgb(const Vector< U, 3 > &v)
Definition rgb.h:54
static constexpr Rgb yellow()
Definition rgb.h:40
value_type & reference
Definition rgb.h:16
static constexpr Rgb blue()
Definition rgb.h:36
value_type b
Definition rgb.h:84
static constexpr Rgb black()
Definition rgb.h:29
value_type * iterator
Definition rgb.h:19
constexpr iterator end()
Definition rgb.h:77
static constexpr Rgb muted_red()
Definition rgb.h:30
constexpr Rgb(value_type v)
Definition rgb.h:46
static constexpr Rgb red()
Definition rgb.h:31
static constexpr Rgb lightest_grey()
Definition rgb.h:23
static constexpr Rgb orange()
Definition rgb.h:41
static constexpr Rgb darkest_grey()
Definition rgb.h:28
static constexpr Rgb purple()
Definition rgb.h:42
constexpr const_iterator begin() const
Definition rgb.h:75
size_t size_type
Definition rgb.h:18
constexpr const_iterator end() const
Definition rgb.h:78
static constexpr Rgb cyan()
Definition rgb.h:37
static constexpr Rgb lighter_grey()
Definition rgb.h:24
const value_type * const_iterator
Definition rgb.h:20
constexpr reference operator[](size_type pos)
Definition rgb.h:69
const value_type & const_reference
Definition rgb.h:17
constexpr iterator begin()
Definition rgb.h:74
constexpr size_t size() const
Definition rgb.h:72
static constexpr Rgb darker_grey()
Definition rgb.h:27
T value_type
Definition rgb.h:15
not(std::convertible_to< U, T >)) const expr Rgb(const Rgb< U > &v)
Definition rgb.h:62
constexpr const_reference operator[](size_type pos) const
Definition rgb.h:70
static constexpr Rgb white()
Definition rgb.h:22
static constexpr Rgb green()
Definition rgb.h:33
static constexpr Rgb light_grey()
Definition rgb.h:25
static constexpr Rgb dark_green()
Definition rgb.h:34