0024138: Exception during projection of the point on the face
[occt.git] / src / Extrema / Extrema_GenLocateExtPC.gxx
CommitLineData
b311480e 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
7fd59977 21
22
23#include <StdFail_NotDone.hxx>
24#include <Standard_DomainError.hxx>
25#include <math_FunctionRoot.hxx>
26
27//=======================================================================
28//function : Extrema_GenLocateExtPC
29//purpose :
30//=======================================================================
31
32Extrema_GenLocateExtPC::Extrema_GenLocateExtPC()
33{
34 myDone = Standard_False;
35}
36
37
38//=======================================================================
39//function : Extrema_GenLocateExtPC
40//purpose :
41//=======================================================================
42
43Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt& P,
44 const Curve& C,
45 const Standard_Real U0,
46 const Standard_Real TolU)
47{
48 Initialize(C, Tool::FirstParameter(C), Tool::LastParameter(C), TolU);
49 Perform(P, U0);
50}
51
52
53//=======================================================================
54//function : Extrema_GenLocateExtPC
55//purpose :
56//=======================================================================
57
58Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt& P,
59 const Curve& C,
60 const Standard_Real U0,
61 const Standard_Real Umin,
62 const Standard_Real Usup,
63 const Standard_Real TolU)
64{
65 Initialize(C, Umin, Usup, TolU);
66 Perform(P, U0);
67}
68
69
70//=======================================================================
71//function : Initialize
72//purpose :
73//=======================================================================
74
75void Extrema_GenLocateExtPC::Initialize(const Curve& C,
76 const Standard_Real Umin,
77 const Standard_Real Usup,
78 const Standard_Real TolU)
79{
80 myDone = Standard_False;
81 myF.Initialize(C);
82 myumin = Umin;
83 myusup = Usup;
84 mytolU = TolU;
85}
86
87
88//=======================================================================
89//function : Perform
90//purpose :
91//=======================================================================
92
93void Extrema_GenLocateExtPC::Perform(const Pnt& P,
94 const Standard_Real U0)
95
96/*-----------------------------------------------------------------------------
97Fonction:
98 Recherche de la valeur de parametre U telle que:
99 - dist(P,C(u)) passe par un extremum,
100 - U soit la solution la plus proche de U0.
101
102Methode:
103 Si U est solution, alors F(U)=(C(U)-P).C'(U) = 0.
104 Le probleme consiste a rechercher, dans l'intervalle de definition
105 de la courbe, la racine de F la plus proche de U0.
106 On utilise la classe math_FunctionRoot avec les arguments de
107 construction suivants:
108 - F: Extrema_FuncExtPC cree a partir de P et C,
109 - U0,
110 - TolU,
111 - Uinf: borne inferieure de l'intervalle de definition,
112 - Ulast: borne superieure de l'intervalle de definition,
113 - 100. .
114-----------------------------------------------------------------------------*/
115{
116 myF.SetPoint(P);
117 math_FunctionRoot S (myF, U0, mytolU, myumin, myusup);
118 myDone = S.IsDone();
119 if (myDone) {
120 Standard_Real uu, ff;
121 POnC PP = Point();
122 uu = PP.Parameter();
123 if(myF.Value(uu, ff)) {
124 if (Abs(ff) >= 1.e-07) myDone = Standard_False;
125 }
126 else myDone = Standard_False;
127 }
128}
129
130//=======================================================================
131//function : IsDone
132//purpose :
133//=======================================================================
134
135Standard_Boolean Extrema_GenLocateExtPC::IsDone () const
136{
137 return myDone;
138}
139
140
141//=======================================================================
142//function : Value
143//purpose :
144//=======================================================================
145
146Standard_Real Extrema_GenLocateExtPC::SquareDistance() const
147{
148 if (!myDone) { StdFail_NotDone::Raise(); }
149 return myF.SquareDistance(1);
150}
151
152
153//=======================================================================
154//function : IsMin
155//purpose :
156//=======================================================================
157
158Standard_Boolean Extrema_GenLocateExtPC::IsMin () const
159{
160 if (!myDone) { StdFail_NotDone::Raise(); }
161 return myF.IsMin(1);
162}
163
164
165//=======================================================================
166//function : Point
167//purpose :
168//=======================================================================
169
170POnC Extrema_GenLocateExtPC::Point () const
171{
172 if (!myDone) { StdFail_NotDone::Raise(); }
173 return myF.Point(1);
174}
175