0024927: Getting rid of "Persistent" functionality -- Storable
[occt.git] / src / gp / gp_Elips.lxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559
16
17
18#include <gp.hxx>
19#include <Standard_ConstructionError.hxx>
20
21inline gp_Elips::gp_Elips () :
22majorRadius (RealLast()),
23minorRadius (RealSmall())
24{ }
25
26inline gp_Elips::gp_Elips (const gp_Ax2& A2,
27 const Standard_Real MajorRadius,
28 const Standard_Real MinorRadius) :
29 pos(A2),
30 majorRadius (MajorRadius),
31 minorRadius (MinorRadius)
32{
33 Standard_ConstructionError_Raise_if
34 (MinorRadius < 0.0 || MajorRadius < MinorRadius,"");
35}
36
37inline Standard_Real gp_Elips::Area() const
c6541a0c 38{ return M_PI * majorRadius * minorRadius; }
7fd59977 39
40inline Standard_Real gp_Elips::MajorRadius() const
41{ return majorRadius; }
42
43inline Standard_Real gp_Elips::MinorRadius() const
44{ return minorRadius; }
45
46inline Standard_Real gp_Elips::Parameter() const
47{
48 if (majorRadius == 0.0) return 0.0;
49 else return (minorRadius * minorRadius) / majorRadius;
50}
51
52inline const gp_Ax2& gp_Elips::Position() const
53{ return pos; }
54
55inline const gp_Ax1& gp_Elips::Axis () const
56{ return pos.Axis(); }
57
58inline gp_Ax1 gp_Elips::Directrix1() const
59{
60 Standard_Real E = Eccentricity();
61 Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
62 gp_XYZ Orig = pos.XDirection().XYZ();
63 Orig.Multiply (majorRadius/E);
64 Orig.Add (pos.Location().XYZ());
65 return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
66}
67
68inline gp_Ax1 gp_Elips::Directrix2() const
69{
70 Standard_Real E = Eccentricity();
71 Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
72 gp_XYZ Orig = pos.XDirection().XYZ();
73 Orig.Multiply (-majorRadius/E);
74 Orig.Add (pos.Location().XYZ());
75 return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
76}
77
78inline Standard_Real gp_Elips::Eccentricity() const
79{
80 if (majorRadius == 0.0) { return 0.0; }
81 else {
82 return sqrt(majorRadius * majorRadius -
83 minorRadius * minorRadius) / majorRadius;
84 }
85}
86
87inline Standard_Real gp_Elips::Focal() const
88{
89 return 2.0 * sqrt(majorRadius * majorRadius -
90 minorRadius * minorRadius);
91}
92
93inline gp_Pnt gp_Elips::Focus1() const
94{
95 Standard_Real C = sqrt(majorRadius * majorRadius -
96 minorRadius * minorRadius);
97 const gp_Pnt& PP = pos.Location ();
98 const gp_Dir& DD = pos.XDirection();
99 return gp_Pnt (PP.X() + C * DD.X(),
100 PP.Y() + C * DD.Y(),
101 PP.Z() + C * DD.Z());
102}
103
104inline gp_Pnt gp_Elips::Focus2() const
105{
106 Standard_Real C = sqrt(majorRadius * majorRadius -
107 minorRadius * minorRadius);
108 const gp_Pnt& PP = pos.Location ();
109 const gp_Dir& DD = pos.XDirection();
110 return gp_Pnt (PP.X() - C * DD.X(),
111 PP.Y() - C * DD.Y(),
112 PP.Z() - C * DD.Z());
113}
114
115inline const gp_Pnt& gp_Elips::Location () const
116{ return pos.Location(); }
117
118inline gp_Ax1 gp_Elips::XAxis () const
119{ return gp_Ax1 (pos.Location(), pos.XDirection()); }
120
121inline gp_Ax1 gp_Elips::YAxis () const
122{ return gp_Ax1 (pos.Location(), pos.YDirection()); }
123
124inline void gp_Elips::SetAxis (const gp_Ax1& A1)
125{ pos.SetAxis(A1); }
126
127inline void gp_Elips::SetPosition (const gp_Ax2& A2)
128{ pos = A2; }
129
130inline void gp_Elips::SetLocation (const gp_Pnt& P)
131{ pos.SetLocation (P); }
132
133inline void gp_Elips::SetMajorRadius (const Standard_Real R)
134{
135 Standard_ConstructionError_Raise_if(R < minorRadius,"");
136 majorRadius = R;
137}
138
139inline void gp_Elips::SetMinorRadius (const Standard_Real R)
140{
141 Standard_ConstructionError_Raise_if(R < 0.0 || majorRadius < R,"");
142 minorRadius = R;
143}
144
145inline void gp_Elips::Rotate (const gp_Ax1& A1,
146 const Standard_Real Ang) { pos.Rotate(A1, Ang); }
147
148inline gp_Elips gp_Elips::Rotated (const gp_Ax1& A1,
149 const Standard_Real Ang) const
150{
151 gp_Elips E = *this;
152 E.pos.Rotate(A1, Ang);
153 return E;
154}
155
156inline void gp_Elips::Scale (const gp_Pnt& P,
157 const Standard_Real S)
158// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin
159// { pos.Scale(P, S); }
160{
161 majorRadius *= S;
162 if (majorRadius < 0) majorRadius = - majorRadius;
163 minorRadius *= S;
164 if (minorRadius < 0) minorRadius = - minorRadius;
165 pos.Scale(P, S);
166}
167// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End
168
169inline gp_Elips gp_Elips::Scaled (const gp_Pnt& P,
170 const Standard_Real S) const
171{
172 gp_Elips E = *this;
173 E.majorRadius *= S;
174 if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
175 E.minorRadius *= S;
176 if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
177 E.pos.Scale(P, S);
178 return E;
179}
180
181inline void gp_Elips::Transform (const gp_Trsf& T)
182{
183 majorRadius *= T.ScaleFactor();
184 if (majorRadius < 0) majorRadius = - majorRadius;
185 minorRadius *= T.ScaleFactor();
186 if (minorRadius < 0) minorRadius = - minorRadius;
187 pos.Transform(T);
188}
189
190inline gp_Elips gp_Elips::Transformed (const gp_Trsf& T) const
191{
192 gp_Elips E = *this;
193 E.majorRadius *= T.ScaleFactor();
194 if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
195 E.minorRadius *= T.ScaleFactor();
196 if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
197 E.pos.Transform(T);
198 return E;
199}
200
201inline void gp_Elips::Translate (const gp_Vec& V)
202{ pos.Translate(V); }
203
204inline gp_Elips gp_Elips::Translated (const gp_Vec& V) const
205{
206 gp_Elips E = *this;
207 E.pos.Translate(V);
208 return E;
209}
210
211inline void gp_Elips::Translate (const gp_Pnt& P1,
212 const gp_Pnt& P2)
213{ pos.Translate(P1, P2); }
214
215inline gp_Elips gp_Elips::Translated (const gp_Pnt& P1,
216 const gp_Pnt& P2) const
217{
218 gp_Elips E = *this;
219 E.pos.Translate(P1, P2);
220 return E;
221}
222