0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / Extrema / Extrema_ExtPElC2d.cxx
CommitLineData
7fd59977 1// File: Extrema_ExtPElC2d.cxx
2// Created: Mon Dec 13 12:37:09 1993
3// Author: Christophe MARION
4// <cma@zerox>
5
6#include <Precision.hxx>
7#include <Extrema_ExtPElC2d.ixx>
8#include <StdFail_NotDone.hxx>
9#include <math_DirectPolynomialRoots.hxx>
10#include <math_TrigonometricFunctionRoots.hxx>
11#include <ElCLib.hxx>
12#include <Standard_OutOfRange.hxx>
13#include <Standard_NotImplemented.hxx>
14//=============================================================================
15
16Extrema_ExtPElC2d::Extrema_ExtPElC2d () { myDone = Standard_False; }
17//=============================================================================
18
19Extrema_ExtPElC2d::Extrema_ExtPElC2d
20 (const gp_Pnt2d& P,
21 const gp_Lin2d& L,
22 const Standard_Real Tol,
23 const Standard_Real Uinf,
24 const Standard_Real Usup)
25{
26 Perform(P, L, Tol, Uinf, Usup);
27}
28
29void Extrema_ExtPElC2d::Perform(const gp_Pnt2d& P,
30 const gp_Lin2d& L,
31 const Standard_Real Tol,
32 const Standard_Real Uinf,
33 const Standard_Real Usup)
34{
35 myDone = Standard_True;
36 gp_Pnt2d OR, MyP;
37 myNbExt = 0;
38
39 gp_Vec2d V1 = gp_Vec2d(L.Direction());
40 OR = L.Location();
41 gp_Vec2d V(OR, P);
42 Standard_Real Mydist = V1.Dot(V);
43 if ((Mydist >= Uinf -Tol) &&
44 (Mydist <= Usup+ Tol)){
45 myNbExt = 1;
46 MyP = OR.Translated(Mydist*V1);
47 Extrema_POnCurv2d MyPOnCurve(Mydist, MyP);
48 mySqDist[0] = P.SquareDistance(MyP);
49 myPoint[0] = MyPOnCurve;
50 myIsMin[0] = Standard_True;
51 }
52}
53
54//=============================================================================
55
56Extrema_ExtPElC2d::Extrema_ExtPElC2d
57 (const gp_Pnt2d& P,
58 const gp_Circ2d& C,
59 const Standard_Real Tol,
60 const Standard_Real Uinf,
61 const Standard_Real Usup)
62{
63 Perform(P, C, Tol, Uinf, Usup);
64}
65
66void Extrema_ExtPElC2d::Perform(const gp_Pnt2d& P,
67 const gp_Circ2d& C,
68 const Standard_Real Tol,
69 const Standard_Real Uinf,
70 const Standard_Real Usup)
71{
72 Standard_Real radius, U1, U2;
73// gp_Pnt2d OC, P1, P2, OL;
74 gp_Pnt2d OC, P1, P2;
75 OC = C.Location();
76 myNbExt = 0;
77
78 if (OC.IsEqual(P, Precision::Confusion())) {
79 myDone = Standard_False;
80 }
81 else {
82 myDone = Standard_True;
83 gp_Dir2d V(gp_Vec2d(P, OC));
84 radius = C.Radius();
85 P1 = OC.Translated(radius*V);
86 U1 = ElCLib::Parameter(C, P1);
c6541a0c 87 U2 = U1 + M_PI;
7fd59977 88 P2 = OC.Translated(-radius*V);
89 Standard_Real myuinf = Uinf;
c6541a0c
D
90 ElCLib::AdjustPeriodic(Uinf, Uinf+2*M_PI, Precision::PConfusion(), myuinf, U1);
91 ElCLib::AdjustPeriodic(Uinf, Uinf+2*M_PI, Precision::PConfusion(), myuinf, U2);
92 if (((U1-2*M_PI-Uinf) < Tol) && ((U1-2*M_PI-Uinf) > -Tol)) U1 = Uinf;
93 if (((U2-2*M_PI-Uinf) < Tol) && ((U2-2*M_PI-Uinf) > -Tol)) U2 = Uinf;
7fd59977 94
95 if (((Uinf-U1) < Tol) && ((U1-Usup) < Tol)) {
96 Extrema_POnCurv2d MyPOnCurve(U1, P1);
97 mySqDist[0] = P.SquareDistance(P1);
98 myPoint[0] = MyPOnCurve;
99 myIsMin[0] = Standard_True;
100 myNbExt++;
101 }
102
103 if (((Uinf-U2) < Tol) && ((U2-Usup) < Tol)) {
104 Extrema_POnCurv2d MyPOnCurve(U2, P2);
105 mySqDist[myNbExt] = P.SquareDistance(P2);
106 myPoint[myNbExt] = MyPOnCurve;
107 myIsMin[myNbExt] = Standard_True;
108 myNbExt++;
109 }
110 }
111}
112
113//=============================================================================
114
115
116Extrema_ExtPElC2d::Extrema_ExtPElC2d (const gp_Pnt2d& P,
117 const gp_Elips2d& E,
118 const Standard_Real Tol,
119 const Standard_Real Uinf,
120 const Standard_Real Usup)
121{
122 Perform(P, E, Tol, Uinf, Usup);
123}
124
125
126
127void Extrema_ExtPElC2d::Perform (const gp_Pnt2d& P,
128 const gp_Elips2d& E,
129 const Standard_Real Tol,
130 const Standard_Real Uinf,
131 const Standard_Real Usup)
132{
133// gp_Pnt2d OR, P1, P2;
134 gp_Pnt2d OR;
135 OR = E.Location();
136
137 Standard_Integer NoSol, NbSol;
138 Standard_Real A = E.MajorRadius();
139 Standard_Real B = E.MinorRadius();
140 gp_Vec2d V(OR,P);
141
142 if (OR.IsEqual(P, Precision::Confusion()) &&
143 (Abs(A-B) <= Tol)) {
144 myDone = Standard_False;
145 }
146 else {
7fd59977 147 Standard_Real X = V.Dot(gp_Vec2d(E.XAxis().Direction()));
148 Standard_Real Y = V.Dot(gp_Vec2d(E.YAxis().Direction()));
149
150 math_TrigonometricFunctionRoots Sol(0.,(B*B-A*A)/2.,-B*Y,A*X,0.,Uinf,Usup);
151
152 if (!Sol.IsDone()) { return; }
153 gp_Pnt2d Cu;
154 Standard_Real Us;
155 NbSol = Sol.NbSolutions();
156 myNbExt = 0;
157 for (NoSol = 1; NoSol <= NbSol; NoSol++) {
158 Us = Sol.Value(NoSol);
159 Cu = ElCLib::Value(Us, E);
160 mySqDist[myNbExt] = Cu.SquareDistance(P);
161 myIsMin[myNbExt] = (NoSol == 0);
162 myPoint[myNbExt] = Extrema_POnCurv2d(Us,Cu);
163 myNbExt++;
164 }
165 myDone = Standard_True;
166 }
167}
168//=============================================================================
169
170Extrema_ExtPElC2d::Extrema_ExtPElC2d (const gp_Pnt2d& P,
171 const gp_Hypr2d& C,
172 const Standard_Real Tol,
173 const Standard_Real Uinf,
174 const Standard_Real Usup)
175{
176 Perform(P, C, Tol, Uinf, Usup);
177}
178
179
180void Extrema_ExtPElC2d::Perform(const gp_Pnt2d& P,
181 const gp_Hypr2d& H,
182 const Standard_Real Tol,
183 const Standard_Real Uinf,
184 const Standard_Real Usup)
185{
186 gp_Pnt2d O = H.Location();
187 myDone = Standard_False;
188 myNbExt = 0;
189
190 Standard_Real R = H.MajorRadius();
191 Standard_Real r = H.MinorRadius();
192 gp_Vec2d OPp(O,P);
7fd59977 193 Standard_Real Tol2 = Tol * Tol;
194 Standard_Real X = OPp.Dot(gp_Vec2d(H.XAxis().Direction()));
195 Standard_Real Y = OPp.Dot(gp_Vec2d(H.YAxis().Direction()));
196 Standard_Real C1 = (R*R+r*r)/4.;
197 math_DirectPolynomialRoots Sol(C1,-(X*R+Y*r)/2.,0.,(X*R-Y*r)/2.,-C1);
198 if (!Sol.IsDone()) { return; }
199 gp_Pnt2d Cu;
200 Standard_Real Us, Vs;
201 Standard_Integer NbSol = Sol.NbSolutions();
202 Standard_Boolean DejaEnr;
203 Standard_Integer NoExt;
204 gp_Pnt2d TbExt[4];
205 for (Standard_Integer NoSol = 1; NoSol <= NbSol; NoSol++) {
206 Vs = Sol.Value(NoSol);
207 if (Vs > 0.) {
208 Us = Log(Vs);
209 if ((Us >= Uinf) && (Us <= Usup)) {
210 Cu = ElCLib::Value(Us,H);
211 DejaEnr = Standard_False;
212 for (NoExt = 0; NoExt < myNbExt; NoExt++) {
213 if (TbExt[NoExt].SquareDistance(Cu) < Tol2) {
214 DejaEnr = Standard_True;
215 break;
216 }
217 }
218 if (!DejaEnr) {
219 TbExt[myNbExt] = Cu;
220 mySqDist[myNbExt] = Cu.SquareDistance(P);
221 myIsMin[myNbExt] = (NoSol == 0);
222 myPoint[myNbExt] = Extrema_POnCurv2d(Us,Cu);
223 myNbExt++;
224 }
225 } // if ((Us >= Uinf) && (Us <= Usup))
226 } // if (Vs > 0.)
227 } // for (Standard_Integer NoSol = 1; ...
228 myDone = Standard_True;
229}
230
231//=============================================================================
232
233Extrema_ExtPElC2d::Extrema_ExtPElC2d (const gp_Pnt2d& P,
234 const gp_Parab2d& C,
235 const Standard_Real Tol,
236 const Standard_Real Uinf,
237 const Standard_Real Usup)
238{
239 Perform(P, C, Tol, Uinf, Usup);
240}
241
242
243void Extrema_ExtPElC2d::Perform(const gp_Pnt2d& P,
244 const gp_Parab2d& C,
245 const Standard_Real Tol,
246 const Standard_Real Uinf,
247 const Standard_Real Usup)
248{
249 myDone = Standard_False;
250 myNbExt = 0;
251 gp_Pnt2d O = C.Location();
252
253 Standard_Real Tol2 = Tol * Tol;
254 Standard_Real F = C.Focal();
255 gp_Vec2d OPp (O,P);
7fd59977 256 Standard_Real X = OPp.Dot(gp_Vec2d(C.MirrorAxis().Direction()));
257 Standard_Real Y = OPp.Dot(gp_Vec2d(C.Axis().YAxis().Direction()));
258
259 math_DirectPolynomialRoots Sol(1./(4.*F),0.,2.*F-X,-2.*F*Y);
260 if (!Sol.IsDone()) { return; }
261 gp_Pnt2d Cu;
262 Standard_Real Us;
263 Standard_Integer NbSol = Sol.NbSolutions();
264 Standard_Boolean DejaEnr;
265 Standard_Integer NoExt;
266 gp_Pnt2d TbExt[3];
267 for (Standard_Integer NoSol = 1; NoSol <= NbSol; NoSol++) {
268 Us = Sol.Value(NoSol);
269 if ((Us >= Uinf) && (Us <= Usup)) {
270 Cu = ElCLib::Value(Us,C);
271 DejaEnr = Standard_False;
272 for (NoExt = 0; NoExt < myNbExt; NoExt++) {
273 if (TbExt[NoExt].SquareDistance(Cu) < Tol2) {
274 DejaEnr = Standard_True;
275 break;
276 }
277 }
278 if (!DejaEnr) {
279 TbExt[myNbExt] = Cu;
280 mySqDist[myNbExt] = Cu.SquareDistance(P);
281 myIsMin[myNbExt] = (NoSol == 0);
282 myPoint[myNbExt] = Extrema_POnCurv2d(Us,Cu);
283 myNbExt++;
284 }
285 } // if ((Us >= Uinf) && (Us <= Usup))
286 } // for (Standard_Integer NoSol = 1; ...
287 myDone = Standard_True;
288}
289//=============================================================================
290
291Standard_Boolean Extrema_ExtPElC2d::IsDone () const { return myDone; }
292//=============================================================================
293
294Standard_Integer Extrema_ExtPElC2d::NbExt () const
295{
296 if (!IsDone()) { StdFail_NotDone::Raise(); }
297 return myNbExt;
298}
299//=============================================================================
300
301Standard_Real Extrema_ExtPElC2d::SquareDistance (const Standard_Integer N) const
302{
303 if ((N < 1) || (N > NbExt())) { Standard_OutOfRange::Raise(); }
304 return mySqDist[N-1];
305}
306//=============================================================================
307
308Standard_Boolean Extrema_ExtPElC2d::IsMin (const Standard_Integer N) const
309{
310 if ((N < 1) || (N > NbExt())) { Standard_OutOfRange::Raise(); }
311 return myIsMin[N-1];
312}
313//=============================================================================
314
315Extrema_POnCurv2d Extrema_ExtPElC2d::Point (const Standard_Integer N) const
316{
317 if ((N < 1) || (N > NbExt())) { Standard_OutOfRange::Raise(); }
318 return myPoint[N-1];
319}
320//=============================================================================