Warning, /include/opencascade/Extrema_CurveLocator.gxx is written in an unsupported language. File is not indexed.
0001 // Copyright (c) 1995-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014
0015 #include <Standard_OutOfRange.hxx>
0016
0017
0018 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
0019 const Standard_Integer NbU,
0020 POnC& Papp) {
0021
0022 /*-----------------------------------------------------------------------------
0023 Fonction:
0024 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
0025 point le plus proche du point P.
0026 L'echantillonnage est fait a parametre constant sur l'intervalle de
0027 definition de la courbe.
0028 -----------------------------------------------------------------------------*/
0029
0030 if (NbU < 2) { throw Standard_OutOfRange(); }
0031
0032 Standard_Real U = Tool1::FirstParameter(C);
0033 Standard_Real PasU = (Tool1::LastParameter(C) - U)/ (NbU - 1);
0034 Standard_Real Dist2Min = RealLast(), UMin=0;
0035 Pnt PntMin;
0036 Standard_Real Dist2;
0037 Pnt Pt;
0038 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
0039 Pt = Tool1::Value(C, U);
0040 Dist2 = Pt.SquareDistance(P);
0041 if (Dist2 < Dist2Min) {
0042 Dist2Min = Dist2;
0043 UMin = U;
0044 PntMin = Pt;
0045 }
0046 }
0047 Papp.SetValues(UMin,PntMin);
0048 }
0049
0050
0051
0052 void Extrema_CurveLocator::Locate (const Pnt& P, const Curve1& C,
0053 const Standard_Integer NbU,
0054 const Standard_Real Umin,
0055 const Standard_Real Usup,
0056 POnC& Papp) {
0057
0058 /*-----------------------------------------------------------------------------
0059 Fonction:
0060 Recherche, parmi un echantillon de 'NbU' points de la courbe C, du
0061 point le plus proche du point P.
0062 L'echantillonnage est fait a parametre constant sur l'intervalle de
0063 definition de la courbe.
0064 -----------------------------------------------------------------------------*/
0065
0066 if (NbU < 2) { throw Standard_OutOfRange(); }
0067 Standard_Real U1, U2, U11, U12;
0068 Standard_Real Uinf = Tool1::FirstParameter(C);
0069 Standard_Real Ulast = Tool1::LastParameter(C);
0070
0071
0072 U1 = Min(Uinf, Ulast);
0073 U2 = Max(Uinf, Ulast);
0074 U11 = Min(Umin, Usup);
0075 U12 = Max(Umin, Usup);
0076
0077 if (U11 < U1 - RealEpsilon()) U11 = U1;
0078 if (U12 > U2 + RealEpsilon()) U12 = U2;
0079
0080 Standard_Real U = U11;
0081 Standard_Real PasU = (U12 - U)/ (NbU - 1);
0082 Standard_Real Dist2Min = RealLast(), UMin=0;
0083 Pnt PntMin;
0084 Standard_Real Dist2;
0085 Pnt Pt;
0086 for ( Standard_Integer NoSample = 1; NoSample < NbU; NoSample++, U += PasU) {
0087 Pt = Tool1::Value(C, U);
0088 Dist2 = Pt.SquareDistance(P);
0089 if (Dist2 < Dist2Min) {
0090 Dist2Min = Dist2;
0091 UMin = U;
0092 PntMin = Pt;
0093 }
0094 }
0095 Papp.SetValues(UMin, PntMin);
0096 }
0097
0098
0099