0028738: Data Exchange, XCAFPrs_Style - add transparency property
[occt.git] / src / Quantity / Quantity_ColorRGBAHasher.hxx
diff --git a/src/Quantity/Quantity_ColorRGBAHasher.hxx b/src/Quantity/Quantity_ColorRGBAHasher.hxx
new file mode 100644 (file)
index 0000000..73f388f
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright (c) 2017 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Quantity_ColorRGBAHasher_HeaderFile
+#define _Quantity_ColorRGBAHasher_HeaderFile
+
+#include <Quantity_ColorRGBA.hxx>
+#include <Quantity_ColorHasher.hxx>
+
+//! Hasher of Quantity_ColorRGBA.
+struct Quantity_ColorRGBAHasher
+{
+
+  //! Returns hash code for the given color.
+  static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
+                                    const Standard_Integer    theUpper)
+  {
+    const NCollection_Vec4<float>& aColor = theColor;
+    uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
+                      + (uint32_t(aColor.b() * 255.0f) << 16)
+                      + (uint32_t(aColor.g() * 255.0f) << 8)
+                      +  uint32_t(aColor.r() * 255.0f);
+    return ((aColor32 & 0x7fffffff) % theUpper) + 1;
+  }
+
+  //! Returns true if two colors are equal.
+  static Standard_Boolean IsEqual (const Quantity_ColorRGBA& theColor1,
+                                   const Quantity_ColorRGBA& theColor2)
+  {
+    return theColor1 == theColor2;
+  }
+
+};
+
+#endif // _Quantity_ColorRGBAHasher_HeaderFile