0027536: Visualization - incorrect behavior of zoom persisted objects
[occt.git] / src / MeshVS / MeshVS_ColorHasher.cxx
1 // Created on: 2003-12-05
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <MeshVS_ColorHasher.hxx>
18 #include <Quantity_Color.hxx>
19
20 //================================================================
21 // Function : HashCode
22 // Purpose  : 
23 //================================================================
24 Standard_Integer MeshVS_ColorHasher::HashCode ( const Quantity_Color& theCol, const Standard_Integer theUpper )
25 {
26   Standard_Integer r = Standard_Integer( 255 * theCol.Red   () ),
27                    g = Standard_Integer( 255 * theCol.Green () ),
28                    b = Standard_Integer( 255 * theCol.Blue  () );
29
30   #define MESHPRS_HASH_BYTE(val) { \
31     aHash += (val);              \
32     aHash += (aHash << 10);      \
33     aHash ^= (aHash >> 6);       \
34   }
35   Standard_Integer aHash = 0;
36   MESHPRS_HASH_BYTE ( r )
37   MESHPRS_HASH_BYTE ( g )
38   MESHPRS_HASH_BYTE ( b )
39   aHash += (aHash << 3);
40   aHash ^= (aHash >> 11);
41   aHash += (aHash << 15);
42   return (( aHash & 0x7fff ) % theUpper) + 1;
43   #undef MESHPRS_HASH_BYTE
44 }
45
46 //================================================================
47 // Function : IsEqual
48 // Purpose  : 
49 //================================================================
50 Standard_Boolean MeshVS_ColorHasher::IsEqual( const Quantity_Color& K1, const Quantity_Color& K2 )
51 {
52   return K1==K2;
53 }