1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <Standard_OutOfRange.hxx>
22 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
23 const Standard_Integer NbU,
26 /*-----------------------------------------------------------------------------
28 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
29 point le plus proche du point P.
30 L'echantillonnage est fait a parametre constant sur l'intervalle de
31 definition de la courbe.
32 -----------------------------------------------------------------------------*/
34 if (NbU < 2) { Standard_OutOfRange::Raise(); }
36 Standard_Real U = Tool1::FirstParameter(C);
37 Standard_Real PasU = (Tool1::LastParameter(C) - U)/ (NbU - 1);
38 Standard_Real Dist2Min = RealLast(), UMin=0;
42 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
43 Pt = Tool1::Value(C, U);
44 Dist2 = Pt.SquareDistance(P);
45 if (Dist2 < Dist2Min) {
51 Papp.SetValues(UMin,PntMin);
56 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
57 const Standard_Integer NbU,
58 const Standard_Real Umin,
59 const Standard_Real Usup,
62 /*-----------------------------------------------------------------------------
64 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
65 point le plus proche du point P.
66 L'echantillonnage est fait a parametre constant sur l'intervalle de
67 definition de la courbe.
68 -----------------------------------------------------------------------------*/
70 if (NbU < 2) { Standard_OutOfRange::Raise(); }
71 Standard_Real U1, U2, U11, U12;
72 Standard_Real Uinf = Tool1::FirstParameter(C);
73 Standard_Real Ulast = Tool1::LastParameter(C);
76 U1 = Min(Uinf, Ulast);
77 U2 = Max(Uinf, Ulast);
78 U11 = Min(Umin, Usup);
79 U12 = Max(Umin, Usup);
81 if (U11 < U1 - RealEpsilon()) U11 = U1;
82 if (U12 > U2 + RealEpsilon()) U12 = U2;
84 Standard_Real U = U11;
85 Standard_Real PasU = (U12 - U)/ (NbU - 1);
86 Standard_Real Dist2Min = RealLast(), UMin=0;
90 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
91 Pt = Tool1::Value(C, U);
92 Dist2 = Pt.SquareDistance(P);
93 if (Dist2 < Dist2Min) {
99 Papp.SetValues(UMin, PntMin);