24#include <boost/test/unit_test.hpp>
49 const auto c =
COLOR4D{ 0.4, 0.5, 0.6, 0.7 };
51 BOOST_CHECK_EQUAL( c.r, 0.4 );
52 BOOST_CHECK_EQUAL( c.g, 0.5 );
53 BOOST_CHECK_EQUAL( c.b, 0.6 );
54 BOOST_CHECK_EQUAL( c.a, 0.7 );
56 const auto copied = c;
59 BOOST_CHECK_EQUAL( c, copied );
61 const auto c2 =
COLOR4D{ 0.1, 0.2, 0.3, 0.4 };
64 BOOST_CHECK_NE( c, c2 );
86 static const std::vector<COLOR_SCALAR_CASE> cases = {
87 { { 0.0, 0.25, 1.0, 1.0 }, 0.0, { 1.0, 0.75, 0.0, 1.0 } },
90 for(
const auto& c : cases )
94 const auto inverted = col.Inverted();
95 BOOST_CHECK_EQUAL( inverted, c.expected );
99 BOOST_CHECK_EQUAL( col, c.expected );
109 static const std::vector<COLOR_SCALAR_CASE> cases = {
110 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.5, 0.5, 0.5, 1.0 } },
111 { { 0.0, 0.5, 1.0, 1.0 }, 0.5, { 0.5, 0.75, 1.0, 1.0 } },
114 for(
const auto& c : cases )
118 const auto brightened = col.Brightened( c.factor );
119 BOOST_CHECK_EQUAL( brightened, c.expected );
122 col.Brighten( c.factor );
123 BOOST_CHECK_EQUAL( col, c.expected );
133 static const std::vector<COLOR_SCALAR_CASE> cases = {
134 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.0, 0.0, 0.0, 1.0 } },
135 { { 1.0, 1.0, 1.0, 1.0 }, 0.5, { 0.5, 0.5, 0.5, 1.0 } },
138 for(
const auto& c : cases )
142 const auto brightened = col.Darkened( c.factor );
143 BOOST_CHECK_EQUAL( brightened, c.expected );
146 col.Darken( c.factor );
147 BOOST_CHECK_EQUAL( col, c.expected );
157 static const std::vector<COLOR_SCALAR_CASE> cases = {
158 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.0, 0.0, 0.0, 0.5 } },
159 { { 0.0, 0.5, 1.0, 1.0 }, 0.5, { 0.0, 0.5, 1.0, 0.5 } },
162 for(
const auto& c : cases )
166 const auto with_alpha = col.WithAlpha( c.factor );
167 BOOST_CHECK_EQUAL( with_alpha, c.expected );
191 static const std::vector<FROM_HSV_TO_HEX_CASE> cases = {
192 { 10, 0.71, 0.66, 168, 69, 49 },
193 { 15, 0.96, 0.34, 87, 24, 3 },
194 { 120, 0.50, 0.50, 64, 128, 64 },
195 { 190, 0.32, 0.97, 168, 234, 247 },
196 { 240, 0.15, 0.75, 163, 163, 191 },
197 { 240, 0.90, 0.75, 19, 19, 191 },
198 { 310, 0.71, 0.66, 168, 49, 148 },
199 { 331, 0.15, 0.85, 217, 184, 200 },
202 for(
const auto& c : cases )
206 double new_h, new_s, new_v;
207 col.ToHSV( new_h, new_s, new_v );
208 const unsigned char alpha = 0xFF;
211 BOOST_CHECK_CLOSE( c.h, new_h, 0.0001 );
212 BOOST_CHECK_CLOSE( c.s, new_s, 0.0001 );
213 BOOST_CHECK_CLOSE( c.v, new_v, 0.0001 );
233 static const std::vector<FROM_HSL_TO_HEX_CASE> cases = {
234 { 10, 0.71, 0.66, 230, 127, 107 },
235 { 15, 0.96, 0.34, 170, 45, 3 },
236 { 120, 0.5, 0.5, 64, 191, 64 },
237 { 190, 0.32, 0.97, 245, 249, 250 },
238 { 240, 0.15, 0.75, 182, 182, 201 },
239 { 240, 0.90, 0.75, 134, 134, 249 },
240 { 310, 0.71, 0.66, 230, 107, 209 },
241 { 331, 0.15, 0.85, 222, 211, 217 },
244 for(
const auto& c : cases )
248 double new_h, new_s, new_l;
249 col.ToHSL( new_h, new_s, new_l );
250 const unsigned char alpha = 0xFF;
253 BOOST_CHECK_CLOSE( c.h, new_h, 0.0001 );
254 BOOST_CHECK_CLOSE( c.s, new_s, 0.0001 );
255 BOOST_CHECK_CLOSE( c.l, new_l, 0.0001 );
268 { { 0x00, 0x00, 0x00, 0x00 }, { 0.0, 0.0, 0.0, 0.0 } },
269 { { 0x66, 0x80, 0x99, 0xB3 }, { 0.4, 0.5, 0.6, 0.7 } },
270 { { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0, 1.0, 1.0, 1.0 } },
271 { { 0xFF, 0x00, 0x00, 0xFF }, { 0.999, 0.001, 0.0, 1.0 } },
282 wxColour wx_col = c.c4d.ToColour();
285 BOOST_CHECK_EQUAL( wx_col.Red(), c.wx.Red() );
286 BOOST_CHECK_EQUAL( wx_col.Green(), c.wx.Green() );
287 BOOST_CHECK_EQUAL( wx_col.Blue(), c.wx.Blue() );
288 BOOST_CHECK_EQUAL( wx_col.Alpha(), c.wx.Alpha() );
298 const double tol = 0.5 / 255.0;
302 const auto col =
COLOR4D{ c.wx };
314 std::hash<COLOR4D> colorHasher;
316 COLOR4D a( 0.5, 0.5, 0.5, 0.5 );
317 COLOR4D b( 0.5, 0.5, 0.5, 0.5 );
319 BOOST_CHECK_EQUAL( a.
Compare( b ), 0 );
320 BOOST_CHECK_EQUAL( colorHasher( a ), colorHasher( b ) );
323 BOOST_CHECK_GT( a.
Compare( b ), 0 );
324 BOOST_CHECK_NE( colorHasher( a ), colorHasher( b ) );
327 BOOST_CHECK_LT( a.
Compare( b ), 0 );
331 BOOST_CHECK_GT( a.
Compare( b ), 0 );
334 BOOST_CHECK_LT( a.
Compare( b ), 0 );
338 BOOST_CHECK_GT( a.
Compare( b ), 0 );
341 BOOST_CHECK_LT( a.
Compare( b ), 0 );
345 BOOST_CHECK_GT( a.
Compare( b ), 0 );
348 BOOST_CHECK_LT( a.
Compare( b ), 0 );
A color representation with 4 components: red, green, blue, alpha.
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
int Compare(const COLOR4D &aRhs) const
void FromHSL(double aInHue, double aInSaturation, double aInLightness)
Change currently used color to the one given by hue, saturation and lightness parameters.
Test utilities for COLOUR4D objects.
The Cairo implementation of the graphics abstraction layer.
bool IsColorNearHex(const KIGFX::COLOR4D &aCol, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Checks if a COLOR4D is close enough to a given RGB char value.
bool IsColorNear(const KIGFX::COLOR4D &aCol, const KIGFX::COLOR4D aOther, double aTol)
Checks if a COLOR4D is close enough to another.
Test case data for a test that takes a colour and a scalar factor and returns a result.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(BasicOps)
Declares a struct as the Boost test fixture.
static std::vector< WX_CONV_CASE > wx_conv_cases
BOOST_AUTO_TEST_SUITE_END()