0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / Geom2d / Geom2d_Hyperbola.cxx
1 // Created on: 1993-03-24
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 <Geom2d_Geometry.hxx>
20 #include <Geom2d_Hyperbola.hxx>
21 #include <gp.hxx>
22 #include <gp_Ax2d.hxx>
23 #include <gp_Ax22d.hxx>
24 #include <gp_Dir2d.hxx>
25 #include <gp_Hypr2d.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <gp_Trsf2d.hxx>
28 #include <gp_Vec2d.hxx>
29 #include <gp_XY.hxx>
30 #include <Precision.hxx>
31 #include <Standard_ConstructionError.hxx>
32 #include <Standard_DomainError.hxx>
33 #include <Standard_RangeError.hxx>
34 #include <Standard_Type.hxx>
35
36 IMPLEMENT_STANDARD_RTTIEXT(Geom2d_Hyperbola,Geom2d_Conic)
37
38 typedef Geom2d_Hyperbola         Hyperbola;
39 typedef gp_Ax2d   Ax2d;
40 typedef gp_Dir2d  Dir2d;
41 typedef gp_Pnt2d  Pnt2d;
42 typedef gp_Vec2d  Vec2d;
43 typedef gp_Trsf2d Trsf2d;
44 typedef gp_XY     XY;
45
46 //=======================================================================
47 //function : Copy
48 //purpose  : 
49 //=======================================================================
50
51 Handle(Geom2d_Geometry) Geom2d_Hyperbola::Copy() const 
52 {
53   Handle(Geom2d_Hyperbola) H;
54   H = new Hyperbola (pos, majorRadius, minorRadius);
55   return H;
56 }
57
58
59
60 //=======================================================================
61 //function : Geom2d_Hyperbola
62 //purpose  : 
63 //=======================================================================
64
65 Geom2d_Hyperbola::Geom2d_Hyperbola (const gp_Hypr2d& H) 
66 {
67   majorRadius = H.MajorRadius();
68   minorRadius = H.MinorRadius();
69   pos = H.Axis();
70 }
71
72
73 //=======================================================================
74 //function : Geom2d_Hyperbola
75 //purpose  : 
76 //=======================================================================
77
78 Geom2d_Hyperbola::Geom2d_Hyperbola (const Ax2d& A, 
79                                     const Standard_Real MajorRadius, 
80                                     const Standard_Real MinorRadius, 
81                                     const Standard_Boolean Sense) 
82 : majorRadius (MajorRadius), minorRadius (MinorRadius) 
83 {
84   if( MajorRadius < 0.0|| MinorRadius < 0.0) 
85     throw Standard_ConstructionError();
86   pos = gp_Ax22d(A, Sense);
87 }
88
89 //=======================================================================
90 //function : Geom2d_Hyperbola
91 //purpose  : 
92 //=======================================================================
93
94 Geom2d_Hyperbola::Geom2d_Hyperbola (const gp_Ax22d& Axis, 
95                                     const Standard_Real MajorRadius, 
96                                     const Standard_Real MinorRadius) 
97 : majorRadius (MajorRadius), minorRadius (MinorRadius) 
98 {
99   if( MajorRadius < 0.0|| MinorRadius < 0.0)
100     throw Standard_ConstructionError();
101   pos = Axis;
102 }
103
104
105 //=======================================================================
106 //function : SetHypr2d
107 //purpose  : 
108 //=======================================================================
109
110 void Geom2d_Hyperbola::SetHypr2d (const gp_Hypr2d& H) 
111 {
112   majorRadius = H.MajorRadius();
113   minorRadius = H.MinorRadius();
114   pos = H.Axis();
115 }
116
117
118 //=======================================================================
119 //function : SetMajorRadius
120 //purpose  : 
121 //=======================================================================
122
123 void Geom2d_Hyperbola::SetMajorRadius (const Standard_Real MajorRadius) 
124 {
125   if (MajorRadius < 0.0) 
126     throw Standard_ConstructionError();
127   else                   
128     majorRadius = MajorRadius;
129 }
130
131
132 //=======================================================================
133 //function : SetMinorRadius
134 //purpose  : 
135 //=======================================================================
136
137 void Geom2d_Hyperbola::SetMinorRadius (const Standard_Real MinorRadius) 
138 {
139   if (MinorRadius < 0.0 ) 
140     throw Standard_ConstructionError();
141   else
142     minorRadius = MinorRadius;
143 }
144
145
146 //=======================================================================
147 //function : Hypr2d
148 //purpose  : 
149 //=======================================================================
150
151 gp_Hypr2d Geom2d_Hyperbola::Hypr2d () const 
152 {
153   return gp_Hypr2d (pos, majorRadius, minorRadius);
154 }
155
156
157 //=======================================================================
158 //function : ReversedParameter
159 //purpose  : 
160 //=======================================================================
161
162 Standard_Real Geom2d_Hyperbola::ReversedParameter( const Standard_Real U) const
163 {
164   return ( -U);
165 }
166
167 //=======================================================================
168 //function : FirstParameter
169 //purpose  : 
170 //=======================================================================
171
172 Standard_Real Geom2d_Hyperbola::FirstParameter () const   
173 {
174   return -Precision::Infinite(); 
175 }
176
177 //=======================================================================
178 //function : LastParameter
179 //purpose  : 
180 //=======================================================================
181
182 Standard_Real Geom2d_Hyperbola::LastParameter () const    
183 {
184   return Precision::Infinite(); 
185 }
186
187 //=======================================================================
188 //function : IsClosed
189 //purpose  : 
190 //=======================================================================
191
192 Standard_Boolean Geom2d_Hyperbola::IsClosed () const      
193 {
194   return Standard_False; 
195 }
196
197 //=======================================================================
198 //function : IsPeriodic
199 //purpose  : 
200 //=======================================================================
201
202 Standard_Boolean Geom2d_Hyperbola::IsPeriodic () const    
203 {
204   return Standard_False; 
205 }
206  
207 //=======================================================================
208 //function : Asymptote1
209 //purpose  : 
210 //=======================================================================
211
212 Ax2d Geom2d_Hyperbola::Asymptote1 () const 
213 {
214   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
215   return Hv.Asymptote1();
216 }
217
218 //=======================================================================
219 //function : Asymptote2
220 //purpose  : 
221 //=======================================================================
222
223 Ax2d Geom2d_Hyperbola::Asymptote2 () const 
224 {
225   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
226   return Hv.Asymptote2();
227 }
228
229 //=======================================================================
230 //function : ConjugateBranch1
231 //purpose  : 
232 //=======================================================================
233
234 gp_Hypr2d Geom2d_Hyperbola::ConjugateBranch1 () const 
235 {
236   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
237   return Hv.ConjugateBranch1 ();
238 }
239
240 //=======================================================================
241 //function : ConjugateBranch2
242 //purpose  : 
243 //=======================================================================
244
245 gp_Hypr2d Geom2d_Hyperbola::ConjugateBranch2 () const 
246 {
247   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
248   return Hv.ConjugateBranch2 ();
249 }
250
251 //=======================================================================
252 //function : Directrix1
253 //purpose  : 
254 //=======================================================================
255
256 Ax2d Geom2d_Hyperbola::Directrix1 () const 
257 {
258   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
259   return Hv.Directrix1 ();
260 }
261
262 //=======================================================================
263 //function : Directrix2
264 //purpose  : 
265 //=======================================================================
266
267 Ax2d Geom2d_Hyperbola::Directrix2 () const 
268 {
269   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
270   return Hv.Directrix2 ();
271 }
272
273 //=======================================================================
274 //function : Eccentricity
275 //purpose  : 
276 //=======================================================================
277
278 Standard_Real Geom2d_Hyperbola::Eccentricity () const 
279 {
280   Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), " ");
281   return 
282    (Sqrt(majorRadius*majorRadius+minorRadius*minorRadius))/majorRadius;
283 }
284
285 //=======================================================================
286 //function : Focal
287 //purpose  : 
288 //=======================================================================
289
290 Standard_Real Geom2d_Hyperbola::Focal () const 
291 {
292   return 2.0 * Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
293 }
294
295 //=======================================================================
296 //function : Focus1
297 //purpose  : 
298 //=======================================================================
299
300 Pnt2d Geom2d_Hyperbola::Focus1 () const 
301 {
302   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
303   XY Pxy = pos.XDirection().XY();
304   Pxy.Multiply (C);
305   Pxy.Add (pos.Location().XY());  
306   return Pnt2d (Pxy);
307 }
308
309 //=======================================================================
310 //function : Focus2
311 //purpose  : 
312 //=======================================================================
313
314 Pnt2d Geom2d_Hyperbola::Focus2 () const 
315 {
316   Standard_Real C = Sqrt(majorRadius * majorRadius + minorRadius * minorRadius);
317   XY Pxy = pos.XDirection().XY();
318   Pxy.Multiply (-C);
319   Pxy.Add (pos.Location().XY());  
320   return Pnt2d (Pxy);
321 }
322
323 //=======================================================================
324 //function : MajorRadius
325 //purpose  : 
326 //=======================================================================
327
328 Standard_Real Geom2d_Hyperbola::MajorRadius () const      
329 {
330   return majorRadius; 
331 }
332
333 //=======================================================================
334 //function : MinorRadius
335 //purpose  : 
336 //=======================================================================
337
338 Standard_Real Geom2d_Hyperbola::MinorRadius () const      
339 {
340   return minorRadius; 
341 }
342
343 //=======================================================================
344 //function : OtherBranch
345 //purpose  : 
346 //=======================================================================
347
348 gp_Hypr2d Geom2d_Hyperbola::OtherBranch () const 
349 {
350   gp_Hypr2d Hv (pos, majorRadius, minorRadius);
351   return Hv.OtherBranch ();
352 }
353
354
355 //=======================================================================
356 //function : Parameter
357 //purpose  : 
358 //=======================================================================
359
360 Standard_Real Geom2d_Hyperbola::Parameter () const 
361 {
362   Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), " ");
363   return (minorRadius * minorRadius) / majorRadius;
364 }
365
366 //=======================================================================
367 //function : D0
368 //purpose  : 
369 //=======================================================================
370
371 void Geom2d_Hyperbola::D0 (const Standard_Real   U,  
372                                  Pnt2d& P ) const 
373 {
374   P = ElCLib::HyperbolaValue (U, pos, majorRadius, minorRadius);
375 }
376
377 //=======================================================================
378 //function : D1
379 //purpose  : 
380 //=======================================================================
381
382 void Geom2d_Hyperbola::D1 (const Standard_Real   U, 
383                                  Pnt2d& P, 
384                                  Vec2d& V1) const 
385 {
386   ElCLib::HyperbolaD1 (U, pos, majorRadius, minorRadius, P, V1);
387 }
388
389
390 //=======================================================================
391 //function : D2
392 //purpose  : 
393 //=======================================================================
394
395 void Geom2d_Hyperbola::D2 (const Standard_Real   U, 
396                                  Pnt2d& P, 
397                                  Vec2d& V1, Vec2d& V2) const
398 {
399   ElCLib::HyperbolaD2 (U, pos, majorRadius, minorRadius, P, V1, V2);
400 }
401
402
403 //=======================================================================
404 //function : D3
405 //purpose  : 
406 //=======================================================================
407
408 void Geom2d_Hyperbola::D3 (const Standard_Real U, 
409                                  Pnt2d& P, 
410                                  Vec2d& V1, Vec2d& V2, Vec2d& V3) const 
411 {
412   ElCLib::HyperbolaD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3);
413 }
414
415
416 //=======================================================================
417 //function : DN
418 //purpose  : 
419 //=======================================================================
420
421 Vec2d Geom2d_Hyperbola::DN (const Standard_Real U, const Standard_Integer N) const 
422 {
423   Standard_RangeError_Raise_if (N < 1, " ");
424   return ElCLib::HyperbolaDN (U, pos, majorRadius, minorRadius, N);
425 }
426
427
428 //=======================================================================
429 //function : Transform
430 //purpose  : 
431 //=======================================================================
432
433 void Geom2d_Hyperbola::Transform (const Trsf2d& T) 
434 {
435   majorRadius = majorRadius * Abs (T.ScaleFactor());
436   minorRadius = minorRadius * Abs (T.ScaleFactor());
437   pos.Transform(T);
438 }