1 // Copyright (c) 2017 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Quantity_ColorRGBAHasher_HeaderFile
15 #define _Quantity_ColorRGBAHasher_HeaderFile
17 #include <Quantity_ColorRGBA.hxx>
18 #include <Quantity_ColorHasher.hxx>
20 //! Hasher of Quantity_ColorRGBA.
21 struct Quantity_ColorRGBAHasher
24 //! Returns hash code for the given RGBA color, in the range [1, theUpperBound]
25 //! @param theColor the RGBA color object which hash code is to be computed
26 //! @param theUpperBound the upper bound of the range a computing hash code must be within
27 //! @return a computed hash code, in the range [1, theUpperBound]
28 static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
29 const Standard_Integer theUpperBound)
31 const NCollection_Vec4<float>& aColor = theColor;
32 uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
33 + (uint32_t(aColor.b() * 255.0f) << 16)
34 + (uint32_t(aColor.g() * 255.0f) << 8)
35 + uint32_t(aColor.r() * 255.0f);
36 return ::HashCode(aColor32, theUpperBound);
39 //! Returns true if two colors are equal.
40 static Standard_Boolean IsEqual (const Quantity_ColorRGBA& theColor1,
41 const Quantity_ColorRGBA& theColor2)
43 return theColor1 == theColor2;
48 #endif // _Quantity_ColorRGBAHasher_HeaderFile