-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colour.cpp
104 lines (80 loc) · 1.87 KB
/
Colour.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* $Rev: 250 $ */
#include "Colour.h"
Colour::Colour() :
red(0), green(0), blue(0) {
}
Colour::Colour(double r, double g, double b) :
red(r), green(g), blue(b) {
}
Colour::Colour(const Colour& colour) :
red(colour.red), green(colour.green), blue(colour.blue) {
}
Colour::~Colour() {
}
Colour& Colour::operator=(const Colour& colour) {
if (this != &colour) {
red = colour.red;
green = colour.green;
blue = colour.blue;
}
return *this;
}
Colour Colour::operator-() const {
return Colour(-red, -green, -blue);
}
Colour operator+(const Colour& lhs, const Colour& rhs) {
return Colour(lhs) += rhs;
}
Colour& Colour::operator+=(const Colour& colour) {
red += colour.red;
green += colour.green;
blue += colour.blue;
return *this;
}
Colour operator-(const Colour& lhs, const Colour& rhs) {
return Colour(lhs) -= rhs;
}
Colour& Colour::operator-=(const Colour& colour) {
red -= colour.red;
green -= colour.green;
blue -= colour.blue;
return *this;
}
Colour operator*(const Colour& lhs, const Colour& rhs) {
return Colour(lhs) *= rhs;
}
Colour& Colour::operator*=(const Colour& colour) {
red *= colour.red;
green *= colour.green;
blue *= colour.blue;
return *this;
}
Colour operator*(double s, const Colour& colour) {
return Colour(colour) *= s;
}
Colour operator*(const Colour& colour, double s) {
return Colour(colour) *= s;
}
Colour& Colour::operator*=(double s) {
red *= s;
green *= s;
blue *= s;
return *this;
}
Colour operator/(const Colour& colour, double s) {
return Colour(colour) /= s;
}
Colour& Colour::operator/=(double s) {
red /= s;
green /= s;
blue /= s;
return *this;
}
void Colour::clip() {
if (red < 0) red = 0;
if (red > 1) red = 1;
if (green < 0) green = 0;
if (green > 1) green = 1;
if (blue < 0) blue = 0;
if (blue > 1) blue = 1;
}