0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / gp / gp_XYZ.lxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // LPA et JCV 07/92 
16
17 #include <gp.hxx>
18 #include <gp_Mat.hxx>
19 #include <Standard_ConstructionError.hxx>
20 #include <Standard_OutOfRange.hxx>
21
22 inline gp_XYZ::gp_XYZ () : x(0.), y(0.), z(0.) { }
23
24 inline gp_XYZ::gp_XYZ (const Standard_Real X,
25                        const Standard_Real Y,
26                        const Standard_Real Z) : x(X),y(Y),z(Z) { }
27
28 inline void gp_XYZ::SetCoord (const Standard_Real X,
29                               const Standard_Real Y,
30                               const Standard_Real Z)
31 { x = X;  y = Y;  z = Z; }
32
33 inline void gp_XYZ::SetCoord (const Standard_Integer i,
34                               const Standard_Real X) {
35   Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL);
36   (&x)[i-1] = X;
37 }
38
39 inline void gp_XYZ::SetX (const Standard_Real X)
40 { x = X; }
41
42 inline void gp_XYZ::SetY (const Standard_Real Y)
43 { y = Y; }
44
45 inline void gp_XYZ::SetZ (const Standard_Real Z) 
46 { z = Z; }
47
48 inline Standard_Real gp_XYZ::Coord (const Standard_Integer i) const {
49   Standard_OutOfRange_Raise_if( i < 1 || i > 3,NULL);
50   return (&x)[i-1];
51 }
52
53 inline Standard_Real& gp_XYZ::ChangeCoord(const Standard_Integer theIndex)
54 {
55   Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > 3,NULL);
56   return (&x)[theIndex - 1];
57 }
58
59 inline void gp_XYZ::Coord (Standard_Real& X,
60                            Standard_Real& Y,
61                            Standard_Real& Z) const
62 { X = x; Y = y; Z = z; }
63
64 inline Standard_Real gp_XYZ::X () const
65 { return x; }
66
67 inline Standard_Real gp_XYZ::Y () const
68 { return y; }
69
70 inline Standard_Real gp_XYZ::Z () const
71 { return z; }
72
73 inline Standard_Real gp_XYZ::Modulus () const { 
74   return sqrt (x * x + y * y + z * z);
75 }
76
77 inline Standard_Real gp_XYZ::SquareModulus () const {
78   return (x * x + y * y + z * z);
79 }
80
81 inline void gp_XYZ::Add (const gp_XYZ& Other)
82 {
83   x += Other.x;
84   y += Other.y;
85   z += Other.z;
86 }
87
88 inline gp_XYZ gp_XYZ::Added (const gp_XYZ& Other) const {
89   return gp_XYZ(x + Other.x,y + Other.y,z + Other.z);
90 }
91
92 inline void gp_XYZ::Cross (const gp_XYZ& Right)
93 {
94   Standard_Real Xresult = y * Right.z - z * Right.y;
95   Standard_Real Yresult = z * Right.x - x * Right.z;
96   z                     = x * Right.y - y * Right.x;
97   x = Xresult;
98   y = Yresult;
99 }
100
101 inline gp_XYZ gp_XYZ::Crossed (const gp_XYZ& Right) const
102 {
103   return gp_XYZ (y * Right.z - z * Right.y,
104                  z * Right.x - x * Right.z,
105                  x * Right.y - y * Right.x);
106 }
107
108 inline Standard_Real gp_XYZ::CrossMagnitude (const gp_XYZ& Right) const
109 {
110   Standard_Real Xresult = y * Right.z - z * Right.y;
111   Standard_Real Yresult = z * Right.x - x * Right.z;
112   Standard_Real Zresult = x * Right.y - y * Right.x;
113   return sqrt(Xresult * Xresult + Yresult * Yresult + Zresult * Zresult);
114 }
115
116 inline Standard_Real gp_XYZ::CrossSquareMagnitude (const gp_XYZ& Right) const
117 {
118   Standard_Real Xresult = y * Right.z - z * Right.y;
119   Standard_Real Yresult = z * Right.x - x * Right.z;
120   Standard_Real Zresult = x * Right.y - y * Right.x;
121   return Xresult * Xresult + Yresult * Yresult + Zresult * Zresult;
122 }
123
124 inline void gp_XYZ::CrossCross (const gp_XYZ& Coord1,
125                                 const gp_XYZ& Coord2)
126 {
127   Standard_Real Xresult = 
128     y * (Coord1.x * Coord2.y - Coord1.y * Coord2.x) -
129       z * (Coord1.z * Coord2.x - Coord1.x * Coord2.z);
130   Standard_Real Yresult  = 
131     z * (Coord1.y * Coord2.z - Coord1.z * Coord2.y) -
132       x * (Coord1.x * Coord2.y - Coord1.y * Coord2.x);
133   z = 
134     x * (Coord1.z * Coord2.x - Coord1.x * Coord2.z) -
135       y * (Coord1.y * Coord2.z - Coord1.z * Coord2.y);
136   x = Xresult;
137   y = Yresult;
138 }
139
140 inline gp_XYZ gp_XYZ::CrossCrossed (const gp_XYZ& Coord1,
141                                     const gp_XYZ& Coord2) const
142 {
143   gp_XYZ Coord0 = *this;
144   Coord0.CrossCross (Coord1, Coord2);
145   return Coord0;
146 }
147
148 inline void gp_XYZ::Divide (const Standard_Real Scalar)
149 {
150   x /= Scalar;
151   y /= Scalar;
152   z /= Scalar;
153 }
154
155 inline gp_XYZ gp_XYZ::Divided (const Standard_Real Scalar) const {
156   return gp_XYZ(x / Scalar,y / Scalar,z / Scalar);
157 }
158
159 inline Standard_Real gp_XYZ::Dot (const gp_XYZ& Other) const {
160   return(x * Other.x + y * Other.y + z * Other.z);
161 }
162
163 inline Standard_Real gp_XYZ::DotCross (const gp_XYZ& Coord1,
164                                        const gp_XYZ& Coord2) const
165 {
166   Standard_Real Xresult = Coord1.y * Coord2.z - Coord1.z * Coord2.y;
167   Standard_Real Yresult = Coord1.z * Coord2.x - Coord1.x * Coord2.z;
168   Standard_Real Zresult = Coord1.x * Coord2.y - Coord1.y * Coord2.x;
169   return ( x * Xresult + y * Yresult + z * Zresult);
170 }
171
172 inline void gp_XYZ::Multiply (const Standard_Real Scalar)
173 {
174   x *= Scalar;
175   y *= Scalar;
176   z *= Scalar;
177 }
178
179 inline void gp_XYZ::Multiply (const gp_XYZ& Other)
180 {
181   x *= Other.x;
182   y *= Other.y;
183   z *= Other.z;
184 }
185
186 inline void gp_XYZ::Multiply (const gp_Mat& Matrix)
187 {
188   Standard_Real Xresult = Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z;
189   Standard_Real Yresult = Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z;
190   z                     = Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z;
191   x                     = Xresult;
192   y                     = Yresult;
193 }
194
195 inline gp_XYZ gp_XYZ::Multiplied (const Standard_Real Scalar) const {
196   return gp_XYZ(x * Scalar,y * Scalar,z * Scalar);
197 }
198
199 inline gp_XYZ gp_XYZ::Multiplied (const gp_XYZ& Other) const {
200   return gp_XYZ(x * Other.x, y * Other.y, z * Other.z);
201 }
202
203 inline gp_XYZ gp_XYZ::Multiplied (const gp_Mat& Matrix) const
204 {
205   return gp_XYZ (Matrix.matrix[0][0] * x + Matrix.matrix[0][1] * y + Matrix.matrix[0][2] * z,
206                  Matrix.matrix[1][0] * x + Matrix.matrix[1][1] * y + Matrix.matrix[1][2] * z,
207                  Matrix.matrix[2][0] * x + Matrix.matrix[2][1] * y + Matrix.matrix[2][2] * z);
208 }
209
210 inline void gp_XYZ::Normalize ()
211 {
212   Standard_Real D = Modulus();
213   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
214                                        "gp_XYZ::Normalize() - vector has zero norm");
215   x = x / D;  y = y / D;  z = z / D;
216 }
217
218 inline gp_XYZ gp_XYZ::Normalized () const
219 {
220   Standard_Real D = Modulus();
221   Standard_ConstructionError_Raise_if (D <= gp::Resolution(),
222                                        "gp_XYZ::Normalized() - vector has zero norm");
223   return gp_XYZ (x / D, y / D, z / D);
224 }
225
226 inline void gp_XYZ::Reverse ()
227 {
228   x = - x;
229   y = - y;
230   z = - z;
231 }
232
233 inline gp_XYZ gp_XYZ::Reversed () const
234 {
235   return gp_XYZ(-x, -y, -z);
236 }
237
238 inline void gp_XYZ::Subtract (const gp_XYZ& Right)
239 {
240   x-=Right.x;
241   y-=Right.y;
242   z-=Right.z;
243 }
244
245 inline gp_XYZ gp_XYZ::Subtracted (const gp_XYZ& Right) const
246 {
247   return gp_XYZ(x - Right.x, y - Right.y, z - Right.z);
248 }
249
250 inline void gp_XYZ::SetLinearForm (const Standard_Real L, 
251                                    const gp_XYZ& Left,
252                                    const Standard_Real R, 
253                                    const gp_XYZ& Right) {
254   
255   x = L * Left.x + R * Right.x;
256   y = L * Left.y + R * Right.y;
257   z = L * Left.z + R * Right.z; 
258 }
259
260 inline void gp_XYZ::SetLinearForm(const Standard_Real L, 
261                                   const gp_XYZ& Left,
262                                   const gp_XYZ& Right) {
263   x = L * Left.x + Right.x;
264   y = L * Left.y + Right.y;
265   z = L * Left.z + Right.z;
266 }
267
268 inline void gp_XYZ::SetLinearForm (const gp_XYZ& Left, const gp_XYZ& Right) {
269   x = Left.x + Right.x;
270   y = Left.y + Right.y;
271   z = Left.z + Right.z;
272 }
273
274 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
275                                    const Standard_Real A2, const gp_XYZ& XYZ2, 
276                                    const Standard_Real A3, const gp_XYZ& XYZ3) {
277   
278   x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x;
279   y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y;
280   z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z;  
281 }
282
283 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
284                                    const Standard_Real A2, const gp_XYZ& XYZ2, 
285                                    const gp_XYZ& XYZ3) {
286   x = A1 * XYZ1.x + A2 * XYZ2.x + XYZ3.x;
287   y = A1 * XYZ1.y + A2 * XYZ2.y + XYZ3.y;
288   z = A1 * XYZ1.z + A2 * XYZ2.z + XYZ3.z;
289 }
290
291 inline void gp_XYZ::SetLinearForm (const Standard_Real A1, const gp_XYZ& XYZ1,
292                                    const Standard_Real A2, const gp_XYZ& XYZ2, 
293                                    const Standard_Real A3, const gp_XYZ& XYZ3,
294                                    const gp_XYZ& XYZ4) {
295   x = A1 * XYZ1.x + A2 * XYZ2.x + A3 * XYZ3.x + XYZ4.x;
296   y = A1 * XYZ1.y + A2 * XYZ2.y + A3 * XYZ3.y + XYZ4.y;
297   z = A1 * XYZ1.z + A2 * XYZ2.z + A3 * XYZ3.z + XYZ4.z;
298   
299 }
300
301 inline gp_XYZ operator* (const gp_Mat& Matrix, const gp_XYZ& Coord1) {
302   return Coord1.Multiplied (Matrix);
303 }
304
305 inline gp_XYZ operator* (const Standard_Real Scalar, const gp_XYZ& Coord1) {
306   return Coord1.Multiplied (Scalar);
307 }
308
309
310
311
312
313