Improved color comparison

pull/261/head
Léo Terziman 2013-10-28 11:46:07 +01:00
parent 647eab6ae9
commit bc40ebd730
3 changed files with 22 additions and 0 deletions

View File

@ -74,6 +74,7 @@ public:
// comparison // comparison
bool operator == (const aiColor4t& other) const; bool operator == (const aiColor4t& other) const;
bool operator != (const aiColor4t& other) const; bool operator != (const aiColor4t& other) const;
bool operator < (const aiColor4t& other) const;
// color tuple access, rgba order // color tuple access, rgba order
inline TReal operator[](unsigned int i) const; inline TReal operator[](unsigned int i) const;

View File

@ -94,6 +94,17 @@ AI_FORCE_INLINE bool aiColor4t<TReal>::operator!= (const aiColor4t<TReal>& other
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename TReal> template <typename TReal>
AI_FORCE_INLINE bool aiColor4t<TReal>::operator< (const aiColor4t<TReal>& other) const {
return r < other.r || (
r == other.r && (g < other.g ||
g == other.g && (b < other.b ||
b == other.b && a < other.a
)
)
);
}
// ------------------------------------------------------------------------------------------------
template <typename TReal>
AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) { AI_FORCE_INLINE aiColor4t<TReal> operator + (const aiColor4t<TReal>& v1, const aiColor4t<TReal>& v2) {
return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a); return aiColor4t<TReal>( v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a);
} }

View File

@ -172,6 +172,16 @@ struct aiColor3D
bool operator != (const aiColor3D& other) const bool operator != (const aiColor3D& other) const
{return r != other.r || g != other.g || b != other.b;} {return r != other.r || g != other.g || b != other.b;}
/** Component-wise comparison */
// TODO: add epsilon?
bool operator < (const aiColor3D& other) const {
return r < other.r || (
r == other.r && (g < other.g ||
g == other.g && b < other.b
)
);
}
/** Component-wise addition */ /** Component-wise addition */
aiColor3D operator+(const aiColor3D& c) const { aiColor3D operator+(const aiColor3D& c) const {
return aiColor3D(r+c.r,g+c.g,b+c.b); return aiColor3D(r+c.r,g+c.g,b+c.b);