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