-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColour.h
193 lines (166 loc) · 6.11 KB
/
Colour.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* $Rev: 250 $ */
#pragma once
#ifndef COLOUR_H_INCLUDED
#define COLOUR_H_INCLUDED
/**
* \file
* \brief Colour class header file.
*/
/**
* \brief Class to store colour information.
*
* Colours are an important aspect of Material objects, and the
* basic quanitity that a ray tracer comptues for a ray. Colours
* are represented as RGB triples, with values in the range [0,1].
* Note that during computation, Colour values may go outside of the
* range [0,1]. Because of this, these bounds are not enforced. However
* Colours can be brought back into this range with the clip() method.
*
* Colour objects also have basic arithmetic operators defined on them.
* These are applied independently to each component. This is an important
* distinction from Vector and Matrix objects, which have particular rules
* for arithmetic (particularly multiplication).
*/
class Colour {
public:
/** \brief Colour default constructor.
*
* Creates a new colour with all values set to 0 (black).
*/
Colour();
/** \brief Colour constructor.
*
* Creates a new colour with the given red, green, and blue values.
*
* \param r The red value of the new Colour.
* \param g The green value of the new Colour.
* \param b The blue value of the new Colour.
*/
Colour(double r, double g, double b);
/** \brief Colour copy constructor.
*
* \param colour The Colour to copy.
*/
Colour(const Colour& colour);
/** \brief Colour destructor. */
~Colour();
/** \brief Colour assignment operator.
*
* \param colour The Colour to assign to \c this.
* \return A reference to \c this to allow for chaining of assignment.
*/
Colour& operator=(const Colour& colour);
/** \brief Colour unary negation.
*
* Given a Colour (R, G, B), the negated Colour is (-R, -G, -B).
*
* \return The negated Colour.
*/
Colour operator-() const;
/** \brief Colour addition.
*
* Given two Colours, (R1, G1, B1) and (R2, G2, B2), their sum is (R1+R2, G1+G2, B1+B2).
*
* \param lhs The Colour on the left hand side of the + operator.
* \param rhs The Colour on the right hand side of the + operator.
* \return The sum of lhs and rhs.
*/
friend Colour operator+(const Colour& lhs, const Colour& rhs);
/** \brief Colour addition-assignment operator
*
* Add one Colour to another in place.
*
* \param colour The Colour to add to \c this.
* \return A reference to the updated \c this, to allow chaining of assignment.
*/
Colour& operator+=(const Colour& colour);
/** \brief Colour subtraction.
*
* Given two Colours, (R1, G1, B1) and (R2, G2, B2), their difference is (R1-R2, G1-G2, B1-B2).
*
* \param lhs The Colour on the left hand side of the - operator.
* \param rhs The Colour on the right hand side of the - operator.
* \return The difference between lhs and rhs.
*/
friend Colour operator-(const Colour& lhs, const Colour& rhs);
/** \brief Colour subtraction-assignment operator
*
* Subtract one Colour from another in place.
*
* \param colour The Colour to subtract from \c this.
* \return A reference to the updated \c this, to allow chaining of assignment.
*/
Colour& operator-=(const Colour& colour);
/** \brief Colour multiplication.
*
* Given two Colours, (R1, G1, B1) and (R2, G2, B2), their product is (R1*R2, G1*G2, B1*B2).
* Note that this is different from the usual Vector dot and cross products.
*
* \param lhs The Colour on the left hand side of the * operator.
* \param rhs The Colour on the right hand side of the * operator.
* \return The product of lhs and rhs.
*/
friend Colour operator*(const Colour& lhs, const Colour& rhs);
/** \brief Colour multiplication-assignment operator
*
* Multiply one Colour by another in place.
*
* \param colour The Colour to multiply \c this by.
* \return A reference to the updated \c this, to allow chaining of assignment.
*/
Colour& operator*=(const Colour& colour);
/** \brief Scalar-Colour multiplication.
*
* The product of a Colour, (R, G, B) and a scalar, s, is (s*R, s*G, s*B).
*
* \param s The scalar on the left hand side of the * operator.
* \param colour The Colour on the right hand side of the * operator.
* \return The product of lhs and rhs.
*/
friend Colour operator*(double s, const Colour& colour);
/** \brief Colour-scalar multiplication.
*
* The product of a Colour, (R, G, B) and a scalar, s, is (s*R, s*G, s*B).
*
* \param colour The Colour on the left hand side of the * operator.
* \param s The scalar on the right hand side of the * operator.
* \return The product of lhs and rhs.
*/
friend Colour operator*(const Colour& colour, double s);
/** \brief Colour-scalar multiplication-assignment operator
*
* Multiply a Colour by a scalar in place.
*
* \param s The scalar to multiply \c this by.
* \return A reference to the updated \c this, to allow chaining of assignment.
*/
Colour& operator*=(double s);
/** \brief Colour-scalar division.
*
* The division of a Colour, (R, G, B) by a scalar, s, is (R/s, G/s, B/s).
*
* \param colour The Colour on the left hand side of the / operator.
* \param s The scalar on the right hand side of the / operator.
* \return The division of lhs by rhs.
*/
friend Colour operator/(const Colour& colour, double s);
/** \brief Colour-scalar division-assignment operator
*
* Divide a Colour by a scalar in place.
*
* \param s The scalar to divide \c this by.
* \return A reference to the updated \c this, to allow chaining of assignment.
*/
Colour& operator/=(double s);
/** \brief Enforce bounds on Colour components.
*
* Colour component values should lie in the range [0,1], but during computation
* it is sometimes valid for values to lie outside this range. This method clips
* values to this range by simple truncation.
*/
void clip();
double red; //!< The red component of the Colour.
double green; //!< The green component of the Colour.
double blue; //!< The blue component of the Colour.
};
#endif