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