-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.h
106 lines (86 loc) · 2.1 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
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
//
// Created by marti on 06-Sep-21.
//
#ifndef RT_COLOR_H
#define RT_COLOR_H
#include <string>
#include "Point.h"
struct Color {
Color(double r, double g, double b){
this->r = r;
this->g = g;
this->b = b;
}
explicit Color(double all){
this->r = all;
this->g = all;
this->b = all;
}
Color(){
this->r = 0;
this->g = 0;
this->b = 0;
}
void Print(){
std::cout << "(" << r << ", " << g << ", " << b << ")" << std::endl;
}
Color operator* (const double d){ //FIXME: these aren't working for some reason
Color col;
col.r = this->r * d;
col.g = this->g * d;
col.b = this->b * d;
return col;
}
// Color operator* (double d){
// Color col(1, 1, 1);
//// col.r = r * d;
//
// return col;
// }
Color clip() const{
Color clipped(this->r, this->g, this->b);
if(clipped.r > 1) clipped.r = 1;
if(clipped.g > 1) clipped.g = 1;
if(clipped.b > 1) clipped.b = 1;
return clipped;
}
Color operator* (Color c){ //just changed this
Color col;
col.r = this->r * c.r;
col.g = this->g * c.g;
col.b = this->b * c.b;
return col;
}
Color operator+ (Color c){
Color col;
col.r = this->r + c.r;
col.g = this->g + c.g;
col.b = this->b + c.b;
return col;
}
Color operator+= (Color c){
this->r += c.r;
this->g += c.g;
this->b += c.b;
// return *this; //needed?
}
Color operator/= (double d){ //this couldn't be a reference... weird.
this->r /= d;
this->g /= d;
this->b /= d;
return *this; //needed?
}
Color operator= (Color c){
this->r = c.r;
this->g = c.g;
this->b = c.b;
return *this;
}
bool operator== (Color c){ //this couldn't be a reference... weird.
return (this->r == c.r && this->g == c.g && this->b == c.b);
}
double r;
double g;
double b;
};
#endif //RT_COLOR_H