summaryrefslogtreecommitdiff
path: root/inc/Extrema_GenLocateExtPC.gxx
blob: c261f30c99ebc02d860054c3fa7a5732ee0e4496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// File:	Extrema_GenLocateExtPC.gxx
// Created:	Tue Jul 18 17:40:47 1995
// Author:	Modelistation
//		<model@metrox>


#include <StdFail_NotDone.hxx>
#include <Standard_DomainError.hxx>
#include <math_FunctionRoot.hxx>

//=======================================================================
//function : Extrema_GenLocateExtPC
//purpose  : 
//=======================================================================

Extrema_GenLocateExtPC::Extrema_GenLocateExtPC() 
{ 
  myDone = Standard_False; 
}


//=======================================================================
//function : Extrema_GenLocateExtPC
//purpose  : 
//=======================================================================

Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt&          P,
						const Curve&        C,
						const Standard_Real U0, 
						const Standard_Real TolU)
{
  Initialize(C, Tool::FirstParameter(C), Tool::LastParameter(C), TolU);
  Perform(P, U0);
}


//=======================================================================
//function : Extrema_GenLocateExtPC
//purpose  : 
//=======================================================================

Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt&          P,
						const Curve&        C,
						const Standard_Real U0, 
						const Standard_Real Umin,
						const Standard_Real Usup,
						const Standard_Real TolU)
{
  Initialize(C, Umin, Usup, TolU);
  Perform(P, U0);
}


//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void Extrema_GenLocateExtPC::Initialize(const Curve&        C,
					const Standard_Real Umin,
					const Standard_Real Usup,
					const Standard_Real TolU)
{
  myDone = Standard_False;
  myF.Initialize(C);
  myumin = Umin;
  myusup = Usup;
  mytolU = TolU;
}


//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void Extrema_GenLocateExtPC::Perform(const Pnt&          P,
				     const Standard_Real U0)

/*-----------------------------------------------------------------------------
Fonction:
  Recherche de la valeur de parametre U telle que:
  - dist(P,C(u)) passe par un extremum,
  - U soit la solution la plus proche de U0.

Methode:
  Si U est solution, alors F(U)=(C(U)-P).C'(U) = 0.
  Le probleme consiste a rechercher, dans l'intervalle de definition
  de la courbe, la racine de F la plus proche de U0.
  On utilise la classe math_FunctionRoot avec les arguments de
  construction suivants:
  - F: Extrema_FuncExtPC cree a partir de P et C,
  - U0,
  - TolU,
  - Uinf: borne inferieure de l'intervalle de definition,
  - Ulast: borne superieure de l'intervalle de definition,
  - 100. .
-----------------------------------------------------------------------------*/
{
  myF.SetPoint(P);
  math_FunctionRoot S (myF, U0, mytolU, myumin, myusup);
  myDone = S.IsDone();
  if (myDone) {
    Standard_Real uu, ff;
    POnC PP = Point();
    uu = PP.Parameter();
    if(myF.Value(uu, ff)) {
      if (Abs(ff) >= 1.e-07) myDone = Standard_False;
    }
    else myDone = Standard_False;
  }
}

//=======================================================================
//function : IsDone
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_GenLocateExtPC::IsDone () const 
{
  return myDone;
}


//=======================================================================
//function : Value
//purpose  : 
//=======================================================================

Standard_Real Extrema_GenLocateExtPC::SquareDistance() const 
{
  if (!myDone) { StdFail_NotDone::Raise(); }
  return myF.SquareDistance(1);
}


//=======================================================================
//function : IsMin
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_GenLocateExtPC::IsMin () const 
{
  if (!myDone) { StdFail_NotDone::Raise(); }
  return myF.IsMin(1);
}


//=======================================================================
//function : Point
//purpose  : 
//=======================================================================

POnC Extrema_GenLocateExtPC::Point () const 
{
  if (!myDone) { StdFail_NotDone::Raise(); }
  return myF.Point(1);
}