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