浏览代码

Improved color comparison

Léo Terziman 12 年之前
父节点
当前提交
bc40ebd730
共有 3 个文件被更改,包括 22 次插入0 次删除
  1. 1 0
      include/assimp/color4.h
  2. 11 0
      include/assimp/color4.inl
  3. 10 0
      include/assimp/types.h

+ 1 - 0
include/assimp/color4.h

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

+ 11 - 0
include/assimp/color4.inl

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

+ 10 - 0
include/assimp/types.h

@@ -172,6 +172,16 @@ struct aiColor3D
 	bool operator != (const aiColor3D& other) const
 		{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 */
 	aiColor3D operator+(const aiColor3D& c) const {
 		return aiColor3D(r+c.r,g+c.g,b+c.b);