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. |
b311480e |
14 | |
7fd59977 |
15 | // LPA et JCV 07/92 mise a jour des methodes inline pour passage sur C1 |
16 | |
17 | #include <gp.hxx> |
18 | #include <Standard_DomainError.hxx> |
19 | #include <Standard_ConstructionError.hxx> |
20 | |
21 | inline gp_Hypr2d::gp_Hypr2d () : |
22 | majorRadius(RealLast()), |
23 | minorRadius(RealLast()) |
24 | { } |
25 | |
26 | inline gp_Hypr2d::gp_Hypr2d (const gp_Ax22d& A, |
27 | const Standard_Real MajorRadius, |
28 | const Standard_Real MinorRadius) : |
29 | pos(A), |
30 | majorRadius(MajorRadius), |
31 | minorRadius(MinorRadius) |
32 | { |
2d2b3d53 |
33 | Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, |
34 | "gp_Hypr2d() - invalid construction parameters"); |
7fd59977 |
35 | } |
36 | |
37 | inline gp_Hypr2d::gp_Hypr2d (const gp_Ax2d& MajorAxis, |
38 | const Standard_Real MajorRadius, |
39 | const Standard_Real MinorRadius, |
40 | const Standard_Boolean Sense) : |
41 | majorRadius(MajorRadius), |
42 | minorRadius(MinorRadius) |
43 | { |
44 | pos = gp_Ax22d(MajorAxis,Sense); |
2d2b3d53 |
45 | Standard_ConstructionError_Raise_if (MinorRadius < 0.0 || MajorRadius < 0.0, |
46 | "gp_Hypr2d() - invalid construction parameters"); |
7fd59977 |
47 | } |
48 | |
49 | inline void gp_Hypr2d::SetLocation (const gp_Pnt2d& P) |
50 | { pos.SetLocation (P); } |
51 | |
52 | inline void gp_Hypr2d::SetMajorRadius (const Standard_Real MajorRadius) |
53 | { |
2d2b3d53 |
54 | Standard_ConstructionError_Raise_if (MajorRadius < 0.0, |
55 | "gp_Hypr2d::SetMajorRadius() - major radius should be greater or equal zero"); |
7fd59977 |
56 | majorRadius = MajorRadius; |
57 | } |
58 | |
59 | inline void gp_Hypr2d::SetMinorRadius (const Standard_Real MinorRadius) |
60 | { |
2d2b3d53 |
61 | Standard_ConstructionError_Raise_if (MinorRadius < 0.0, |
62 | "gp_Hypr2d::SetMinorRadius() - minor radius should be greater or equal zero"); |
7fd59977 |
63 | minorRadius = MinorRadius; |
64 | } |
65 | |
66 | inline void gp_Hypr2d::SetAxis (const gp_Ax22d& A) |
67 | { pos.SetAxis(A); } |
68 | |
69 | inline void gp_Hypr2d::SetXAxis (const gp_Ax2d& A) |
70 | { pos.SetXAxis(A); } |
71 | |
72 | inline void gp_Hypr2d::SetYAxis (const gp_Ax2d& A) |
73 | { pos.SetYAxis(A); } |
74 | |
75 | inline gp_Ax2d gp_Hypr2d::Asymptote1() const |
76 | { |
2d2b3d53 |
77 | Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), |
78 | "gp_Hypr2d::Asymptote1() - major radius is zero"); |
7fd59977 |
79 | gp_Dir2d Vdir = pos.XDirection(); |
80 | gp_XY Coord1 (pos.YDirection().XY()); |
81 | gp_XY Coord2 = Coord1.Multiplied (minorRadius / majorRadius); |
82 | Coord1.Add (Coord2); |
83 | Vdir.SetXY (Coord1); |
84 | return gp_Ax2d (pos.Location(), Vdir); |
85 | } |
86 | |
87 | inline gp_Ax2d gp_Hypr2d::Asymptote2() const { |
2d2b3d53 |
88 | Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), |
89 | "gp_Hypr2d::Asymptote2() - major radius is zero"); |
7fd59977 |
90 | gp_Vec2d Vdir = pos.XDirection(); |
91 | gp_XY Coord1 (pos.YDirection().XY()); |
92 | gp_XY Coord2 = Coord1.Multiplied (-minorRadius / majorRadius); |
93 | Coord1.Add (Coord2); |
94 | Vdir.SetXY (Coord1); |
95 | return gp_Ax2d (pos.Location(), Vdir); |
96 | } |
97 | |
98 | inline gp_Hypr2d gp_Hypr2d::ConjugateBranch1() const |
99 | { |
100 | gp_Dir2d V (pos.YDirection()); |
101 | Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; |
102 | return gp_Hypr2d (gp_Ax2d (pos.Location(),V), minorRadius, majorRadius,sign); |
103 | } |
104 | |
105 | inline gp_Hypr2d gp_Hypr2d::ConjugateBranch2() const |
106 | { |
107 | gp_Dir2d V (pos.YDirection().Reversed()); |
108 | Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; |
109 | return gp_Hypr2d (gp_Ax2d(pos.Location(),V),minorRadius, majorRadius,sign); |
110 | } |
111 | |
112 | inline gp_Ax2d gp_Hypr2d::Directrix1() const |
113 | { |
114 | Standard_Real E = Eccentricity(); |
115 | gp_XY Orig = pos.XDirection().XY(); |
116 | Orig.Multiply (majorRadius/E); |
117 | Orig.Add (pos.Location().XY()); |
118 | return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); |
119 | } |
120 | |
121 | inline gp_Ax2d gp_Hypr2d::Directrix2() const |
122 | { |
123 | Standard_Real E = Eccentricity(); |
124 | gp_XY Orig = pos.XDirection().XY(); |
125 | Orig.Multiply (Parameter()/E); |
126 | Orig.Add (Focus1().XY()); |
127 | return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection())); |
128 | } |
129 | |
130 | inline Standard_Real gp_Hypr2d::Eccentricity() const |
131 | { |
2d2b3d53 |
132 | Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), |
133 | "gp_Hypr2d::Eccentricity() - major radius is zero"); |
7fd59977 |
134 | return sqrt(majorRadius * majorRadius + |
135 | minorRadius * minorRadius) / majorRadius; |
136 | } |
137 | |
138 | inline Standard_Real gp_Hypr2d::Focal() const |
139 | { |
140 | return 2.0 * sqrt (majorRadius * majorRadius + |
141 | minorRadius * minorRadius); |
142 | } |
143 | |
144 | inline gp_Pnt2d gp_Hypr2d::Focus1() const |
145 | { |
146 | Standard_Real C = sqrt (majorRadius * majorRadius + |
147 | minorRadius * minorRadius); |
148 | return gp_Pnt2d (pos.Location().X() + C * pos.XDirection().X(), |
149 | pos.Location().Y() + C * pos.XDirection().Y()); |
150 | } |
151 | |
152 | inline gp_Pnt2d gp_Hypr2d::Focus2() const |
153 | { |
154 | Standard_Real C = sqrt (majorRadius * majorRadius + |
155 | minorRadius * minorRadius); |
156 | return gp_Pnt2d (pos.Location().X() - C * pos.XDirection().X(), |
157 | pos.Location().Y() - C * pos.XDirection().Y()); |
158 | } |
159 | |
160 | inline const gp_Pnt2d& gp_Hypr2d::Location () const |
161 | { return pos.Location(); } |
162 | |
163 | inline Standard_Real gp_Hypr2d::MajorRadius() const |
164 | { return majorRadius; } |
165 | |
166 | inline Standard_Real gp_Hypr2d::MinorRadius() const |
167 | { return minorRadius; } |
168 | |
169 | inline gp_Hypr2d gp_Hypr2d::OtherBranch() const |
170 | { |
171 | Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; |
172 | return gp_Hypr2d (gp_Ax2d (pos.Location(),pos.XDirection().Reversed()), |
173 | majorRadius,minorRadius,sign); |
174 | } |
175 | |
176 | inline Standard_Real gp_Hypr2d::Parameter() const |
177 | { |
2d2b3d53 |
178 | Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), |
179 | "gp_Hypr2d::Parameter() - major radius is zero"); |
7fd59977 |
180 | return (minorRadius * minorRadius) / majorRadius; |
181 | } |
182 | |
183 | inline const gp_Ax22d& gp_Hypr2d::Axis () const |
184 | { return pos; } |
185 | |
186 | inline gp_Ax2d gp_Hypr2d::XAxis () const |
187 | { return pos.XAxis(); } |
188 | |
189 | inline gp_Ax2d gp_Hypr2d::YAxis () const |
190 | { return pos.YAxis(); } |
191 | |
192 | inline void gp_Hypr2d::Reverse() |
193 | { |
194 | gp_Dir2d Temp = pos.YDirection (); |
195 | Temp.Reverse (); |
196 | pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
197 | } |
198 | |
199 | inline gp_Hypr2d gp_Hypr2d::Reversed() const |
200 | { |
201 | gp_Hypr2d H = *this; |
202 | gp_Dir2d Temp = pos.YDirection (); |
203 | Temp.Reverse (); |
204 | H.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp)); |
205 | return H; |
206 | } |
207 | |
208 | inline Standard_Boolean gp_Hypr2d::IsDirect() const |
209 | { return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; } |
210 | |
211 | inline void gp_Hypr2d::Rotate (const gp_Pnt2d& P, |
212 | const Standard_Real Ang) |
213 | {pos.Rotate (P,Ang);} |
214 | |
215 | inline gp_Hypr2d gp_Hypr2d::Rotated (const gp_Pnt2d& P, |
216 | const Standard_Real Ang) const |
217 | { |
218 | gp_Hypr2d H = *this; |
219 | H.pos.Rotate (P, Ang); |
220 | return H; |
221 | } |
222 | |
223 | inline void gp_Hypr2d::Scale (const gp_Pnt2d& P, |
224 | const Standard_Real S) |
225 | { |
226 | majorRadius *= S; |
227 | if (majorRadius < 0) majorRadius = - majorRadius; |
228 | minorRadius *= S; |
229 | if (minorRadius < 0) minorRadius = - minorRadius; |
230 | pos.Scale(P, S); |
231 | } |
232 | |
233 | inline gp_Hypr2d gp_Hypr2d::Scaled (const gp_Pnt2d& P, |
234 | const Standard_Real S) const |
235 | { |
236 | gp_Hypr2d H = *this; |
237 | H.majorRadius *= S; |
238 | if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; |
239 | H.minorRadius *= S; |
240 | if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; |
241 | H.pos.Scale(P, S); |
242 | return H; |
243 | } |
244 | |
245 | inline void gp_Hypr2d::Transform (const gp_Trsf2d& T) |
246 | { |
247 | majorRadius *= T.ScaleFactor(); |
248 | if (majorRadius < 0) majorRadius = - majorRadius; |
249 | minorRadius *= T.ScaleFactor(); |
250 | if (minorRadius < 0) minorRadius = - minorRadius; |
251 | pos.Transform(T); |
252 | } |
253 | |
254 | inline gp_Hypr2d gp_Hypr2d::Transformed (const gp_Trsf2d& T) const |
255 | { |
256 | gp_Hypr2d H = *this; |
257 | H.majorRadius *= T.ScaleFactor(); |
258 | if (H.majorRadius < 0) H.majorRadius = - H.majorRadius; |
259 | H.minorRadius *= T.ScaleFactor(); |
260 | if (H.minorRadius < 0) H.minorRadius = - H.minorRadius; |
261 | H.pos.Transform(T); |
262 | return H; |
263 | } |
264 | |
265 | inline void gp_Hypr2d::Translate (const gp_Vec2d& V) |
266 | { pos.Translate(V); } |
267 | |
268 | inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Vec2d& V) const |
269 | { |
270 | gp_Hypr2d H = *this; |
271 | H.pos.Translate(V); |
272 | return H; |
273 | } |
274 | |
275 | inline void gp_Hypr2d::Translate (const gp_Pnt2d& P1, |
276 | const gp_Pnt2d& P2) |
277 | { |
278 | pos.Translate(P1, P2); |
279 | } |
280 | |
281 | inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Pnt2d& P1, |
282 | const gp_Pnt2d& P2) const |
283 | { |
284 | gp_Hypr2d H = *this; |
285 | H.pos.Translate(P1, P2); |
286 | return H; |
287 | } |
288 | |