MathLib
Loading...
Searching...
No Matches
TestColorConversion.cpp
Go to the documentation of this file.
2#include <cassert>
3#include <iostream>
4#include <cstdlib>
5
6
8{
9
10using namespace Color;
11using namespace Math::Literals;
12
14{
15 std::cout << __func__ << std::endl;
16
17 {
18 UnitRGBf red{ 1.0, 0.0, 0.0 };
20
21 assert( hsv_representation.hue().value() == 0.0f );
24 assert( hsv_representation.value() == 1.0f );
25 }
26
27 {
28 UnitRGBf green{ 0.0, 1.0, 0.0 };
29 HSVf hsv_representation{ ToHSV( green ) };
30
34 assert( hsv_representation.value() == 1.0f );
35 }
36
37 {
38 UnitRGBf blue{ 0.0, 0.0, 1.0 };
39 HSVf hsv_representation{ ToHSV( blue ) };
40
44 assert( hsv_representation.value() == 1.0f );
45 }
46
47 {
48 UnitRGBf cyan{ 0.0, 1.0, 1.0 };
50
54 assert( hsv_representation.value() == 1.0f );
55 }
56
57 {
58 UnitRGBf magenta{ 1.0, 0.0, 1.0 };
60
64 assert( hsv_representation.value() == 1.0f );
65 }
66
67 {
68 UnitRGBf yellow{ 1.0, 1.0, 0.0 };
70
74 assert( hsv_representation.value() == 1.0f );
75 }
76}
77
79{
80 std::cout << __func__ << std::endl;
81
82 UnitRGBf black{ 0.0, 0.0, 0.0 };
84
85 // Hue is irrelevant (could be any hue)
86
88 assert( hsv_representation.value() == 0.0f );
89}
90
92{
93 std::cout << __func__ << std::endl;
94
95 UnitRGBf black{ 0.0, 0.0, 0.0 };
97
98 // Not really important, but it HAS to be a hue
99 assert( hsv_representation.hue().value() == 0.0f );
101}
102
104{
105 std::cout << __func__ << std::endl;
106
107 UnitRGBf white{ 1.0, 1.0, 1.0 };
109
111 assert( hsv_representation.value() == 1.0f );
112}
113
115{
116 std::cout << __func__ << std::endl;
117
118 UnitRGBf white{ 1.0, 1.0, 1.0 };
120
121 // Not really important, but it HAS to be a hue (could be any hue)
122 assert( hsv_representation.hue().value() == 0.0f );
124}
125
127{
128 std::cout << __func__ << std::endl;
129
130 UnitRGBf grey{ 0.5, 0.5, 0.5 };
132
133 // Not really important, but it HAS to be a hue (could be any hue)
134 assert( hsv_representation.hue().value() == 0.0f );
136
138 assert( hsv_representation.value() == 0.5f );
139}
140
142{
143 std::cout << __func__ << std::endl;
144
145 {
146 UnitRGBf cyan{ 0.0, 1.0, 1.0 };
148
149 assert( hsv_representation.hue().value() == 180.0f );
152 assert( hsv_representation.value() == 1.0f );
153 }
154
155 {
156 UnitRGBf magenta{ 1.0, 0.0, 1.0 };
158
159 assert( hsv_representation.hue().value() == 300.0f );
162 assert( hsv_representation.value() == 1.0f );
163 }
164
165 {
166 UnitRGBf yellow{ 1.0, 1.0, 0.0 };
168
169 assert( hsv_representation.hue().value() == 60.0f );
172 assert( hsv_representation.value() == 1.0f );
173 }
174}
175
177{
178 std::cout << __func__ << std::endl;
179
180 {
181 HSVf red{ 0.0_deg_f, 1.0f, 1.0f };
183
184 assert( rgb_representation.red() == 1.0f );
185 assert( rgb_representation.green() == 0.0f );
186 assert( rgb_representation.blue() == 0.0f );
187 }
188
189 {
190 HSVf green{ 120.0_deg_f, 1.0f, 1.0f };
192
193 assert( rgb_representation.red() == 0.0f );
194 assert( rgb_representation.green() == 1.0f );
195 assert( rgb_representation.blue() == 0.0f );
196 }
197
198 {
199 HSVf blue{ 240.0_deg_f, 1.0f, 1.0f };
201
202 assert( rgb_representation.red() == 0.0f );
203 assert( rgb_representation.green() == 0.0f );
204 assert( rgb_representation.blue() == 1.0f );
205 }
206}
207
209{
210 std::cout << __func__ << std::endl;
211
212 {
213 HSVf cyan{ 180.0_deg_f, 1.0, 1.0 };
215
216 assert( rgb_representation.red() == 0.0f );
217 assert( rgb_representation.green() == 1.0f );
218 assert( rgb_representation.blue() == 1.0f );
219 }
220
221 {
222 HSVf magenta{ 300.0_deg_f, 1.0, 1.0 };
224
225 assert( rgb_representation.red() == 1.0f );
226 assert( rgb_representation.green() == 0.0f );
227 assert( rgb_representation.blue() == 1.0f );
228 }
229
230 {
231 HSVf yellow{ 60.0_deg_f, 1.0, 1.0 };
233
234 assert( rgb_representation.red() == 1.0f );
235 assert( rgb_representation.green() == 1.0f );
236 assert( rgb_representation.blue() == 0.0f );
237 }
238}
239
241{
242 std::cout << __func__ << std::endl;
243
244 {
245 HSVf black{ 0.0_deg_f, 1.0, 0.0 };
247
248 assert( rgb_representation.red() == 0.0f );
249 assert( rgb_representation.green() == 0.0f );
250 assert( rgb_representation.blue() == 0.0f );
251 }
252
253 {
254 HSVf white{ 0.0_deg_f, 0.0, 1.0 };
256
257 assert( rgb_representation.red() == 1.0f );
258 assert( rgb_representation.green() == 1.0f );
259 assert( rgb_representation.blue() == 1.0f );
260 }
261}
262
263void Run()
264{
265 std::cout << "Running Color Conversion Tests..." << std::endl;
266
274
278
279 std::cout << "PASSED!" << std::endl;
280}
281
282}
283
284int main(void)
285{
287 return EXIT_SUCCESS;
288}
int main(void)
constexpr value_type saturation() const
Definition Types.hpp:849
constexpr Math::BasicDegree< value_type > hue() const
Definition Types.hpp:848
constexpr enum Color hueColor() const
Definition Types.hpp:872
constexpr value_type value() const
Definition Types.hpp:850
void GreyHasHueAndSaturationOfZeroAndValueOf50Percent()
BasicHSV< T > ToHSV(const BasicUnitRGB< T > &input)
BasicUnitRGB< T > ToRGB(const BasicHSV< T > &input_hsv)