-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.h
executable file
·45 lines (38 loc) · 1000 Bytes
/
color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <string>
#include "util.h"
class Color {
public:
float r, g, b;
Color(float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
Color() : Color(0,0,0) {}
void setColor(const float& _r, const float& _g, const float& _b) {
r = _r; g = _g; b = _b;
}
std::string toString() const {
const auto N = 50;
char buffer[N];
std::snprintf(buffer, N, "COLOR[%f, %f, %f]", r, g, b);
return buffer;
}
bool operator==(const Color& c) const {
return (isEqualEnough(r, c.r) &&
isEqualEnough(g, c.g) &&
isEqualEnough(b, c.b) );
}
Color operator+(const Color& c) const {
return Color(r+c.r, g+c.g, b+c.b);
}
Color operator-(const Color& c) const {
return Color(r-c.r, g-c.g, b-c.b);
}
Color operator*(const float a) const {
return Color(r*a, g*a, b*a);
}
Color operator*(const Color& c) const {
return Color(r*c.r, g*c.g, b*c.b);
}
};
inline Color operator*(float a, Color c) {
return c * a;
}