b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | |
20 | #include <gp_Trsf2d.hxx> |
21 | #include <gp.hxx> |
22 | #include <Standard_ConstructionError.hxx> |
23 | |
24 | inline gp_Elips2d::gp_Elips2d() : |
25 | majorRadius(RealLast()), |
26 | minorRadius(RealSmall()) |
27 | { } |
28 | |
29 | inline gp_Elips2d::gp_Elips2d (const gp_Ax2d& MajorAxis, |
30 | const Standard_Real MajorRadius, |
31 | const Standard_Real MinorRadius, |
32 | const Standard_Boolean Sense) : |
33 | majorRadius(MajorRadius), |
34 | minorRadius(MinorRadius) |
35 | { |
36 | pos = gp_Ax22d(MajorAxis,Sense); |
37 | Standard_ConstructionError_Raise_if |
38 | (MinorRadius < 0.0 || MajorRadius < MinorRadius,""); |
39 | } |
40 | |
41 | inline gp_Elips2d::gp_Elips2d (const gp_Ax22d& A, |
42 | const Standard_Real MajorRadius, |
43 | const Standard_Real MinorRadius) : |
44 | pos(A), |
45 | majorRadius(MajorRadius), |
46 | minorRadius(MinorRadius) |
47 | { |
48 | Standard_ConstructionError_Raise_if |
49 | (MinorRadius < 0.0 || MajorRadius < MinorRadius,""); |
50 | } |
51 | |
52 | inline void gp_Elips2d::SetLocation (const gp_Pnt2d& P) |
53 | { pos.SetLocation(P);} |
54 | |
55 | inline void gp_Elips2d::SetMajorRadius (const Standard_Real MajorRadius) |
56 | { |
57 | Standard_ConstructionError_Raise_if(MajorRadius < minorRadius,""); |
58 | majorRadius = MajorRadius; |
59 | } |
60 | |
61 | inline void gp_Elips2d::SetMinorRadius (const Standard_Real MinorRadius) |
62 | { |
63 | Standard_ConstructionError_Raise_if |
64 | (MinorRadius < 0.0 || majorRadius < MinorRadius,""); |
65 | minorRadius = MinorRadius; |
66 | } |
67 | |
68 | inline void gp_Elips2d::SetXAxis (const gp_Ax2d& A) |
69 | { pos.SetXAxis(A); } |
70 | |
71 | inline void gp_Elips2d::SetAxis (const gp_Ax22d& A) |
72 | { pos.SetAxis(A); } |
73 | |
74 | inline void gp_Elips2d::SetYAxis (const gp_Ax2d& A) |
75 | { pos.SetYAxis(A); } |
76 | |
77 | inline Standard_Real gp_Elips2d::Area() const |
c6541a0c |
78 | { return M_PI * majorRadius * minorRadius; } |
7fd59977 |
79 | |
80 | inline gp_Ax2d gp_Elips2d::Directrix1() const |
81 | { |
82 | Standard_Real E = Eccentricity(); |
83 | Standard_ConstructionError_Raise_if (E <= gp::Resolution(), ""); |
84 | gp_XY Orig = pos.XDirection().XY(); |
85 | Orig.Multiply (majorRadius/E); |
86 | Orig.Add (pos.Location().XY()); |
87 | return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); |
88 | } |
89 | |
90 | inline gp_Ax2d gp_Elips2d::Directrix2() const |
91 | { |
92 | Standard_Real E = Eccentricity(); |
93 | Standard_ConstructionError_Raise_if (E <= gp::Resolution(), ""); |
94 | gp_XY Orig = pos.XDirection().XY(); |
95 | Orig.Multiply (-majorRadius/E); |
96 | Orig.Add (pos.Location().XY()); |
97 | return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); |
98 | } |
99 | |
100 | inline Standard_Real gp_Elips2d::Eccentricity() const |
101 | { |
102 | if (majorRadius == 0.0) { return 0.0; } |
103 | else { |
104 | return sqrt(majorRadius * majorRadius - |
105 | minorRadius * minorRadius) / majorRadius; |
106 | } |
107 | } |
108 | |
109 | inline Standard_Real gp_Elips2d::Focal() const |
110 | { |
111 | return 2.0 * sqrt(majorRadius * majorRadius - |
112 | minorRadius * minorRadius); |
113 | } |
114 | |
115 | inline gp_Pnt2d gp_Elips2d::Focus1() const |
116 | { |
117 | Standard_Real C = sqrt(majorRadius * majorRadius - |
118 | minorRadius * minorRadius); |
119 | const gp_Pnt2d& PP = pos.Location (); |
120 | const gp_Dir2d& DD = pos.XDirection(); |
121 | return gp_Pnt2d (PP.X() + C * DD.X(), |
122 | PP.Y() + C * DD.Y()); |
123 | } |
124 | |
125 | inline gp_Pnt2d gp_Elips2d::Focus2() const |
126 | { |
127 | Standard_Real C = sqrt (majorRadius * majorRadius - |
128 | minorRadius * minorRadius); |
129 | const gp_Pnt2d& PP = pos.Location (); |
130 | const gp_Dir2d& DD = pos.XDirection(); |
131 | return gp_Pnt2d (PP.X() - C * DD.X(), |
132 | PP.Y() - C * DD.Y()); |
133 | } |
134 | |
135 | inline const gp_Pnt2d& gp_Elips2d::Location () const |
136 | { return pos.Location(); } |
137 | |
138 | inline Standard_Real gp_Elips2d::MajorRadius() const |
139 | { return majorRadius; } |
140 | |
141 | inline Standard_Real gp_Elips2d::MinorRadius() const |
142 | { return minorRadius; } |
143 | |
144 | inline Standard_Real gp_Elips2d::Parameter () const |
145 | { |
146 | if (majorRadius == 0.0) return 0.0; |
147 | else return (minorRadius * minorRadius) / majorRadius; |
148 | } |
149 | |
150 | inline const gp_Ax22d& gp_Elips2d::Axis () const |
151 | { return pos; } |
152 | |
153 | inline gp_Ax2d gp_Elips2d::YAxis () const |
154 | { return pos.YAxis(); } |
155 | |
156 | inline gp_Ax2d gp_Elips2d::XAxis () const |
157 | { return pos.XAxis(); } |
158 | |
159 | inline void gp_Elips2d::Reverse() |
160 | { |
161 | gp_Dir2d Temp = pos.YDirection (); |
162 | Temp.Reverse (); |
163 | pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
164 | } |
165 | |
166 | inline gp_Elips2d gp_Elips2d::Reversed() const |
167 | { |
168 | gp_Elips2d E = *this; |
169 | gp_Dir2d Temp = pos.YDirection (); |
170 | Temp.Reverse (); |
171 | E.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
172 | return E; |
173 | } |
174 | |
175 | inline Standard_Boolean gp_Elips2d::IsDirect() const |
176 | { return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } |
177 | |
178 | inline void gp_Elips2d::Rotate (const gp_Pnt2d& P, |
179 | const Standard_Real Ang) |
180 | { pos.Rotate (P, Ang); } |
181 | |
182 | inline gp_Elips2d gp_Elips2d::Rotated (const gp_Pnt2d& P, |
183 | const Standard_Real Ang) const |
184 | { |
185 | gp_Elips2d E = *this; |
186 | E.pos.Rotate (P, Ang); |
187 | return E; |
188 | } |
189 | |
190 | inline void gp_Elips2d::Scale (const gp_Pnt2d& P, |
191 | const Standard_Real S) |
192 | { |
193 | majorRadius *= S; |
194 | if (majorRadius < 0) majorRadius = - majorRadius; |
195 | minorRadius *= S; |
196 | if (minorRadius < 0) minorRadius = - minorRadius; |
197 | pos.Scale(P, S); |
198 | } |
199 | |
200 | inline gp_Elips2d gp_Elips2d::Scaled (const gp_Pnt2d& P, |
201 | const Standard_Real S) const |
202 | { |
203 | gp_Elips2d E = *this; |
204 | E.majorRadius *= S; |
205 | if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; |
206 | E.minorRadius *= S; |
207 | if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; |
208 | E.pos.Scale(P, S); |
209 | return E; |
210 | } |
211 | |
212 | inline void gp_Elips2d::Transform(const gp_Trsf2d& T) |
213 | { |
214 | Standard_Real TSca = T.ScaleFactor(); |
215 | if(TSca<0.0) TSca=-TSca; |
216 | majorRadius *= TSca; |
217 | minorRadius *= TSca; |
218 | pos.Transform(T); |
219 | } |
220 | |
221 | inline gp_Elips2d gp_Elips2d::Transformed (const gp_Trsf2d& T) const |
222 | { |
223 | gp_Elips2d E = *this; |
224 | E.majorRadius *= T.ScaleFactor(); |
225 | if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; |
226 | E.minorRadius *= T.ScaleFactor(); |
227 | if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; |
228 | E.pos.Transform(T); |
229 | return E; |
230 | } |
231 | |
232 | inline void gp_Elips2d::Translate (const gp_Vec2d& V) |
233 | { pos.Translate(V); } |
234 | |
235 | inline gp_Elips2d gp_Elips2d::Translated (const gp_Vec2d& V) const |
236 | { |
237 | gp_Elips2d E = *this; |
238 | E.pos.Translate(V); |
239 | return E; |
240 | } |
241 | |
242 | inline void gp_Elips2d::Translate (const gp_Pnt2d& P1, |
243 | const gp_Pnt2d& P2) |
244 | { pos.Translate(P1, P2); } |
245 | |
246 | inline gp_Elips2d gp_Elips2d::Translated (const gp_Pnt2d& P1, |
247 | const gp_Pnt2d& P2) const |
248 | { |
249 | gp_Elips2d E = *this; |
250 | E.pos.Translate(P1, P2); |
251 | return E; |
252 | } |
253 | |