-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolor.h
72 lines (63 loc) · 1.55 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef COLOR_H
#define COLOR_H
#include <cmath>
namespace htwk {
struct color {
int cy;
int cb;
int cr;
color() = default;
color(int _cy, int _cb, int _cr) : cy(_cy), cb(_cb), cr(_cr) {}
color(const color&) = default;
color(color&&) = default;
color& operator=(const color&) = default;
color& operator=(color&&) = default;
~color() = default;
float dist(const color& o, float color_weight) {
color d = *this - o;
d.cb *= color_weight;
d.cr *= color_weight;
return std::sqrt(d.cy * d.cy + d.cb * d.cb + d.cr * d.cr);
}
color& operator+=(const color& rhs) {
cy += rhs.cy;
cb += rhs.cb;
cr += rhs.cr;
return *this;
}
friend color operator+(color lhs, const color& rhs) {
lhs += rhs;
return lhs;
}
color& operator-=(const color& rhs) {
cy -= rhs.cy;
cb -= rhs.cb;
cr -= rhs.cr;
return *this;
}
friend color operator-(color lhs, const color& rhs) {
lhs -= rhs;
return lhs;
}
friend color operator*(color lhs, float rhs) {
lhs.cy *= rhs;
lhs.cb *= rhs;
lhs.cr *= rhs;
return lhs;
}
friend color operator*(float lhs, const color& rhs) {
return rhs * lhs;
}
color& operator/=(float rhs) {
cy /= rhs;
cb /= rhs;
cr /= rhs;
return *this;
}
friend color operator/(color lhs, float rhs) {
lhs /= rhs;
return lhs;
}
};
} // namespace htwk
#endif // COLOR_H