dfc62eb05d392f0fdd5b82356a0a61abfcfb4827
[occt.git] / src / Extrema / Extrema_GenLocateExtPC.gxx
1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <StdFail_NotDone.hxx>
18 #include <Standard_DomainError.hxx>
19 #include <math_FunctionRoot.hxx>
20
21 //=======================================================================
22 //function : Extrema_GenLocateExtPC
23 //purpose  : 
24 //=======================================================================
25
26 Extrema_GenLocateExtPC::Extrema_GenLocateExtPC() 
27
28   myDone = Standard_False; 
29 }
30
31
32 //=======================================================================
33 //function : Extrema_GenLocateExtPC
34 //purpose  : 
35 //=======================================================================
36
37 Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt&          P,
38                                                 const Curve&        C,
39                                                 const Standard_Real U0, 
40                                                 const Standard_Real TolU)
41 {
42   Initialize(C, Tool::FirstParameter(C), Tool::LastParameter(C), TolU);
43   Perform(P, U0);
44 }
45
46
47 //=======================================================================
48 //function : Extrema_GenLocateExtPC
49 //purpose  : 
50 //=======================================================================
51
52 Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt&          P,
53                                                 const Curve&        C,
54                                                 const Standard_Real U0, 
55                                                 const Standard_Real Umin,
56                                                 const Standard_Real Usup,
57                                                 const Standard_Real TolU)
58 {
59   Initialize(C, Umin, Usup, TolU);
60   Perform(P, U0);
61 }
62
63
64 //=======================================================================
65 //function : Initialize
66 //purpose  : 
67 //=======================================================================
68
69 void Extrema_GenLocateExtPC::Initialize(const Curve&        C,
70                                         const Standard_Real Umin,
71                                         const Standard_Real Usup,
72                                         const Standard_Real TolU)
73 {
74   myDone = Standard_False;
75   myF.Initialize(C);
76   myumin = Umin;
77   myusup = Usup;
78   mytolU = TolU;
79 }
80
81
82 //=======================================================================
83 //function : Perform
84 //purpose  : 
85 //=======================================================================
86
87 void Extrema_GenLocateExtPC::Perform(const Pnt&          P,
88                                      const Standard_Real U0)
89
90 /*-----------------------------------------------------------------------------
91 Fonction:
92   Recherche de la valeur de parametre U telle que:
93   - dist(P,C(u)) passe par un extremum,
94   - U soit la solution la plus proche de U0.
95
96 Methode:
97   Si U est solution, alors F(U)=(C(U)-P).C'(U) = 0.
98   Le probleme consiste a rechercher, dans l'intervalle de definition
99   de la courbe, la racine de F la plus proche de U0.
100   On utilise la classe math_FunctionRoot avec les arguments de
101   construction suivants:
102   - F: Extrema_FuncExtPC cree a partir de P et C,
103   - U0,
104   - TolU,
105   - Uinf: borne inferieure de l'intervalle de definition,
106   - Ulast: borne superieure de l'intervalle de definition,
107   - 100. .
108 -----------------------------------------------------------------------------*/
109 {
110   myF.SetPoint(P);
111   math_FunctionRoot S (myF, U0, mytolU, myumin, myusup);
112   myDone = S.IsDone();
113   if (myDone) {
114     Standard_Real uu, ff;
115     POnC PP = Point();
116     uu = PP.Parameter();
117     if(myF.Value(uu, ff)) {
118       if (Abs(ff) >= 1.e-07) myDone = Standard_False;
119     }
120     else myDone = Standard_False;
121   }
122 }
123
124 //=======================================================================
125 //function : IsDone
126 //purpose  : 
127 //=======================================================================
128
129 Standard_Boolean Extrema_GenLocateExtPC::IsDone () const 
130 {
131   return myDone;
132 }
133
134
135 //=======================================================================
136 //function : Value
137 //purpose  : 
138 //=======================================================================
139
140 Standard_Real Extrema_GenLocateExtPC::SquareDistance() const 
141 {
142   if (!IsDone())
143   {
144     throw StdFail_NotDone();
145   }
146   return myF.SquareDistance(1);
147 }
148
149
150 //=======================================================================
151 //function : IsMin
152 //purpose  : 
153 //=======================================================================
154
155 Standard_Boolean Extrema_GenLocateExtPC::IsMin () const 
156 {
157   if (!IsDone())
158   {
159     throw StdFail_NotDone();
160   }
161   return myF.IsMin(1);
162 }
163
164
165 //=======================================================================
166 //function : Point
167 //purpose  : 
168 //=======================================================================
169
170 const POnC & Extrema_GenLocateExtPC::Point () const 
171 {
172   if (!IsDone())
173   {
174     throw StdFail_NotDone();
175   }
176   return myF.Point(1);
177 }
178