0024624: Lost word in license statement in source files
[occt.git] / src / Geom2d / Geom2d_Ellipse.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_Ellipse.ixx>
18 #include <gp.hxx>
19 #include <gp_Dir2d.hxx>
20 #include <gp_XYZ.hxx>
21 #include <ElCLib.hxx>
22 #include <Standard_RangeError.hxx>
23 #include <Standard_ConstructionError.hxx>
24
25
26 typedef Geom2d_Ellipse         Ellipse;
27 typedef Handle(Geom2d_Ellipse) Handle(Ellipse);
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 //function : Copy
41 //purpose  : 
42 //=======================================================================
43
44 Handle(Geom2d_Geometry) Geom2d_Ellipse::Copy() const 
45 {
46   Handle(Ellipse) E;
47   E = new Ellipse (pos, majorRadius, minorRadius);
48   return E;
49 }
50
51
52 //=======================================================================
53 //function : Geom2d_Ellipse
54 //purpose  : 
55 //=======================================================================
56
57 Geom2d_Ellipse::Geom2d_Ellipse (const gp_Elips2d& E) {
58  
59   majorRadius = E.MajorRadius();
60   minorRadius = E.MinorRadius();
61   pos = E.Axis();
62 }
63
64
65
66 //=======================================================================
67 //function : Geom2d_Ellipse
68 //purpose  : 
69 //=======================================================================
70
71 Geom2d_Ellipse::Geom2d_Ellipse (const Ax2d& MajorAxis,
72                                 const Standard_Real MajorRadius,
73                                 const Standard_Real MinorRadius,
74                                 const Standard_Boolean Sense) 
75 :majorRadius (MajorRadius), minorRadius (MinorRadius){
76
77   if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) {
78     Standard_ConstructionError::Raise();
79   }
80   pos = gp_Ax22d(MajorAxis, Sense);
81 }
82
83
84 //=======================================================================
85 //function : Geom2d_Ellipse
86 //purpose  : 
87 //=======================================================================
88
89 Geom2d_Ellipse::Geom2d_Ellipse (const gp_Ax22d& Axis, 
90                                 const Standard_Real MajorRadius, 
91                                 const Standard_Real MinorRadius) 
92 : majorRadius (MajorRadius), minorRadius (MinorRadius)
93 {
94   if (MajorRadius < MinorRadius || MinorRadius < 0.0 ) {
95     Standard_ConstructionError::Raise();
96   }
97   pos = Axis;
98 }
99
100
101 //=======================================================================
102 //function : SetElips2d
103 //purpose  : 
104 //=======================================================================
105
106 void Geom2d_Ellipse::SetElips2d (const gp_Elips2d& E) 
107 {
108   majorRadius = E.MajorRadius();
109   minorRadius = E.MinorRadius();
110   pos = E.Axis();
111 }
112
113
114 //=======================================================================
115 //function : SetMajorRadius
116 //purpose  : 
117 //=======================================================================
118
119 void Geom2d_Ellipse::SetMajorRadius (const Standard_Real MajorRadius) 
120 {
121   if (MajorRadius < minorRadius) 
122     Standard_ConstructionError::Raise();
123   else                           
124     majorRadius = MajorRadius; 
125 }
126
127
128 //=======================================================================
129 //function : SetMinorRadius
130 //purpose  : 
131 //=======================================================================
132
133 void Geom2d_Ellipse::SetMinorRadius (const Standard_Real MinorRadius) 
134 {
135    if (MinorRadius < 0 || majorRadius < MinorRadius) 
136      { Standard_ConstructionError::Raise(); }
137    else 
138      { minorRadius = MinorRadius; }
139 }
140
141
142 //=======================================================================
143 //function : Elips2d
144 //purpose  : 
145 //=======================================================================
146
147 gp_Elips2d Geom2d_Ellipse::Elips2d () const 
148 {
149   return gp_Elips2d (pos, majorRadius, minorRadius);
150 }
151
152 //=======================================================================
153 //function : ReversedParameter
154 //purpose  : 
155 //=======================================================================
156
157 Standard_Real Geom2d_Ellipse::ReversedParameter( const Standard_Real U) const 
158 {
159   return (2. * M_PI - U);
160 }
161
162 //=======================================================================
163 //function : Directrix1
164 //purpose  : 
165 //=======================================================================
166
167 Ax2d Geom2d_Ellipse::Directrix1 () const 
168 {
169   gp_Elips2d Ev (pos, majorRadius, minorRadius);
170   return Ev.Directrix1();
171 }
172
173
174 //=======================================================================
175 //function : Directrix2
176 //purpose  : 
177 //=======================================================================
178
179 Ax2d Geom2d_Ellipse::Directrix2 () const 
180 {
181   gp_Elips2d Ev (pos, majorRadius, minorRadius);
182   return Ev.Directrix2();
183 }
184
185
186 //=======================================================================
187 //function : Eccentricity
188 //purpose  : 
189 //=======================================================================
190
191 Standard_Real Geom2d_Ellipse::Eccentricity () const 
192 {
193   if (majorRadius == 0.0) 
194     { return 0.0; }
195   else 
196     { return 
197         (Sqrt(majorRadius*majorRadius-minorRadius*minorRadius))/majorRadius;
198     }
199 }
200
201
202 //=======================================================================
203 //function : Focal
204 //purpose  : 
205 //=======================================================================
206
207 Standard_Real Geom2d_Ellipse::Focal () const 
208 {
209   return 2.0 * Sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
210 }
211
212
213 //=======================================================================
214 //function : Focus1
215 //purpose  : 
216 //=======================================================================
217
218 Pnt2d Geom2d_Ellipse::Focus1 () const 
219 {
220   Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
221   return Pnt2d (pos.Location().X() + C * pos.XDirection().X(),
222                 pos.Location().Y() + C * pos.XDirection().Y());
223 }
224
225
226 //=======================================================================
227 //function : Focus2
228 //purpose  : 
229 //=======================================================================
230
231 Pnt2d Geom2d_Ellipse::Focus2 () const 
232 {
233   Standard_Real C = Sqrt(majorRadius * majorRadius - minorRadius * minorRadius);
234   return Pnt2d (pos.Location().X() - C * pos.XDirection().X(),
235                 pos.Location().Y() - C * pos.XDirection().Y());
236 }
237
238 //=======================================================================
239 //function : MajorRadius
240 //purpose  : 
241 //=======================================================================
242
243 Standard_Real Geom2d_Ellipse::MajorRadius () const       
244 {
245   return majorRadius; 
246 }
247
248 //=======================================================================
249 //function : MinorRadius
250 //purpose  : 
251 //=======================================================================
252
253 Standard_Real Geom2d_Ellipse::MinorRadius () const       
254 {
255   return minorRadius; 
256 }
257
258 //=======================================================================
259 //function : Parameter
260 //purpose  : 
261 //=======================================================================
262
263 Standard_Real Geom2d_Ellipse::Parameter () const 
264 {
265   if (majorRadius == 0.0) 
266     return 0.0;
267   else                    
268     return (minorRadius * minorRadius)/majorRadius;
269 }
270
271
272 //=======================================================================
273 //function : FirstParameter
274 //purpose  : 
275 //=======================================================================
276
277 Standard_Real Geom2d_Ellipse::FirstParameter () const    
278 {
279   return 0.0; 
280 }
281
282 //=======================================================================
283 //function : LastParameter
284 //purpose  : 
285 //=======================================================================
286
287 Standard_Real Geom2d_Ellipse::LastParameter () const     
288 {
289   return 2.0 * M_PI; 
290 }
291
292 //=======================================================================
293 //function : IsClosed
294 //purpose  : 
295 //=======================================================================
296
297 Standard_Boolean Geom2d_Ellipse::IsClosed () const       
298 {
299   return Standard_True; 
300 }
301
302 //=======================================================================
303 //function : IsPeriodic
304 //purpose  : 
305 //=======================================================================
306
307 Standard_Boolean Geom2d_Ellipse::IsPeriodic () const     
308 {
309   return Standard_True; 
310 }
311
312 //=======================================================================
313 //function : D0
314 //purpose  : 
315 //=======================================================================
316
317 void Geom2d_Ellipse::D0 (const Standard_Real U, Pnt2d& P) const 
318 {
319   P = ElCLib::EllipseValue (U, pos, majorRadius, minorRadius);
320 }
321
322 //=======================================================================
323 //function : D1
324 //purpose  : 
325 //=======================================================================
326
327 void Geom2d_Ellipse::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const 
328 {
329   ElCLib::EllipseD1 (U, pos, majorRadius, minorRadius, P, V1);
330 }
331
332
333 //=======================================================================
334 //function : D2
335 //purpose  : 
336 //=======================================================================
337
338 void Geom2d_Ellipse::D2 (const Standard_Real U, 
339                                Pnt2d& P, 
340                                Vec2d& V1, Vec2d& V2) const 
341 {
342   ElCLib::EllipseD2 (U, pos, majorRadius, minorRadius, P, V1, V2);
343 }
344
345
346 //=======================================================================
347 //function : D3
348 //purpose  : 
349 //=======================================================================
350
351 void Geom2d_Ellipse::D3 (const Standard_Real U, 
352                                Pnt2d& P, 
353                                Vec2d& V1, Vec2d& V2, Vec2d& V3) const 
354 {
355   ElCLib::EllipseD3 (U, pos, majorRadius, minorRadius, P, V1, V2, V3);
356 }
357
358
359 //=======================================================================
360 //function : DN
361 //purpose  : 
362 //=======================================================================
363
364 Vec2d Geom2d_Ellipse::DN (const Standard_Real U, const Standard_Integer N) const 
365 {
366   Standard_RangeError_Raise_if (N < 1, " ");
367   return ElCLib::EllipseDN (U, pos, majorRadius, minorRadius, N);
368 }
369
370 //=======================================================================
371 //function : Transform
372 //purpose  : 
373 //=======================================================================
374
375 void Geom2d_Ellipse::Transform (const Trsf2d& T) 
376 {
377   majorRadius = majorRadius * Abs(T.ScaleFactor());
378   minorRadius = minorRadius * Abs(T.ScaleFactor());
379   pos.Transform(T);
380 }