0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / MeshVS / MeshVS_TwoColors.cxx
1 // Created on: 2003-10-08
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2003-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <MeshVS_TwoColors.hxx>
22
23
24 //================================================================
25 // Function : HashCode
26 // Purpose  :
27 //================================================================
28 Standard_Integer HashCode ( const MeshVS_TwoColors&       theKey,
29                             const Standard_Integer theUpper)
30 {
31 #define MESHPRS_HASH_BYTE(val) { \
32     aHash += (val);              \
33     aHash += (aHash << 10);      \
34     aHash ^= (aHash >> 6);       \
35   }
36   Standard_Integer aHash = 0;
37   MESHPRS_HASH_BYTE (theKey.r1)
38   MESHPRS_HASH_BYTE (theKey.g1)
39   MESHPRS_HASH_BYTE (theKey.b1)
40   MESHPRS_HASH_BYTE (theKey.r2)
41   MESHPRS_HASH_BYTE (theKey.g2)
42   MESHPRS_HASH_BYTE (theKey.b2)
43   aHash += (aHash << 3);
44   aHash ^= (aHash >> 11);
45   aHash += (aHash << 15);
46   return (( aHash & 0x7fffffff ) % theUpper) + 1;
47 #undef MESHPRS_HASH_BYTE
48 }
49
50 //================================================================
51 // Function : IsEqual
52 // Purpose  :
53 //================================================================
54 Standard_Boolean IsEqual (const MeshVS_TwoColors& K1,
55                           const MeshVS_TwoColors& K2)
56 {
57   return (((K1.r1 * 256 + K1.g1) * 256 + K1.b1) ==
58           ((K2.r1 * 256 + K2.g1) * 256 + K2.b1) &&
59           ((K1.r2 * 256 + K1.g2) * 256 + K1.b2) ==
60           ((K2.r2 * 256 + K2.g2) * 256 + K2.b2));
61 }
62
63 //================================================================
64 // Function : operator ==
65 // Purpose  :
66 //================================================================
67 Standard_Boolean operator== ( const MeshVS_TwoColors& K1,
68                               const MeshVS_TwoColors& K2  )
69 {
70   return IsEqual ( K1, K2 );
71 }
72
73 //================================================================
74 // Function : BindTwoColors
75 // Purpose  :
76 //================================================================
77 MeshVS_TwoColors BindTwoColors ( const Quantity_Color& theCol1, const Quantity_Color& theCol2 )
78 {
79   MeshVS_TwoColors aRes;
80
81   aRes.r1 = unsigned ( theCol1.Red()   * 255.0 );
82   aRes.g1 = unsigned ( theCol1.Green() * 255.0 );
83   aRes.b1 = unsigned ( theCol1.Blue()  * 255.0 );
84   aRes.r2 = unsigned ( theCol2.Red()   * 255.0 );
85   aRes.g2 = unsigned ( theCol2.Green() * 255.0 );
86   aRes.b2 = unsigned ( theCol2.Blue()  * 255.0 );
87
88   return aRes;
89 }
90
91 //================================================================
92 // Function : ExtractColor
93 // Purpose  :
94 //================================================================
95 Quantity_Color ExtractColor ( MeshVS_TwoColors& theTwoColors, const Standard_Integer Index )
96 {
97   Quantity_Color aRes;
98   Standard_Real max = 255.0;
99
100   if ( Index == 1 )
101     aRes.SetValues ( Standard_Real (theTwoColors.r1) / max,
102                      Standard_Real (theTwoColors.g1) / max,
103                      Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
104   else if (Index == 2)
105     aRes.SetValues ( Standard_Real (theTwoColors.r2) / max,
106                      Standard_Real (theTwoColors.g2) / max,
107                      Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
108
109   return aRes;
110 }
111
112 //================================================================
113 // Function : ExtractColors
114 // Purpose  :
115 //================================================================
116 void ExtractColors ( MeshVS_TwoColors& theTwoColors, Quantity_Color& theCol1, Quantity_Color& theCol2 )
117 {
118   Standard_Real max = 255.0;
119   theCol1.SetValues ( Standard_Real (theTwoColors.r1) / max,
120                       Standard_Real (theTwoColors.g1) / max,
121                       Standard_Real (theTwoColors.b1) / max, Quantity_TOC_RGB );
122   theCol2.SetValues ( Standard_Real (theTwoColors.r2) / max,
123                       Standard_Real (theTwoColors.g2) / max,
124                       Standard_Real (theTwoColors.b2) / max, Quantity_TOC_RGB );
125 }