1 #include "alg/color.hpp"
6 set(0.0, 0.0, 0.0, 0.0);
9 Color::Color(const Color &c)
11 set(c.colors[RedChannel],
12 c.colors[GreenChannel],
13 c.colors[BlueChannel],
14 c.colors[AlphaChannel]);
17 Color::Color(float red, float green, float blue, float alpha)
19 set(red, green, blue, alpha);
22 void Color::set(float r, float g, float b, float a)
24 colors[RedChannel] = r;
25 colors[GreenChannel] = g;
26 colors[BlueChannel] = b;
27 colors[AlphaChannel] = a;
30 const float *const Color::get() const
35 void Color::setR(float r)
37 colors[RedChannel] = r;
40 float Color::r() const
42 return colors[RedChannel];
45 void Color::setG(float g)
47 colors[GreenChannel] = g;
50 float Color::g() const
52 return colors[GreenChannel];
55 void Color::setB(float b)
57 colors[BlueChannel] = b;
60 float Color::b() const
62 return colors[BlueChannel];
65 void Color::setA(float a)
67 colors[AlphaChannel] = a;
70 float Color::a() const
72 return colors[AlphaChannel];
75 static bool close(float l, float r, float t=1e-6)
77 float difference = fabsf(l-r);
81 return (difference <= (t*l) or difference <= (t*r));
83 bool operator==(const Color &x, const Color &y)
85 return (close(x.colors[Color::RedChannel] ,y.colors[Color::RedChannel]) and
86 close(x.colors[Color::GreenChannel],y.colors[Color::GreenChannel]) and
87 close(x.colors[Color::BlueChannel] ,y.colors[Color::BlueChannel]) and
88 close(x.colors[Color::AlphaChannel],y.colors[Color::AlphaChannel]));
91 std::ostream &operator<<(std::ostream &out, const Color &c)
93 out << "Color(" << c.r() << ", "