-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.cpp
More file actions
53 lines (44 loc) · 1.28 KB
/
Color.cpp
File metadata and controls
53 lines (44 loc) · 1.28 KB
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
/**
* \author Marie DARRIGOL & Anthony LEONARD & Ophélie PELLOUX-PRAYER & Olivier SOLDANO
* \project Ray-Tracing
* \file color.cpp
* \brief represent a RGB color without alpha
*/
#include "Color.h"
#include <algorithm>
/**
*\fn Color::Color()
*\brief constructs a RGB color descriptor that is perfectly black
*/
Color::Color() : Vec3() {}
/**
*\fn Color::Color(float r, float g, float b)
*\brief constructs a RGB color descriptor with r,g, and b in [0.0 , 1.0]
*/
Color::Color(float r, float g, float b): Vec3(r,g,b){}
/**
*\fn Color::Color(int r, int g, int b)
*\brief constructs a RGB color descriptor with r,g, and b integers and in [0;255]
reducing those standard integer values to the float range [0.0 , 1.0]
*/
Color::Color(int r, int g, int b) : Vec3(((float) r) / 255.0f,
((float) g) / 255.0f,
((float) b) / 255.0f) {}
/**
*\fn Color::Color(const Vec3 &c)
*\brief copy constructor
*/
Color::Color(const Vec3 &c): Vec3(c){}
/**
*\fn void Color::normalise()
*\brief corrects the overflows
*/
void Color::normalise() {
float max_overflow = max(max(this->getX(), this->getY()), this->getZ());
if (max_overflow > 1.0f) {
this->setX(this->getX() / max_overflow);
this->setY(this->getY() / max_overflow);
this->setZ(this->getZ() / max_overflow);
}
}
Color::~Color(){}