Modernize `CColor` class

* Use `constexpr`
* Add c'tor for `float` to avoid unnecassary conversions if arguments are
  already `float`
* Simplify syntax in `operator==`
This commit is contained in:
Martchus 2023-01-30 17:18:43 +01:00
parent 39882a6db6
commit 36b970ebcb
1 changed files with 20 additions and 12 deletions

View File

@ -48,22 +48,30 @@
class CColor
{
public:
CColor() { red = green = blue = 0; }
constexpr CColor()
: red(0.0f)
, green(0.0f)
, blue(0.0f)
{}
CColor(double r, double g, double b)
constexpr CColor(float r, float g, float b)
: red(r)
, green(g)
, blue(b)
{}
constexpr CColor(double r, double g, double b)
: red(static_cast<float>(r))
, green(static_cast<float>(g))
, blue(static_cast<float>(b))
{}
constexpr bool operator==(CColor color)
{
red = static_cast<float>(r);
green = static_cast<float>(g);
blue = static_cast<float>(b);
return red == color.red && green == color.green && blue == color.blue;
}
float red, green, blue;
bool operator==(CColor color)
{
if (red == color.red && green == color.green && blue == color.blue)
return true;
return false;
}
};
/*!