0024134: Wrong result of projection point on the face
[occt.git] / src / Extrema / Extrema_GenExtPC.gxx
1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <StdFail_NotDone.hxx>
24 #include <math_DirectPolynomialRoots.hxx>
25 #include <math_FunctionRoots.hxx>
26 #include <Standard_OutOfRange.hxx>
27 #include <Standard_NotImplemented.hxx>
28
29
30 //=======================================================================
31 //function : Extrema_GenExtPC
32 //purpose  : 
33 //=======================================================================
34
35 Extrema_GenExtPC::Extrema_GenExtPC () { 
36   myDone = Standard_False;
37   myInit = Standard_False;
38 }
39
40
41
42 //=======================================================================
43 //function : Extrema_GenExtPC
44 //purpose  : 
45 //=======================================================================
46
47 Extrema_GenExtPC::Extrema_GenExtPC (const Pnt&             P, 
48                                     const Curve&           C,
49                                     const Standard_Integer NbSample, 
50                                     const Standard_Real    TolU,
51                                     const Standard_Real    TolF) : myF (P,C)
52 {
53   Initialize(C, NbSample, TolU, TolF);
54   Perform(P);
55 }
56
57
58 //=======================================================================
59 //function : Extrema_GenExtPC
60 //purpose  : 
61 //=======================================================================
62
63 Extrema_GenExtPC::Extrema_GenExtPC (const Pnt&             P, 
64                                     const Curve&           C,
65                                     const Standard_Integer NbSample, 
66                                     const Standard_Real    Umin, 
67                                     const Standard_Real    Usup,
68                                     const Standard_Real    TolU,
69                                     const Standard_Real    TolF) : myF (P,C)
70 {
71   Initialize(C, NbSample, Umin, Usup, TolU, TolF);
72   Perform(P);
73 }
74
75
76 //=======================================================================
77 //function : Initialize
78 //purpose  : 
79 //=======================================================================
80
81 void Extrema_GenExtPC::Initialize(const Curve&           C,
82                                   const Standard_Integer NbU,
83                                   const Standard_Real    TolU,
84                                   const Standard_Real    TolF)
85 {
86   myInit = Standard_True;
87   mynbsample = NbU;
88   mytolu = TolU;
89   mytolF = TolF;
90   myF.Initialize(C);
91   myumin = Tool::FirstParameter(C);
92   myusup = Tool::LastParameter(C);
93 }
94
95 //=======================================================================
96 //function : Initialize
97 //purpose  : 
98 //=======================================================================
99
100 void Extrema_GenExtPC::Initialize(const Curve&           C,
101                                   const Standard_Integer NbU,
102                                   const Standard_Real    Umin,
103                                   const Standard_Real    Usup,
104                                   const Standard_Real    TolU,
105                                   const Standard_Real    TolF)
106 {
107   myInit = Standard_True;
108   mynbsample = NbU;
109   mytolu = TolU;
110   mytolF = TolF;
111   myF.Initialize(C);
112   myumin = Umin;
113   myusup = Usup;
114 }
115
116
117 //=======================================================================
118 //function : Initialize
119 //purpose  : 
120 //=======================================================================
121
122 void Extrema_GenExtPC::Initialize(const Standard_Integer NbU,
123                                   const Standard_Real    Umin,
124                                   const Standard_Real    Usup,
125                                   const Standard_Real    TolU,
126                                   const Standard_Real    TolF)
127 {
128   mynbsample = NbU;
129   mytolu = TolU;
130   mytolF = TolF;
131   myumin = Umin;
132   myusup = Usup;
133 }
134
135 //=======================================================================
136 //function : Initialize
137 //purpose  : 
138 //=======================================================================
139
140 void Extrema_GenExtPC::Initialize(const Curve& C)
141 {
142   myF.Initialize(C);
143 }
144
145
146
147 //=======================================================================
148 //function : Perform
149 //purpose  : 
150 //=======================================================================
151
152 void Extrema_GenExtPC::Perform(const Pnt& P)
153 /*-----------------------------------------------------------------------------
154 Fonction:
155   Recherche des valeurs de parametre u telle que dist(P,C(u)) passe
156   par un extremum.
157
158 Methode:
159   Si U est solution, alors (C(U)-P).C'(U) = 0.
160   Le probleme consiste a rechercher les racines de cette fonction
161   dans l'intervalle de definition de la courbe.
162   On utilise la classe math_FunctionRoots avec les arguments de
163   construction suivant:
164   - F: Extrema_FuncExtPC cree a partir de P et C,
165   - Uinf: borne inferieure de l'intervalle de definition,
166   - Usup: borne superieure de l'intervalle de definition,
167   - NbSample,
168   - TolU,
169   - TolF,
170   - TolF.
171 -----------------------------------------------------------------------------*/
172 {
173   myF.SetPoint(P);
174   myF.SubIntervalInitialize(myumin,myusup);
175   myDone = Standard_False;
176
177   math_FunctionRoots S (myF, myumin, myusup, mynbsample, mytolu, mytolF, mytolF);
178   if (!S.IsDone() ||
179       S.IsAllNull()) { return; }
180
181   myDone = Standard_True;
182 }
183
184
185
186 //=======================================================================
187 //function : IsDone
188 //purpose  : 
189 //=======================================================================
190
191 Standard_Boolean Extrema_GenExtPC::IsDone () const {
192
193   return myDone;
194 }
195
196
197 //=======================================================================
198 //function : NbExt
199 //purpose  : 
200 //=======================================================================
201
202 Standard_Integer Extrema_GenExtPC::NbExt () const {
203
204   if (!IsDone()) { StdFail_NotDone::Raise(); }
205   return myF.NbExt();
206 }
207
208
209 //=======================================================================
210 //function : Value
211 //purpose  : 
212 //=======================================================================
213
214 Standard_Real Extrema_GenExtPC::SquareDistance (const Standard_Integer N) const {
215
216   if (!IsDone()) { StdFail_NotDone::Raise(); }
217   return myF.SquareDistance(N);
218 }
219
220
221 //=======================================================================
222 //function : IsMin
223 //purpose  : 
224 //=======================================================================
225
226 Standard_Boolean Extrema_GenExtPC::IsMin (const Standard_Integer N) const {
227
228   if (!IsDone()) { StdFail_NotDone::Raise(); }
229   return myF.IsMin(N);
230 }
231
232
233 //=======================================================================
234 //function : Point
235 //purpose  : 
236 //=======================================================================
237
238 const POnC & Extrema_GenExtPC::Point (const Standard_Integer N) const 
239 {
240   if (!IsDone()) { StdFail_NotDone::Raise(); }
241   return myF.Point(N);
242 }
243 //=============================================================================