Ray Tracer  2020
Public Member Functions | Public Attributes | Related Functions | List of all members
Colour Class Reference

Class to store colour information. More...

#include <Colour.h>

Public Member Functions

 Colour ()
 Colour default constructor. More...
 
 Colour (double r, double g, double b)
 Colour constructor. More...
 
 Colour (const Colour &colour)
 Colour copy constructor. More...
 
 ~Colour ()
 Colour destructor. More...
 
Colouroperator= (const Colour &colour)
 Colour assignment operator. More...
 
Colour operator- () const
 Colour unary negation. More...
 
Colouroperator+= (const Colour &colour)
 Colour addition-assignment operator. More...
 
Colouroperator-= (const Colour &colour)
 Colour subtraction-assignment operator. More...
 
Colouroperator*= (const Colour &colour)
 Colour multiplication-assignment operator. More...
 
Colouroperator*= (double s)
 Colour-scalar multiplication-assignment operator. More...
 
Colouroperator/= (double s)
 Colour-scalar division-assignment operator. More...
 
void clip ()
 Enforce bounds on Colour components. More...
 

Public Attributes

double red
 The red component of the Colour. More...
 
double green
 The green component of the Colour. More...
 
double blue
 The blue component of the Colour. More...
 

Related Functions

(Note that these are not member functions.)

Colour operator+ (const Colour &lhs, const Colour &rhs)
 Colour addition. More...
 
Colour operator- (const Colour &lhs, const Colour &rhs)
 Colour subtraction. More...
 
Colour operator* (const Colour &lhs, const Colour &rhs)
 Colour multiplication. More...
 
Colour operator* (double s, const Colour &colour)
 Scalar-Colour multiplication. More...
 
Colour operator* (const Colour &colour, double s)
 Colour-scalar multiplication. More...
 
Colour operator/ (const Colour &colour, double s)
 Colour-scalar division. More...
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ Colour() [1/3]

Colour::Colour ( )

Colour default constructor.

Creates a new colour with all values set to 0 (black).

◆ Colour() [2/3]

Colour::Colour ( double  r,
double  g,
double  b 
)

Colour constructor.

Creates a new colour with the given red, green, and blue values.

Parameters
rThe red value of the new Colour.
gThe green value of the new Colour.
bThe blue value of the new Colour.

◆ Colour() [3/3]

Colour::Colour ( const Colour colour)

Colour copy constructor.

Parameters
colourThe Colour to copy.

◆ ~Colour()

Colour::~Colour ( )

Colour destructor.

Member Function Documentation

◆ clip()

void Colour::clip ( )

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.

◆ operator*=() [1/2]

Colour & Colour::operator*= ( const Colour colour)

Colour multiplication-assignment operator.

Multiply one Colour by another in place.

Parameters
colourThe Colour to multiply this by.
Returns
A reference to the updated this, to allow chaining of assignment.

◆ operator*=() [2/2]

Colour & Colour::operator*= ( double  s)

Colour-scalar multiplication-assignment operator.

Multiply a Colour by a scalar in place.

Parameters
sThe scalar to multiply this by.
Returns
A reference to the updated this, to allow chaining of assignment.

◆ operator+=()

Colour & Colour::operator+= ( const Colour colour)

Colour addition-assignment operator.

Add one Colour to another in place.

Parameters
colourThe Colour to add to this.
Returns
A reference to the updated this, to allow chaining of assignment.

◆ operator-()

Colour Colour::operator- ( ) const

Colour unary negation.

Given a Colour (R, G, B), the negated Colour is (-R, -G, -B).

Returns
The negated Colour.

◆ operator-=()

Colour & Colour::operator-= ( const Colour colour)

Colour subtraction-assignment operator.

Subtract one Colour from another in place.

Parameters
colourThe Colour to subtract from this.
Returns
A reference to the updated this, to allow chaining of assignment.

◆ operator/=()

Colour & Colour::operator/= ( double  s)

Colour-scalar division-assignment operator.

Divide a Colour by a scalar in place.

Parameters
sThe scalar to divide this by.
Returns
A reference to the updated this, to allow chaining of assignment.

◆ operator=()

Colour & Colour::operator= ( const Colour colour)

Colour assignment operator.

Parameters
colourThe Colour to assign to this.
Returns
A reference to this to allow for chaining of assignment.

Friends And Related Function Documentation

◆ operator*() [1/3]

Colour operator* ( const Colour colour,
double  s 
)
related

Colour-scalar multiplication.

The product of a Colour, (R, G, B) and a scalar, s, is (s*R, s*G, s*B).

Parameters
colourThe Colour on the left hand side of the * operator.
sThe scalar on the right hand side of the * operator.
Returns
The product of lhs and rhs.

◆ operator*() [2/3]

Colour operator* ( const Colour lhs,
const Colour rhs 
)
related

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.

Parameters
lhsThe Colour on the left hand side of the * operator.
rhsThe Colour on the right hand side of the * operator.
Returns
The product of lhs and rhs.

◆ operator*() [3/3]

Colour operator* ( double  s,
const Colour colour 
)
related

Scalar-Colour multiplication.

The product of a Colour, (R, G, B) and a scalar, s, is (s*R, s*G, s*B).

Parameters
sThe scalar on the left hand side of the * operator.
colourThe Colour on the right hand side of the * operator.
Returns
The product of lhs and rhs.

◆ operator+()

Colour operator+ ( const Colour lhs,
const Colour rhs 
)
related

Colour addition.

Given two Colours, (R1, G1, B1) and (R2, G2, B2), their sum is (R1+R2, G1+G2, B1+B2).

Parameters
lhsThe Colour on the left hand side of the + operator.
rhsThe Colour on the right hand side of the + operator.
Returns
The sum of lhs and rhs.

◆ operator-()

Colour operator- ( const Colour lhs,
const Colour rhs 
)
related

Colour subtraction.

Given two Colours, (R1, G1, B1) and (R2, G2, B2), their difference is (R1-R2, G1-G2, B1-B2).

Parameters
lhsThe Colour on the left hand side of the - operator.
rhsThe Colour on the right hand side of the - operator.
Returns
The difference between lhs and rhs.

◆ operator/()

Colour operator/ ( const Colour colour,
double  s 
)
related

Colour-scalar division.

The division of a Colour, (R, G, B) by a scalar, s, is (R/s, G/s, B/s).

Parameters
colourThe Colour on the left hand side of the / operator.
sThe scalar on the right hand side of the / operator.
Returns
The division of lhs by rhs.

Member Data Documentation

◆ blue

double Colour::blue

The blue component of the Colour.

◆ green

double Colour::green

The green component of the Colour.

◆ red

double Colour::red

The red component of the Colour.


The documentation for this class was generated from the following files: