ba33179d5e94c68d1d9af40e2cd8665d17596d1a
[occt.git] / src / Geom2d / Geom2d_Parabola.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_Parabola.ixx>
18
19 #include <Precision.hxx>
20 #include <gp_XY.hxx>
21 #include <ElCLib.hxx>
22 #include <gp_Dir2d.hxx>
23 #include <Standard_ConstructionError.hxx>
24 #include <Standard_RangeError.hxx>
25
26 typedef Geom2d_Parabola         Parabola;
27 typedef Handle(Geom2d_Parabola) Handle(Parabola);
28 typedef gp_Ax2d   Ax2d;
29 typedef gp_Dir2d  Dir2d;
30 typedef gp_Pnt2d  Pnt2d;
31 typedef gp_Vec2d  Vec2d;
32 typedef gp_Trsf2d Trsf2d;
33 typedef gp_XY     XY;
34
35
36
37
38
39
40 //=======================================================================
41 //function : Copy
42 //purpose  : 
43 //=======================================================================
44
45 Handle(Geom2d_Geometry) Geom2d_Parabola::Copy() const 
46 {
47   Handle(Parabola) Prb;
48   Prb = new Parabola (pos, focalLength);
49   return Prb;
50 }
51
52
53
54 //=======================================================================
55 //function : Geom2d_Parabola
56 //purpose  : 
57 //=======================================================================
58
59 Geom2d_Parabola::Geom2d_Parabola (const gp_Parab2d& Prb) 
60 {
61   focalLength = Prb.Focal ();
62   pos         = Prb.Axis();
63 }
64
65
66 //=======================================================================
67 //function : Geom2d_Parabola
68 //purpose  : 
69 //=======================================================================
70
71 Geom2d_Parabola::Geom2d_Parabola (const Ax2d& MirrorAxis, 
72                                   const Standard_Real Focal, 
73                                   const Standard_Boolean Sense) 
74 : focalLength (Focal) 
75 {
76   if (Focal < 0.0) { Standard_ConstructionError::Raise(); }
77   pos = gp_Ax22d(MirrorAxis, Sense);
78 }
79
80
81 //=======================================================================
82 //function : Geom2d_Parabola
83 //purpose  : 
84 //=======================================================================
85
86 Geom2d_Parabola::Geom2d_Parabola (const gp_Ax22d& Axis, const Standard_Real Focal)
87 : focalLength (Focal) 
88 {
89   if (Focal < 0.0) { Standard_ConstructionError::Raise(); }
90   pos  = Axis;
91 }
92
93
94 //=======================================================================
95 //function : Geom2d_Parabola
96 //purpose  : 
97 //=======================================================================
98
99 Geom2d_Parabola::Geom2d_Parabola (const Ax2d& D, const Pnt2d& F) {
100
101   gp_Parab2d Prb (D, F);
102   pos = Prb.Axis();
103   focalLength = Prb.Focal();
104 }
105
106 //=======================================================================
107 //function : SetFocal
108 //purpose  : 
109 //=======================================================================
110
111 void Geom2d_Parabola::SetFocal (const Standard_Real Focal) 
112 {
113   if (Focal < 0.0) Standard_ConstructionError::Raise();
114   focalLength = Focal;
115 }
116
117
118 //=======================================================================
119 //function : SetParab2d
120 //purpose  : 
121 //=======================================================================
122
123 void Geom2d_Parabola::SetParab2d (const gp_Parab2d& Prb) 
124 {
125   focalLength = Prb.Focal ();
126   pos = Prb.Axis();
127 }
128
129 //=======================================================================
130 //function : Parab2d
131 //purpose  : 
132 //=======================================================================
133
134 gp_Parab2d Geom2d_Parabola::Parab2d () const 
135 {
136   return gp_Parab2d (pos, focalLength);
137 }
138
139 //=======================================================================
140 //function : ReversedParameter
141 //purpose  : 
142 //=======================================================================
143
144 Standard_Real Geom2d_Parabola::ReversedParameter( const Standard_Real U) const
145 {
146   return ( -U);
147 }
148
149 //=======================================================================
150 //function : FirstParameter
151 //purpose  : 
152 //=======================================================================
153
154 Standard_Real Geom2d_Parabola::FirstParameter () const   
155 {
156   return -Precision::Infinite(); 
157 }
158
159 //=======================================================================
160 //function : LastParameter
161 //purpose  : 
162 //=======================================================================
163
164 Standard_Real Geom2d_Parabola::LastParameter () const    
165 {
166   return Precision::Infinite(); 
167 }
168
169 //=======================================================================
170 //function : IsClosed
171 //purpose  : 
172 //=======================================================================
173
174 Standard_Boolean Geom2d_Parabola::IsClosed ()   const    
175 {
176   return Standard_False; 
177 }
178
179 //=======================================================================
180 //function : IsPeriodic
181 //purpose  : 
182 //=======================================================================
183
184 Standard_Boolean Geom2d_Parabola::IsPeriodic () const    
185 {
186   return Standard_False; 
187 }
188
189 //=======================================================================
190 //function : Directrix
191 //purpose  : 
192 //=======================================================================
193
194 Ax2d Geom2d_Parabola::Directrix () const 
195 {
196   gp_Parab2d Prb (pos, focalLength);
197   return Prb.Directrix();
198 }
199
200 //=======================================================================
201 //function : Eccentricity
202 //purpose  : 
203 //=======================================================================
204
205 Standard_Real Geom2d_Parabola::Eccentricity () const     
206 {
207   return 1.0; 
208 }
209
210 //=======================================================================
211 //function : Focus
212 //purpose  : 
213 //=======================================================================
214
215 Pnt2d Geom2d_Parabola::Focus () const 
216 {
217   XY Pxy = pos.XDirection().XY();
218   Pxy.Multiply (focalLength);
219   Pxy.Add (pos.Location().XY());
220   return Pnt2d (Pxy);
221 }
222
223 //=======================================================================
224 //function : Focal
225 //purpose  : 
226 //=======================================================================
227
228 Standard_Real Geom2d_Parabola::Focal () const            
229 {
230   return focalLength; 
231 }
232
233 //=======================================================================
234 //function : Parameter
235 //purpose  : 
236 //=======================================================================
237
238 Standard_Real Geom2d_Parabola::Parameter () const        
239 {
240   return 2.0 * focalLength; 
241 }
242
243 //=======================================================================
244 //function : D0
245 //purpose  : 
246 //=======================================================================
247
248 void Geom2d_Parabola::D0 (const Standard_Real   U,
249                                 Pnt2d& P) const 
250 {
251   P = ElCLib::ParabolaValue (U, pos, focalLength);
252 }
253
254 //=======================================================================
255 //function : D1
256 //purpose  : 
257 //=======================================================================
258
259 void Geom2d_Parabola::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const 
260 {
261   ElCLib::ParabolaD1 (U, pos, focalLength, P, V1);
262 }
263
264 //=======================================================================
265 //function : D2
266 //purpose  : 
267 //=======================================================================
268
269 void Geom2d_Parabola::D2 (const Standard_Real U, 
270                                 Pnt2d& P, 
271                                 Vec2d& V1, Vec2d& V2) const 
272 {
273   ElCLib::ParabolaD2 (U, pos, focalLength, P, V1, V2);
274 }
275
276 //=======================================================================
277 //function : D3
278 //purpose  : 
279 //=======================================================================
280
281 void Geom2d_Parabola::D3 (const Standard_Real U, 
282                                 Pnt2d& P, 
283                                 Vec2d& V1, Vec2d& V2, Vec2d& V3) const 
284 {
285    ElCLib::ParabolaD2 (U, pos, focalLength, P, V1, V2);
286    V3.SetCoord (0.0, 0.0);
287 }
288
289 //=======================================================================
290 //function : DN
291 //purpose  : 
292 //=======================================================================
293
294 Vec2d Geom2d_Parabola::DN (const Standard_Real U, const Standard_Integer N) const 
295 {
296    Standard_RangeError_Raise_if (N < 1, " ");
297    return ElCLib::ParabolaDN (U, pos, focalLength, N);
298 }
299
300
301 //=======================================================================
302 //function : Transform
303 //purpose  : 
304 //=======================================================================
305
306 void Geom2d_Parabola::Transform (const Trsf2d& T) 
307 {
308   focalLength *= Abs(T.ScaleFactor());
309    pos.Transform (T);
310 }
311
312 //=======================================================================
313 //function : TransformedParameter
314 //purpose  : 
315 //=======================================================================
316
317 Standard_Real Geom2d_Parabola::TransformedParameter(const Standard_Real U,
318                                                     const gp_Trsf2d& T) const
319 {
320   if (Precision::IsInfinite(U)) return U;
321   return U * Abs(T.ScaleFactor());
322 }
323
324 //=======================================================================
325 //function : ParametricTransformation
326 //purpose  : 
327 //=======================================================================
328
329 Standard_Real Geom2d_Parabola::ParametricTransformation(const gp_Trsf2d& T) const
330 {
331   return Abs(T.ScaleFactor());
332 }
333
334