1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Standard_OutOfRange.hxx>
18 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
19 const Standard_Integer NbU,
22 /*-----------------------------------------------------------------------------
24 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
25 point le plus proche du point P.
26 L'echantillonnage est fait a parametre constant sur l'intervalle de
27 definition de la courbe.
28 -----------------------------------------------------------------------------*/
30 if (NbU < 2) { Standard_OutOfRange::Raise(); }
32 Standard_Real U = Tool1::FirstParameter(C);
33 Standard_Real PasU = (Tool1::LastParameter(C) - U)/ (NbU - 1);
34 Standard_Real Dist2Min = RealLast(), UMin=0;
38 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
39 Pt = Tool1::Value(C, U);
40 Dist2 = Pt.SquareDistance(P);
41 if (Dist2 < Dist2Min) {
47 Papp.SetValues(UMin,PntMin);
52 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
53 const Standard_Integer NbU,
54 const Standard_Real Umin,
55 const Standard_Real Usup,
58 /*-----------------------------------------------------------------------------
60 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
61 point le plus proche du point P.
62 L'echantillonnage est fait a parametre constant sur l'intervalle de
63 definition de la courbe.
64 -----------------------------------------------------------------------------*/
66 if (NbU < 2) { Standard_OutOfRange::Raise(); }
67 Standard_Real U1, U2, U11, U12;
68 Standard_Real Uinf = Tool1::FirstParameter(C);
69 Standard_Real Ulast = Tool1::LastParameter(C);
72 U1 = Min(Uinf, Ulast);
73 U2 = Max(Uinf, Ulast);
74 U11 = Min(Umin, Usup);
75 U12 = Max(Umin, Usup);
77 if (U11 < U1 - RealEpsilon()) U11 = U1;
78 if (U12 > U2 + RealEpsilon()) U12 = U2;
80 Standard_Real U = U11;
81 Standard_Real PasU = (U12 - U)/ (NbU - 1);
82 Standard_Real Dist2Min = RealLast(), UMin=0;
86 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
87 Pt = Tool1::Value(C, U);
88 Dist2 = Pt.SquareDistance(P);
89 if (Dist2 < Dist2Min) {
95 Papp.SetValues(UMin, PntMin);