b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | |
20 | #include <gp_Vec.hxx> |
21 | #include <gp_Trsf.hxx> |
22 | #include <Standard_ConstructionError.hxx> |
23 | #include <Standard_OutOfRange.hxx> |
24 | |
25 | inline gp_Dir::gp_Dir () : coord(1.,0.,0.) |
26 | { |
27 | } |
28 | |
29 | inline gp_Dir::gp_Dir (const gp_Vec& V) |
30 | { |
31 | const gp_XYZ& XYZ = V.XYZ(); |
32 | Standard_Real X = XYZ.X(); |
33 | Standard_Real Y = XYZ.Y(); |
34 | Standard_Real Z = XYZ.Z(); |
35 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
36 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
37 | coord.SetX(X / D); |
38 | coord.SetY(Y / D); |
39 | coord.SetZ(Z / D); |
40 | } |
41 | |
42 | inline gp_Dir::gp_Dir (const gp_XYZ& XYZ) |
43 | { |
44 | Standard_Real X = XYZ.X(); |
45 | Standard_Real Y = XYZ.Y(); |
46 | Standard_Real Z = XYZ.Z(); |
47 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
48 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
49 | coord.SetX(X / D); |
50 | coord.SetY(Y / D); |
51 | coord.SetZ(Z / D); |
52 | } |
53 | |
54 | inline gp_Dir::gp_Dir (const Standard_Real Xv, |
55 | const Standard_Real Yv, |
56 | const Standard_Real Zv) |
57 | { |
58 | Standard_Real D = sqrt (Xv * Xv + Yv * Yv + Zv * Zv); |
59 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
60 | coord.SetX(Xv / D); |
61 | coord.SetY(Yv / D); |
62 | coord.SetZ(Zv / D); |
63 | } |
64 | |
65 | inline void gp_Dir::SetCoord (const Standard_Integer Index, |
66 | const Standard_Real Xi) |
67 | { |
68 | Standard_Real X = coord.X(); |
69 | Standard_Real Y = coord.Y(); |
70 | Standard_Real Z = coord.Z(); |
71 | Standard_OutOfRange_Raise_if (Index < 1 || Index > 3, " "); |
72 | if (Index == 1) X = Xi; |
73 | else if (Index == 2) Y = Xi; |
74 | else Z = Xi; |
75 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
76 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
77 | coord.SetX(X / D); |
78 | coord.SetY(Y / D); |
79 | coord.SetZ(Z / D); |
80 | } |
81 | |
82 | inline void gp_Dir::SetCoord (const Standard_Real Xv, |
83 | const Standard_Real Yv, |
84 | const Standard_Real Zv) { |
85 | Standard_Real D = sqrt(Xv * Xv + Yv * Yv + Zv * Zv); |
86 | Standard_ConstructionError_Raise_if(D <= gp::Resolution(), ""); |
87 | coord.SetX(Xv / D); |
88 | coord.SetY(Yv / D); |
89 | coord.SetZ(Zv / D); |
90 | } |
91 | |
92 | inline void gp_Dir::SetX (const Standard_Real X) |
93 | { |
94 | Standard_Real Y = coord.Y(); |
95 | Standard_Real Z = coord.Z(); |
96 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
97 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
98 | coord.SetX(X / D); |
99 | coord.SetY(Y / D); |
100 | coord.SetZ(Z / D); |
101 | } |
102 | |
103 | inline void gp_Dir::SetY (const Standard_Real Y) |
104 | { |
105 | Standard_Real Z = coord.Z(); |
106 | Standard_Real X = coord.X(); |
107 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
108 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
109 | coord.SetX(X / D); |
110 | coord.SetY(Y / D); |
111 | coord.SetZ(Z / D); |
112 | } |
113 | |
114 | inline void gp_Dir::SetZ (const Standard_Real Z) |
115 | { |
116 | Standard_Real X = coord.X(); |
117 | Standard_Real Y = coord.Y(); |
118 | Standard_Real D = sqrt (X * X + Y * Y + Z * Z); |
119 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
120 | coord.SetX(X / D); |
121 | coord.SetY(Y / D); |
122 | coord.SetZ(Z / D); |
123 | } |
124 | |
125 | inline void gp_Dir::SetXYZ (const gp_XYZ& XYZ) |
126 | { |
127 | Standard_Real X = XYZ.X(); |
128 | Standard_Real Y = XYZ.Y(); |
129 | Standard_Real Z = XYZ.Z(); |
130 | Standard_Real D = sqrt(X * X + Y * Y + Z * Z); |
131 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
132 | coord.SetX(X / D); |
133 | coord.SetY(Y / D); |
134 | coord.SetZ(Z / D); |
135 | } |
136 | |
137 | inline Standard_Real gp_Dir::Coord (const Standard_Integer Index) const |
138 | { return coord.Coord (Index);} |
139 | |
140 | inline void gp_Dir::Coord (Standard_Real& Xv, |
141 | Standard_Real& Yv, |
142 | Standard_Real& Zv) const |
143 | { coord.Coord (Xv, Yv, Zv); } |
144 | |
145 | inline Standard_Real gp_Dir::X() const |
146 | { return coord.X() ; } |
147 | |
148 | inline Standard_Real gp_Dir::Y() const |
149 | { return coord.Y() ; } |
150 | |
151 | inline Standard_Real gp_Dir::Z() const |
152 | { return coord.Z() ; } |
153 | |
154 | inline const gp_XYZ& gp_Dir::XYZ () const |
155 | { return coord; } |
156 | |
157 | inline Standard_Boolean gp_Dir::IsEqual |
158 | (const gp_Dir& Other, |
159 | const Standard_Real AngularTolerance) const |
160 | { return Angle (Other) <= AngularTolerance; } |
161 | |
162 | inline Standard_Boolean gp_Dir::IsNormal |
163 | (const gp_Dir& Other, |
164 | const Standard_Real AngularTolerance) const |
165 | { |
c6541a0c |
166 | Standard_Real Ang = M_PI / 2.0 - Angle (Other); |
7fd59977 |
167 | if (Ang < 0) Ang = - Ang; |
168 | return Ang <= AngularTolerance; |
169 | } |
170 | |
171 | inline Standard_Boolean gp_Dir::IsOpposite |
172 | (const gp_Dir& Other, |
173 | const Standard_Real AngularTolerance) const |
c6541a0c |
174 | { return M_PI - Angle (Other) <= AngularTolerance; } |
7fd59977 |
175 | |
176 | inline Standard_Boolean gp_Dir::IsParallel |
177 | (const gp_Dir& Other, |
178 | const Standard_Real AngularTolerance) const |
179 | { |
180 | Standard_Real Ang = Angle (Other); |
c6541a0c |
181 | return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance; |
7fd59977 |
182 | } |
183 | |
184 | inline void gp_Dir::Cross (const gp_Dir& Right) |
185 | { |
186 | coord.Cross (Right.coord); |
187 | Standard_Real D = coord.Modulus (); |
188 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
189 | coord.Divide (D); |
190 | } |
191 | |
192 | inline gp_Dir gp_Dir::Crossed (const gp_Dir& Right) const |
193 | { |
194 | gp_Dir V = *this; |
195 | V.coord.Cross (Right.coord); |
196 | Standard_Real D = V.coord.Modulus(); |
197 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
198 | V.coord.Divide (D); |
199 | return V; |
200 | } |
201 | |
202 | inline void gp_Dir::CrossCross (const gp_Dir& V1, |
203 | const gp_Dir& V2) |
204 | { |
205 | coord.CrossCross (V1.coord, V2.coord); |
206 | Standard_Real D = coord.Modulus(); |
207 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
208 | coord.Divide(D); |
209 | } |
210 | |
211 | inline gp_Dir gp_Dir::CrossCrossed (const gp_Dir& V1, |
212 | const gp_Dir& V2) const |
213 | { |
214 | gp_Dir V = *this; |
215 | (V.coord).CrossCross (V1.coord, V2.coord); |
216 | Standard_Real D = V.coord.Modulus(); |
217 | Standard_ConstructionError_Raise_if (D <= gp::Resolution(), ""); |
218 | V.coord.Divide(D); |
219 | return V; |
220 | } |
221 | |
222 | inline Standard_Real gp_Dir::Dot (const gp_Dir& Other) const |
223 | { return coord.Dot (Other.coord); } |
224 | |
225 | inline Standard_Real gp_Dir::DotCross (const gp_Dir& V1, |
226 | const gp_Dir& V2) const |
227 | { return coord.Dot (V1.coord.Crossed (V2.coord)); } |
228 | |
229 | inline void gp_Dir::Reverse () |
230 | { coord.Reverse(); } |
231 | |
232 | inline gp_Dir gp_Dir::Reversed () const { |
233 | gp_Dir V = *this; |
234 | V.coord.Reverse (); |
235 | return V; |
236 | } |
237 | |
238 | inline void gp_Dir::Rotate (const gp_Ax1& A1, const Standard_Real Ang) |
239 | { |
240 | gp_Trsf T; |
241 | T.SetRotation (A1, Ang); |
242 | coord.Multiply (T.HVectorialPart ()); |
243 | } |
244 | |
245 | inline gp_Dir gp_Dir::Rotated (const gp_Ax1& A1, |
246 | const Standard_Real Ang) const |
247 | { |
248 | gp_Dir V = *this; |
249 | V.Rotate (A1, Ang); |
250 | return V; |
251 | } |
252 | |
253 | inline gp_Dir gp_Dir::Transformed (const gp_Trsf& T) const |
254 | { |
255 | gp_Dir V = *this; |
256 | V.Transform (T); |
257 | return V; |
258 | } |
259 | |