0026042: OCCT won't work with the latest Xcode
[occt.git] / src / Geom / Geom_Hyperbola.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <ElCLib.hxx>
19 #include <Geom_Geometry.hxx>
20 #include <Geom_Hyperbola.hxx>
21 #include <gp_Ax1.hxx>
22 #include <gp_Ax2.hxx>
23 #include <gp_Hypr.hxx>
24 #include <gp_Pnt.hxx>
25 #include <gp_Trsf.hxx>
26 #include <gp_Vec.hxx>
27 #include <gp_XYZ.hxx>
28 #include <Precision.hxx>
29 #include <Standard_ConstructionError.hxx>
30 #include <Standard_DomainError.hxx>
31 #include <Standard_RangeError.hxx>
32 #include <Standard_Type.hxx>
33
34 typedef Geom_Hyperbola         Hyperbola;
35 typedef gp_Ax1  Ax1;
36 typedef gp_Ax2  Ax2;
37 typedef gp_Pnt  Pnt;
38 typedef gp_Vec  Vec;
39 typedef gp_Trsf Trsf;
40 typedef gp_XYZ  XYZ;
41
42 //=======================================================================
43 //function : Copy
44 //purpose  : 
45 //=======================================================================
46
47 Handle(Geom_Geometry) Geom_Hyperbola::Copy() const {
48
49   Handle(Geom_Hyperbola) H;
50   H = new Hyperbola (pos, majorRadius, minorRadius);
51   return H;
52 }
53
54
55
56
57 //=======================================================================
58 //function : Geom_Hyperbola
59 //purpose  : 
60 //=======================================================================
61
62 Geom_Hyperbola::Geom_Hyperbola (const gp_Hypr& H) 
63 : majorRadius (H.MajorRadius()), minorRadius (H.MinorRadius()) {
64
65   pos = H.Position();
66 }
67
68
69 //=======================================================================
70 //function : Geom_Hyperbola
71 //purpose  : 
72 //=======================================================================
73
74 Geom_Hyperbola::Geom_Hyperbola ( const Ax2& A, 
75                                  const Standard_Real MajorRadius, 
76                                  const Standard_Real MinorRadius) 
77  : majorRadius (MajorRadius), minorRadius (MinorRadius) {
78
79   if (MajorRadius < 0.0 || MinorRadius < 0.0) {
80     Standard_ConstructionError::Raise();
81   }
82   pos = A;
83 }
84
85 //=======================================================================
86 //function : IsClosed
87 //purpose  : 
88 //=======================================================================
89
90 Standard_Boolean Geom_Hyperbola::IsClosed () const      { return Standard_False; }
91
92 //=======================================================================
93 //function : IsPeriodic
94 //purpose  : 
95 //=======================================================================
96
97 Standard_Boolean Geom_Hyperbola::IsPeriodic () const    { return Standard_False; } 
98
99 //=======================================================================
100 //function : FirstParameter
101 //purpose  : 
102 //=======================================================================
103
104 Standard_Real Geom_Hyperbola::FirstParameter () const   
105 { return -Precision::Infinite(); }
106
107 //=======================================================================
108 //function : LastParameter
109 //purpose  : 
110 //=======================================================================
111
112 Standard_Real Geom_Hyperbola::LastParameter () const    
113 { return Precision::Infinite(); }
114
115 //=======================================================================
116 //function : MajorRadius
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Real Geom_Hyperbola::MajorRadius () const      { return majorRadius; }
121
122 //=======================================================================
123 //function : MinorRadius
124 //purpose  : 
125 //=======================================================================
126
127 Standard_Real Geom_Hyperbola::MinorRadius () const      { return minorRadius; }
128
129 //=======================================================================
130 //function : SetHypr
131 //purpose  : 
132 //=======================================================================
133
134 void Geom_Hyperbola::SetHypr (const gp_Hypr& H) {
135
136    majorRadius = H.MajorRadius();
137    minorRadius = H.MinorRadius();
138    pos = H.Position();
139 }
140
141
142 //=======================================================================
143 //function : SetMajorRadius
144 //purpose  : 
145 //=======================================================================
146
147 void Geom_Hyperbola::SetMajorRadius (const Standard_Real MajorRadius) {
148
149   if (MajorRadius < 0.0) Standard_ConstructionError::Raise();
150   else                   majorRadius = MajorRadius;
151 }
152
153
154 //=======================================================================
155 //function : SetMinorRadius
156 //purpose  : 
157 //=======================================================================
158
159 void Geom_Hyperbola::SetMinorRadius (const Standard_Real MinorRadius) {
160
161   if (MinorRadius < 0.0)  Standard_ConstructionError::Raise();
162   else                    minorRadius = MinorRadius;
163 }
164
165
166 //=======================================================================
167 //function : Hypr
168 //purpose  : 
169 //=======================================================================
170
171 gp_Hypr Geom_Hyperbola::Hypr () const 
172 {
173   return gp_Hypr (pos, majorRadius, minorRadius);
174 }
175
176 //=======================================================================
177 //function : ReversedParameter
178 //purpose  : 
179 //=======================================================================
180
181 Standard_Real Geom_Hyperbola::ReversedParameter( const Standard_Real U) const 
182 {
183   return ( -U);
184 }
185
186 //=======================================================================
187 //function : Asymptote1
188 //purpose  : 
189 //=======================================================================
190
191 Ax1 Geom_Hyperbola::Asymptote1 () const {
192
193   gp_Hypr Hv (pos, majorRadius, minorRadius);
194   return Hv.Asymptote1();
195 }
196
197
198 //=======================================================================
199 //function : Asymptote2
200 //purpose  : 
201 //=======================================================================
202
203 Ax1 Geom_Hyperbola::Asymptote2 () const {
204
205   gp_Hypr Hv (pos, majorRadius, minorRadius);
206   return Hv.Asymptote2();
207 }
208
209
210 //=======================================================================
211 //function : ConjugateBranch1
212 //purpose  : 
213 //=======================================================================
214
215 gp_Hypr Geom_Hyperbola::ConjugateBranch1 () const {
216
217   gp_Hypr Hv (pos, majorRadius, minorRadius);
218   return Hv.ConjugateBranch1();
219 }
220
221 //=======================================================================
222 //function : ConjugateBranch2
223 //purpose  : 
224 //=======================================================================
225
226 gp_Hypr Geom_Hyperbola::ConjugateBranch2 () const {
227
228   gp_Hypr Hv (pos, majorRadius, minorRadius);
229   return Hv.ConjugateBranch2();
230 }
231
232
233 //=======================================================================
234 //function : Directrix1
235 //purpose  : 
236 //=======================================================================
237
238 Ax1 Geom_Hyperbola::Directrix1 () const {
239
240   gp_Hypr Hv (pos, majorRadius, minorRadius);
241   return Hv.Directrix1();
242 }
243
244 //=======================================================================
245 //function : Directrix2
246 //purpose  : 
247 //=======================================================================
248
249 Ax1 Geom_Hyperbola::Directrix2 () const {
250
251   gp_Hypr Hv (pos, majorRadius, minorRadius);
252   return Hv.Directrix2();
253 }
254
255 //=======================================================================
256 //function : D0
257 //purpose  : 
258 //=======================================================================
259
260 void Geom_Hyperbola::D0 (const Standard_Real U, Pnt& P) const {
261
262   P = ElCLib::HyperbolaValue (U, pos, majorRadius, minorRadius);
263 }
264
265 //=======================================================================
266 //function : D1
267 //purpose  : 
268 //=======================================================================
269
270 void Geom_Hyperbola::D1 (const Standard_Real U, Pnt& P, Vec& V1) const {
271
272   ElCLib::HyperbolaD1 (U, pos, majorRadius, minorRadius, P, V1);
273 }
274
275 //=======================================================================
276 //function : D2
277 //purpose  : 
278 //=======================================================================
279
280 void Geom_Hyperbola::D2 (const Standard_Real U, Pnt& P, Vec& V1, Vec& V2) const {
281
282   ElCLib::HyperbolaD2 (U, pos, majorRadius, minorRadius, P, V1, V2);
283 }
284
285 //=======================================================================
286 //function : D3
287 //purpose  : 
288 //=======================================================================
289
290 void Geom_Hyperbola::D3 (
291 const Standard_Real U, Pnt& P, Vec& V1, Vec& V2, Vec& V3) const {
292
293   ElCLib::HyperbolaD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3);
294 }
295
296 //=======================================================================
297 //function : DN
298 //purpose  : 
299 //=======================================================================
300
301 Vec Geom_Hyperbola::DN (const Standard_Real U, const Standard_Integer N) const {
302
303   Standard_RangeError_Raise_if (N < 1, " ");  
304   return ElCLib::HyperbolaDN (U, pos, majorRadius, minorRadius, N);
305 }
306
307 //=======================================================================
308 //function : Eccentricity
309 //purpose  : 
310 //=======================================================================
311
312 Standard_Real Geom_Hyperbola::Eccentricity () const {
313
314   Standard_ConstructionError_Raise_if (majorRadius == 0.0, " ")  
315   return (Sqrt(majorRadius*majorRadius + minorRadius*minorRadius))/majorRadius;
316 }
317
318 //=======================================================================
319 //function : Focal
320 //purpose  : 
321 //=======================================================================
322
323 Standard_Real Geom_Hyperbola::Focal () const {
324
325   return 2.0 * Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
326 }
327
328 //=======================================================================
329 //function : Focus1
330 //purpose  : 
331 //=======================================================================
332
333 Pnt Geom_Hyperbola::Focus1 () const {
334
335   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
336   Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
337   pos.Location().Coord (Xp, Yp, Zp);
338   pos.XDirection().Coord (Xd, Yd, Zd);
339   return Pnt (Xp + C * Xd,  Yp + C * Yd, Zp + C * Zd);
340 }
341
342 //=======================================================================
343 //function : Focus2
344 //purpose  : 
345 //=======================================================================
346
347 Pnt Geom_Hyperbola::Focus2 () const {
348
349   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
350   Standard_Real Xp, Yp, Zp, Xd, Yd, Zd;
351   pos.Location().Coord (Xp, Yp, Zp);
352   pos.XDirection().Coord (Xd, Yd, Zd);
353   return Pnt (Xp - C * Xd,  Yp - C * Yd, Zp - C * Zd);
354 }
355
356 //=======================================================================
357 //function : OtherBranch
358 //purpose  : 
359 //=======================================================================
360
361 gp_Hypr Geom_Hyperbola::OtherBranch () const {
362
363    gp_Hypr Hv (pos, majorRadius, minorRadius);
364    return Hv.OtherBranch ();
365 }
366
367 //=======================================================================
368 //function : Parameter
369 //purpose  : 
370 //=======================================================================
371
372 Standard_Real Geom_Hyperbola::Parameter () const {
373
374    Standard_ConstructionError_Raise_if (majorRadius == 0.0, " ");  
375    return (minorRadius * minorRadius)/majorRadius;
376 }
377
378 //=======================================================================
379 //function : Transform
380 //purpose  : 
381 //=======================================================================
382
383 void Geom_Hyperbola::Transform (const Trsf& T) {
384
385   majorRadius = majorRadius * Abs(T.ScaleFactor());
386   minorRadius = minorRadius * Abs(T.ScaleFactor());
387   pos.Transform(T);
388 }