0026937: Eliminate NO_CXX_EXCEPTION macro support
[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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 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
26Extrema_GenLocateExtPC::Extrema_GenLocateExtPC()
27{
28 myDone = Standard_False;
29}
30
31
32//=======================================================================
33//function : Extrema_GenLocateExtPC
34//purpose :
35//=======================================================================
36
37Extrema_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
52Extrema_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
69void 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
87void Extrema_GenLocateExtPC::Perform(const Pnt& P,
88 const Standard_Real U0)
89
90/*-----------------------------------------------------------------------------
91Fonction:
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
96Methode:
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
129Standard_Boolean Extrema_GenLocateExtPC::IsDone () const
130{
131 return myDone;
132}
133
134
135//=======================================================================
136//function : Value
137//purpose :
138//=======================================================================
139
140Standard_Real Extrema_GenLocateExtPC::SquareDistance() const
141{
9775fa61 142 if (!myDone) { throw StdFail_NotDone(); }
7fd59977 143 return myF.SquareDistance(1);
144}
145
146
147//=======================================================================
148//function : IsMin
149//purpose :
150//=======================================================================
151
152Standard_Boolean Extrema_GenLocateExtPC::IsMin () const
153{
9775fa61 154 if (!myDone) { throw StdFail_NotDone(); }
7fd59977 155 return myF.IsMin(1);
156}
157
158
159//=======================================================================
160//function : Point
161//purpose :
162//=======================================================================
163
5d99f2c8 164const POnC & Extrema_GenLocateExtPC::Point () const
7fd59977 165{
9775fa61 166 if (!myDone) { throw StdFail_NotDone(); }
7fd59977 167 return myF.Point(1);
168}
169