2015-01-15 14:03:44 +11:00
|
|
|
#include "colour.hpp"
|
2015-04-13 18:06:08 +10:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "tap.hpp"
|
2015-01-15 14:03:44 +11:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
2015-04-13 16:45:56 +10:00
|
|
|
util::TAP::logger tap;
|
|
|
|
|
2015-03-03 04:11:30 +11:00
|
|
|
// Simple check for symbol visibility
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_eq (util::colour4f::WHITE, util::colour4f (1), "WHITE available");
|
2015-04-09 20:45:55 +10:00
|
|
|
|
|
|
|
// Check casting works between intergral and floating formats
|
|
|
|
{
|
|
|
|
util::colour4f f (1);
|
|
|
|
util::colour<4,uint8_t> u (255);
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_eq (f.cast<uint8_t> (), u, "cast float to u8");
|
|
|
|
tap.expect_eq (u.cast<float> (), f, "cast u8 to float");
|
2015-04-09 20:45:55 +10:00
|
|
|
}
|
2015-04-09 20:46:55 +10:00
|
|
|
|
|
|
|
// Check lookups are working
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_eq (util::colour4f::from_html ("white"), util::colour4f::WHITE, "HTML lookup");
|
|
|
|
tap.expect_eq ( util::colour4f::from_x11 ("white"), util::colour4f::WHITE, "X11 lookup");
|
2015-04-09 21:50:42 +10:00
|
|
|
|
|
|
|
// Check HSV conversions
|
|
|
|
{
|
|
|
|
// white: hue is undefined
|
|
|
|
auto white = util::rgb_to_hsv ({1,1,1});
|
2015-11-16 11:42:20 +11:00
|
|
|
tap.expect (util::exactly_zero (white.s) && util::exactly_equal (white.v, 1), "white hsv");
|
2015-04-09 21:50:42 +10:00
|
|
|
|
|
|
|
// black: hue is undefined
|
|
|
|
auto black = util::rgb_to_hsv ({0,0,0});
|
2015-11-16 11:42:20 +11:00
|
|
|
tap.expect (util::exactly_zero (black.s) && util::exactly_zero (black.v), "black hsv");
|
2015-04-09 21:50:42 +10:00
|
|
|
|
|
|
|
struct {
|
2015-04-13 16:45:56 +10:00
|
|
|
const char *name;
|
2015-04-09 21:50:42 +10:00
|
|
|
util::colour3f rgb;
|
|
|
|
util::colour3f hsv;
|
|
|
|
} TESTS[] = {
|
2015-04-13 16:45:56 +10:00
|
|
|
{ "red", { 1, 0, 0, }, { 0, 1, 1, } }, // red
|
|
|
|
{ "green", { 0, 1, 0, }, { 120, 1, 1, } }, // green
|
|
|
|
{ "blue", { 0, 0, 1, }, { 240, 1, 1, } }, // blue
|
|
|
|
{ "misc", { 0.75f, 0.25f, 0.75f }, { 300, 2/3.f, 0.75f } },
|
2015-04-09 21:50:42 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto i: TESTS) {
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_eq (util::rgb_to_hsv (i.rgb), i.hsv, i.name);
|
|
|
|
tap.expect_eq (util::hsv_to_rgb (i.hsv), i.rgb, i.name);
|
2015-04-09 21:50:42 +10:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 14:03:44 +11:00
|
|
|
}
|