Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (104 sloc) 2.11 KB
#include "Colors.hpp"
using namespace raytracer;
using namespace std;
Color::Color():
red(0.0), green(0.0), blue(0.0)
{
}
Color::Color(float red, float green, float blue):
red(red), green(green), blue(blue)
{
}
Color& Color::operator+=(const Color &rhs)
{
this->red += rhs.red;
this->green += rhs.green;
this->blue += rhs.blue;
return *this;
}
Color& Color::operator-=(const Color &rhs)
{
this->red -= rhs.red;
this->green -= rhs.green;
this->blue -= rhs.blue;
return *this;
}
Color& Color::operator*=(const Scalar &rhs)
{
this->red *= rhs;
this->green *= rhs;
this->blue *= rhs;
return *this;
}
Color& Color::operator/=(const Scalar &rhs)
{
this->red /= rhs;
this->green /= rhs;
this->blue /= rhs;
return *this;
}
const component& Color::get_red() const
{
return this->red;
}
const component& Color::get_green() const
{
return this->green;
}
const component& Color::get_blue() const
{
return this->blue;
}
void Color::set_red(const component& red)
{
this->red = red;
}
void Color::set_green(const component& green)
{
this->green = green;
}
void Color::set_blue(const component& blue)
{
this->blue = blue;
}
Color raytracer::operator+(const Color& op1, const Color& op2)
{
Color res = op1;
res+=op2;
return res;
}
Color raytracer::operator-(const Color& op1, const Color& op2)
{
Color res = op1;
res-=op2;
return res;
}
Color raytracer::operator*(const Scalar& op1, const Color& op2)
{
return operator*(op2,op1);
}
Color raytracer::operator*(const Color& op1, const Scalar& op2)
{
Color res = op1;
res*=op2;
return res;
}
Color raytracer::operator/(const Color& op1, const Scalar& op2)
{
Color res = op1;
res/=op2;
return res;
}
std::ostream& raytracer::operator<<(std::ostream& os, const Color &c)
{
os << " ( " << c.get_red() << ", "
<< c.get_green() << ", "
<< c.get_blue() << ") ";
return os;
}
bool Color::operator==(const Color &rhs) const
{
return (this->red == rhs.red) &&
(this->green == rhs.green) &&
(this->blue == rhs.blue);
}