4
4
5
5
#include " Color.hpp"
6
6
7
+ #include < cmath>
8
+ #include < iostream>
9
+
7
10
namespace jngl {
8
11
9
12
Rgb::Rgb (float red, float green, float blue) : red(red), green(green), blue(blue) {
@@ -44,6 +47,18 @@ void Rgb::setBlue(const float blue) {
44
47
this ->blue = blue;
45
48
}
46
49
50
+ uint8_t Rgb::getRed_u8 () const {
51
+ return static_cast <uint8_t >(std::lround (red * 255 .f ));
52
+ }
53
+
54
+ uint8_t Rgb::getGreen_u8 () const {
55
+ return static_cast <uint8_t >(std::lround (green * 255 .f ));
56
+ }
57
+
58
+ uint8_t Rgb::getBlue_u8 () const {
59
+ return static_cast <uint8_t >(std::lround (blue * 255 .f ));
60
+ }
61
+
47
62
Rgb::operator Color () const {
48
63
return Color{ static_cast <unsigned char >(red * 255 ), static_cast <unsigned char >(green * 255 ),
49
64
static_cast <unsigned char >(blue * 255 ) };
@@ -54,6 +69,16 @@ Rgb interpolate(Rgb a, Rgb b, float t) {
54
69
a.getBlue () * (1 .f - t) + b.getBlue () * t };
55
70
}
56
71
72
+ bool operator ==(Rgb a, Rgb b) {
73
+ return a.getRed_u8 () == b.getRed_u8 () && a.getGreen_u8 () == b.getGreen_u8 () &&
74
+ a.getBlue_u8 () == b.getBlue_u8 ();
75
+ }
76
+
77
+ std::ostream& operator <<(std::ostream& os, Rgb color) {
78
+ os << " jngl::Rgb{ " << color.getRed () << " , " << color.getGreen () << " , " << color.getBlue () << " }" ;
79
+ return os;
80
+ }
81
+
57
82
} // namespace jngl
58
83
59
84
jngl::Rgb operator " " _rgb(const unsigned long long hex) {
0 commit comments