0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Extrema / Extrema_CurveLocator.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <Standard_OutOfRange.hxx>
16
17
18void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
19 const Standard_Integer NbU,
20 POnC& Papp) {
21
22/*-----------------------------------------------------------------------------
23Fonction:
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-----------------------------------------------------------------------------*/
29
9775fa61 30 if (NbU < 2) { throw Standard_OutOfRange(); }
7fd59977 31
32 Standard_Real U = Tool1::FirstParameter(C);
33 Standard_Real PasU = (Tool1::LastParameter(C) - U)/ (NbU - 1);
34 Standard_Real Dist2Min = RealLast(), UMin=0;
35 Pnt PntMin;
36 Standard_Real Dist2;
37 Pnt Pt;
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) {
42 Dist2Min = Dist2;
43 UMin = U;
44 PntMin = Pt;
45 }
46 }
47 Papp.SetValues(UMin,PntMin);
48}
49
50
51
52void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
53 const Standard_Integer NbU,
54 const Standard_Real Umin,
55 const Standard_Real Usup,
56 POnC& Papp) {
57
58/*-----------------------------------------------------------------------------
59Fonction:
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-----------------------------------------------------------------------------*/
65
9775fa61 66 if (NbU < 2) { throw Standard_OutOfRange(); }
7fd59977 67 Standard_Real U1, U2, U11, U12;
68 Standard_Real Uinf = Tool1::FirstParameter(C);
69 Standard_Real Ulast = Tool1::LastParameter(C);
70
71
72 U1 = Min(Uinf, Ulast);
73 U2 = Max(Uinf, Ulast);
74 U11 = Min(Umin, Usup);
75 U12 = Max(Umin, Usup);
76
77 if (U11 < U1 - RealEpsilon()) U11 = U1;
78 if (U12 > U2 + RealEpsilon()) U12 = U2;
79
80 Standard_Real U = U11;
81 Standard_Real PasU = (U12 - U)/ (NbU - 1);
82 Standard_Real Dist2Min = RealLast(), UMin=0;
83 Pnt PntMin;
84 Standard_Real Dist2;
85 Pnt Pt;
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) {
90 Dist2Min = Dist2;
91 UMin = U;
92 PntMin = Pt;
93 }
94 }
95 Papp.SetValues(UMin, PntMin);
96}
97
98
99