Clean up basics::Color
This commit is contained in:
parent
4b396cabe8
commit
d085a192e8
1 changed files with 147 additions and 100 deletions
|
@ -10,7 +10,7 @@ namespace charles {
|
|||
namespace basics {
|
||||
|
||||
/*
|
||||
* Color::Color --
|
||||
* charles::basics::Color::Color --
|
||||
*/
|
||||
Color::Color()
|
||||
: Color(0.0, 0.0, 0.0, 0.0)
|
||||
|
@ -18,7 +18,7 @@ Color::Color()
|
|||
|
||||
|
||||
/*
|
||||
* Color::Color --
|
||||
* charles::basics::Color::Color --
|
||||
*/
|
||||
Color::Color(const Double& r,
|
||||
const Double& g,
|
||||
|
@ -32,90 +32,10 @@ Color::Color(const Double& r,
|
|||
|
||||
|
||||
/*
|
||||
* Color::operator*= --
|
||||
* Color::operator/= --
|
||||
* Color::operator+= --
|
||||
* Color::operator-= --
|
||||
*
|
||||
* Perform the corresponding arithmetic operation on this color and the given scalar. These methods are destructive and
|
||||
* a reference to this color is returned.
|
||||
* charles::basics::Color::operator= --
|
||||
*/
|
||||
Color &
|
||||
Color::operator*=(const Double &rhs)
|
||||
{
|
||||
red *= rhs;
|
||||
green *= rhs;
|
||||
blue *= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator/=(const Double &rhs)
|
||||
{
|
||||
return *this *= (1.0 / rhs);
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator+=(const Double &rhs)
|
||||
{
|
||||
red += rhs;
|
||||
green += rhs;
|
||||
blue += rhs;
|
||||
alpha += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator-=(const Double &rhs)
|
||||
{
|
||||
return *this += -rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Color::operator* --
|
||||
* Color::operator/ --
|
||||
* Color::operator+ --
|
||||
* Color::operator- --
|
||||
*
|
||||
* Perform the corresponding operation on a copy of this color and the given scalar. Return a new vector.
|
||||
*/
|
||||
Color
|
||||
Color::operator*(const Double &rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) *= rhs;
|
||||
}
|
||||
|
||||
Color
|
||||
Color::operator/(const Double &rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) /= rhs;
|
||||
}
|
||||
|
||||
Color
|
||||
Color::operator+(const Double &rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) += rhs;
|
||||
}
|
||||
|
||||
Color
|
||||
Color::operator-(const Double &rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) -= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Color::operator= --
|
||||
*
|
||||
* Copy the given color's values into this color. Return a reference to this color.
|
||||
*/
|
||||
Color &
|
||||
Color::operator=(const Color &rhs)
|
||||
Color&
|
||||
Color::operator=(const Color& rhs)
|
||||
{
|
||||
red = rhs.red;
|
||||
green = rhs.green;
|
||||
|
@ -125,8 +45,102 @@ Color::operator=(const Color &rhs)
|
|||
}
|
||||
|
||||
|
||||
Color &
|
||||
Color::operator*=(const Color &rhs)
|
||||
/*
|
||||
* charles::basics::Color::operator*= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator*=(const Double& rhs)
|
||||
{
|
||||
red *= rhs;
|
||||
green *= rhs;
|
||||
blue *= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator/= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator/=(const Double& rhs)
|
||||
{
|
||||
return *this *= (1.0 / rhs);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator+= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator+=(const Double& rhs)
|
||||
{
|
||||
red += rhs;
|
||||
green += rhs;
|
||||
blue += rhs;
|
||||
alpha += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator-= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator-=(const Double& rhs)
|
||||
{
|
||||
return *this += -rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator* --
|
||||
*/
|
||||
Color
|
||||
Color::operator*(const Double& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) *= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator/ --
|
||||
*/
|
||||
Color
|
||||
Color::operator/(const Double& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) /= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator+ --
|
||||
*/
|
||||
Color
|
||||
Color::operator+(const Double& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) += rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator- --
|
||||
*/
|
||||
Color
|
||||
Color::operator-(const Double& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) -= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator*= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator*=(const Color& rhs)
|
||||
{
|
||||
red *= rhs.red;
|
||||
green *= rhs.green;
|
||||
|
@ -134,17 +148,25 @@ Color::operator*=(const Color &rhs)
|
|||
return *this;
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator/=(const Color &rhs)
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator/= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator/=(const Color& rhs)
|
||||
{
|
||||
red *= (1.0 / rhs.red);
|
||||
green *= (1.0 / rhs.green);
|
||||
blue *= (1.0 / rhs.blue);
|
||||
red /= rhs.red;
|
||||
green /= rhs.green;
|
||||
blue /= rhs.blue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator+=(const Color &rhs)
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator+= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator+=(const Color& rhs)
|
||||
{
|
||||
red += rhs.red;
|
||||
green += rhs.green;
|
||||
|
@ -153,8 +175,12 @@ Color::operator+=(const Color &rhs)
|
|||
return *this;
|
||||
}
|
||||
|
||||
Color &
|
||||
Color::operator-=(const Color &rhs)
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator-= --
|
||||
*/
|
||||
Color&
|
||||
Color::operator-=(const Color& rhs)
|
||||
{
|
||||
red -= rhs.red;
|
||||
green -= rhs.green;
|
||||
|
@ -164,35 +190,53 @@ Color::operator-=(const Color &rhs)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator* --
|
||||
*/
|
||||
Color
|
||||
Color::operator*(const Color &rhs)
|
||||
Color::operator*(const Color& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) *= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator/ --
|
||||
*/
|
||||
Color
|
||||
Color::operator/(const Color &rhs)
|
||||
Color::operator/(const Color& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) /= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator+ --
|
||||
*/
|
||||
Color
|
||||
Color::operator+(const Color &rhs)
|
||||
Color::operator+(const Color& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) += rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Color::operator- --
|
||||
*/
|
||||
Color
|
||||
Color::operator-(const Color &rhs)
|
||||
Color::operator-(const Color& rhs)
|
||||
const
|
||||
{
|
||||
return Color(*this) -= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::operator* --
|
||||
*/
|
||||
const Color
|
||||
operator*(const Double& lhs,
|
||||
const Color& rhs)
|
||||
|
@ -201,6 +245,9 @@ operator*(const Double& lhs,
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::operator<< --
|
||||
*/
|
||||
std::ostream &
|
||||
operator<<(std::ostream& os,
|
||||
const Color& c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue