1 // Created on: 1994-03-17
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <GeomAPI_ProjectPointOnCurve.ixx>
19 #include <GeomAdaptor_Curve.hxx>
22 //=======================================================================
23 //function : GeomAPI_ProjectPointOnCurve
25 //=======================================================================
26 GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve()
28 myIsDone = Standard_False;
30 //=======================================================================
31 //function : GeomAPI_ProjectPointOnCurve
33 //=======================================================================
34 GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve
36 const Handle(Geom_Curve)& Curve)
40 //=======================================================================
41 //function : GeomAPI_ProjectPointOnCurve
43 //=======================================================================
44 GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve
46 const Handle(Geom_Curve)& Curve,
47 const Standard_Real Umin,
48 const Standard_Real Usup)
50 Init(P,Curve,Umin,Usup);
52 //=======================================================================
55 //=======================================================================
56 void GeomAPI_ProjectPointOnCurve::Init
58 const Handle(Geom_Curve)& Curve)
62 Extrema_ExtPC theExtPC(P, myC);
65 myExtPC.Initialize(myC, myC.FirstParameter(), myC.LastParameter());
68 myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
72 // evaluate the lower distance and its index;
74 Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
77 for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
78 Dist2 = myExtPC.SquareDistance(i);
79 if ( Dist2 < Dist2Min) {
86 //=======================================================================
89 //=======================================================================
90 void GeomAPI_ProjectPointOnCurve::Init(const gp_Pnt& P,
91 const Handle(Geom_Curve)& Curve,
92 const Standard_Real Umin,
93 const Standard_Real Usup )
95 myC.Load(Curve,Umin,Usup);
97 Extrema_ExtPC theExtPC(P, myC);
100 myExtPC.Initialize(myC, myC.FirstParameter(), myC.LastParameter());
103 myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
107 // evaluate the lower distance and its index;
109 Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
112 for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
113 Dist2 = myExtPC.SquareDistance(i);
114 if ( Dist2 < Dist2Min) {
121 //modified by NIZNHY-PKV Wed Apr 3 17:48:51 2002f
122 //=======================================================================
125 //=======================================================================
126 void GeomAPI_ProjectPointOnCurve::Init (const Handle(Geom_Curve)& Curve,
127 const Standard_Real Umin,
128 const Standard_Real Usup )
130 myC.Load(Curve,Umin,Usup);
131 //myExtPC = Extrema_ExtPC(P, myC);
132 myExtPC.Initialize(myC, Umin, Usup);
133 myIsDone = Standard_False;
135 //=======================================================================
138 //=======================================================================
139 void GeomAPI_ProjectPointOnCurve::Perform(const gp_Pnt& aP3D)
141 myExtPC.Perform(aP3D);
143 myIsDone=myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
145 // evaluate the lower distance and its index;
146 Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
149 for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
150 Dist2 = myExtPC.SquareDistance(i);
151 if ( Dist2 < Dist2Min) {
158 //modified by NIZNHY-PKV Wed Apr 3 17:48:53 2002t
159 //=======================================================================
160 //function : NbPoints
162 //=======================================================================
163 Standard_Integer GeomAPI_ProjectPointOnCurve::NbPoints() const
166 return myExtPC.NbExt();
170 //=======================================================================
173 //=======================================================================
174 gp_Pnt GeomAPI_ProjectPointOnCurve::Point(const Standard_Integer Index) const
176 Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
177 "GeomAPI_ProjectPointOnCurve::Point");
178 return (myExtPC.Point(Index)).Value();
182 //=======================================================================
183 //function : Parameter
185 //=======================================================================
187 Standard_Real GeomAPI_ProjectPointOnCurve::Parameter
188 (const Standard_Integer Index) const
190 Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
191 "GeomAPI_ProjectPointOnCurve::Parameter");
192 return (myExtPC.Point(Index)).Parameter();
194 //=======================================================================
195 //function : Parameter
197 //=======================================================================
199 void GeomAPI_ProjectPointOnCurve::Parameter
200 (const Standard_Integer Index,
201 Standard_Real& U ) const
203 Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
204 "GeomAPI_ProjectPointOnCurve::Parameter");
205 U = (myExtPC.Point(Index)).Parameter();
207 //=======================================================================
208 //function : Distance
210 //=======================================================================
211 Standard_Real GeomAPI_ProjectPointOnCurve::Distance
212 (const Standard_Integer Index) const
214 Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
215 "GeomAPI_ProjectPointOnCurve::Distance");
216 return sqrt (myExtPC.SquareDistance(Index));
218 //=======================================================================
219 //function : NearestPoint
221 //=======================================================================
223 gp_Pnt GeomAPI_ProjectPointOnCurve::NearestPoint() const
225 StdFail_NotDone_Raise_if
226 ( !myIsDone, "GeomAPI_ProjectPointOnCurve::NearestPoint");
228 return (myExtPC.Point(myIndex)).Value();
230 //=======================================================================
231 //function : Standard_Integer
233 //=======================================================================
235 GeomAPI_ProjectPointOnCurve::operator Standard_Integer() const
239 //=======================================================================
242 //=======================================================================
244 GeomAPI_ProjectPointOnCurve::operator gp_Pnt() const
246 return NearestPoint();
248 //=======================================================================
249 //function : LowerDistanceParameter
251 //=======================================================================
253 Standard_Real GeomAPI_ProjectPointOnCurve::LowerDistanceParameter() const
255 StdFail_NotDone_Raise_if
256 ( !myIsDone, "GeomAPI_ProjectPointOnCurve::LowerDistanceParameter");
258 return (myExtPC.Point(myIndex)).Parameter();
260 //=======================================================================
261 //function : LowerDistance
263 //=======================================================================
264 Standard_Real GeomAPI_ProjectPointOnCurve::LowerDistance() const
266 StdFail_NotDone_Raise_if
267 ( !myIsDone, "GeomAPI_ProjectPointOnCurve::LowerDistance");
269 return sqrt (myExtPC.SquareDistance(myIndex));
271 //=======================================================================
272 //function : operator
274 //=======================================================================
275 GeomAPI_ProjectPointOnCurve::operator Standard_Real() const
277 return LowerDistance();