geometry: Allow basic color arithmetic

This commit is contained in:
kd-11 2020-01-07 17:10:15 +03:00 committed by kd-11
parent ad845861be
commit 071e73a68e
1 changed files with 40 additions and 1 deletions

View File

@ -856,7 +856,7 @@ struct color4_base
{
}
constexpr color4_base(T x, T y = {}, T z = {}, T w = {})
constexpr color4_base(T x, T y, T z, T w)
: x(x)
, y(y)
, z(z)
@ -864,6 +864,14 @@ struct color4_base
{
}
constexpr color4_base(T value)
: x(value)
, y(value)
, z(value)
, w(value)
{
}
constexpr bool operator == (const color4_base& rhs) const
{
return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
@ -874,6 +882,37 @@ struct color4_base
return !(*this == rhs);
}
void operator *= (const color4_base<T>& rhs)
{
r *= rhs.r;
g *= rhs.g;
b *= rhs.b;
a *= rhs.a;
}
void operator *= (const T& rhs)
{
r *= rhs;
g *= rhs;
b *= rhs;
a *= rhs;
}
constexpr color4_base<T> operator * (const color4_base<T>& rhs) const
{
return { r * rhs.r, g * rhs.g, b * rhs.b, a * rhs.a };
}
constexpr color4_base<T> operator * (const T& rhs) const
{
return { r * rhs, g * rhs, b * rhs, a * rhs };
}
constexpr color4_base<T> operator + (const color4_base<T>& rhs) const
{
return { r + rhs.r, g + rhs.g, b + rhs.b, a + rhs.a };
}
template<typename NT>
constexpr operator color4_base<NT>() const
{