0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Quantity / Quantity_ColorRGBAHasher.hxx
CommitLineData
a71a71de 1// Copyright (c) 2017 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _Quantity_ColorRGBAHasher_HeaderFile
15#define _Quantity_ColorRGBAHasher_HeaderFile
16
17#include <Quantity_ColorRGBA.hxx>
18#include <Quantity_ColorHasher.hxx>
19
20//! Hasher of Quantity_ColorRGBA.
21struct Quantity_ColorRGBAHasher
22{
23
24 //! Returns hash code for the given color.
25 static Standard_Integer HashCode (const Quantity_ColorRGBA& theColor,
26 const Standard_Integer theUpper)
27 {
28 const NCollection_Vec4<float>& aColor = theColor;
29 uint32_t aColor32 = (uint32_t(aColor.a() * 255.0f) << 24)
30 + (uint32_t(aColor.b() * 255.0f) << 16)
31 + (uint32_t(aColor.g() * 255.0f) << 8)
32 + uint32_t(aColor.r() * 255.0f);
33 return ((aColor32 & 0x7fffffff) % theUpper) + 1;
34 }
35
36 //! Returns true if two colors are equal.
37 static Standard_Boolean IsEqual (const Quantity_ColorRGBA& theColor1,
38 const Quantity_ColorRGBA& theColor2)
39 {
40 return theColor1 == theColor2;
41 }
42
43};
44
45#endif // _Quantity_ColorRGBAHasher_HeaderFile