0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / GeomAPI / GeomAPI_ProjectPointOnCurve.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <GeomAPI_ProjectPointOnCurve.ixx>
18
19 #include <GeomAdaptor_Curve.hxx>
20
21
22 //=======================================================================
23 //function : GeomAPI_ProjectPointOnCurve
24 //purpose  : 
25 //=======================================================================
26 GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve()
27 {
28   myIsDone = Standard_False;
29 }
30 //=======================================================================
31 //function : GeomAPI_ProjectPointOnCurve
32 //purpose  : 
33 //=======================================================================
34   GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve
35   (const gp_Pnt&             P, 
36    const Handle(Geom_Curve)& Curve)
37 {
38   Init(P,Curve);
39 }
40 //=======================================================================
41 //function : GeomAPI_ProjectPointOnCurve
42 //purpose  : 
43 //=======================================================================
44   GeomAPI_ProjectPointOnCurve::GeomAPI_ProjectPointOnCurve
45   (const gp_Pnt&             P, 
46    const Handle(Geom_Curve)& Curve,
47    const Standard_Real       Umin,
48    const Standard_Real       Usup)
49 {
50   Init(P,Curve,Umin,Usup);
51 }
52 //=======================================================================
53 //function : Init
54 //purpose  : 
55 //=======================================================================
56   void GeomAPI_ProjectPointOnCurve::Init
57   (const gp_Pnt&             P,
58    const Handle(Geom_Curve)& Curve)
59 {
60   myC.Load(Curve);
61 /*
62   Extrema_ExtPC theExtPC(P, myC);
63   myExtPC = theExtPC;
64 */
65   myExtPC.Initialize(myC, myC.FirstParameter(), myC.LastParameter());
66   myExtPC.Perform(P);
67   
68   myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
69
70   if ( myIsDone) {
71
72     // evaluate the lower distance and its index;
73     
74     Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
75     myIndex = 1;
76     
77     for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
78       Dist2 = myExtPC.SquareDistance(i);
79       if ( Dist2 < Dist2Min) {
80         Dist2Min = Dist2;
81         myIndex = i;
82       }
83     }
84   }
85 }
86 //=======================================================================
87 //function : Init
88 //purpose  : 
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 )
94 {
95   myC.Load(Curve,Umin,Usup);
96 /*
97   Extrema_ExtPC theExtPC(P, myC);
98   myExtPC = theExtPC;
99 */
100   myExtPC.Initialize(myC, myC.FirstParameter(), myC.LastParameter());
101   myExtPC.Perform(P);
102   
103   myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
104
105   if ( myIsDone) {
106
107     // evaluate the lower distance and its index;
108     
109     Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
110     myIndex = 1;
111     
112     for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
113       Dist2 = myExtPC.SquareDistance(i);
114       if ( Dist2 < Dist2Min) {
115         Dist2Min = Dist2;
116         myIndex = i;
117       }
118     }
119   }
120 }
121 //modified by NIZNHY-PKV Wed Apr  3 17:48:51 2002f
122 //=======================================================================
123 //function : Init
124 //purpose  : 
125 //=======================================================================
126   void GeomAPI_ProjectPointOnCurve::Init  (const Handle(Geom_Curve)& Curve,
127                                            const Standard_Real       Umin,
128                                            const Standard_Real       Usup )
129 {
130   myC.Load(Curve,Umin,Usup);
131   //myExtPC = Extrema_ExtPC(P, myC);
132   myExtPC.Initialize(myC, Umin, Usup);
133   myIsDone = Standard_False;
134 }
135 //=======================================================================
136 //function : Perform
137 //purpose  : 
138 //=======================================================================
139   void GeomAPI_ProjectPointOnCurve::Perform(const gp_Pnt& aP3D)
140 {
141   myExtPC.Perform(aP3D);
142   
143   myIsDone=myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
144   if (myIsDone) {
145     // evaluate the lower distance and its index;
146     Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
147     myIndex = 1;
148     
149     for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
150       Dist2 = myExtPC.SquareDistance(i);
151       if ( Dist2 < Dist2Min) {
152         Dist2Min = Dist2;
153         myIndex = i;
154       }
155     }
156   }
157 }
158 //modified by NIZNHY-PKV Wed Apr  3 17:48:53 2002t 
159 //=======================================================================
160 //function : NbPoints
161 //purpose  : 
162 //=======================================================================
163   Standard_Integer GeomAPI_ProjectPointOnCurve::NbPoints() const 
164 {
165   if ( myIsDone )
166     return myExtPC.NbExt();
167   else
168     return 0;
169 }
170 //=======================================================================
171 //function : Point
172 //purpose  : 
173 //=======================================================================
174   gp_Pnt GeomAPI_ProjectPointOnCurve::Point(const Standard_Integer Index) const 
175 {
176   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
177                                "GeomAPI_ProjectPointOnCurve::Point");
178   return (myExtPC.Point(Index)).Value();
179 }
180
181
182 //=======================================================================
183 //function : Parameter
184 //purpose  : 
185 //=======================================================================
186
187 Standard_Real GeomAPI_ProjectPointOnCurve::Parameter
188   (const Standard_Integer Index) const
189 {
190   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
191                                "GeomAPI_ProjectPointOnCurve::Parameter");
192   return (myExtPC.Point(Index)).Parameter();
193 }
194 //=======================================================================
195 //function : Parameter
196 //purpose  : 
197 //=======================================================================
198
199 void GeomAPI_ProjectPointOnCurve::Parameter
200   (const Standard_Integer Index,
201          Standard_Real&   U     ) const
202 {
203   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
204                                "GeomAPI_ProjectPointOnCurve::Parameter");
205   U = (myExtPC.Point(Index)).Parameter();
206 }
207 //=======================================================================
208 //function : Distance
209 //purpose  : 
210 //=======================================================================
211 Standard_Real GeomAPI_ProjectPointOnCurve::Distance
212   (const Standard_Integer Index) const 
213 {
214   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
215                                "GeomAPI_ProjectPointOnCurve::Distance");
216   return sqrt (myExtPC.SquareDistance(Index));
217 }
218 //=======================================================================
219 //function : NearestPoint
220 //purpose  : 
221 //=======================================================================
222
223 gp_Pnt GeomAPI_ProjectPointOnCurve::NearestPoint() const 
224 {
225   StdFail_NotDone_Raise_if 
226     ( !myIsDone, "GeomAPI_ProjectPointOnCurve::NearestPoint");
227                             
228   return (myExtPC.Point(myIndex)).Value();
229 }
230 //=======================================================================
231 //function : Standard_Integer
232 //purpose  : 
233 //=======================================================================
234
235 GeomAPI_ProjectPointOnCurve::operator Standard_Integer() const
236 {
237   return NbPoints();
238 }
239 //=======================================================================
240 //function : gp_Pnt
241 //purpose  : 
242 //=======================================================================
243
244 GeomAPI_ProjectPointOnCurve::operator gp_Pnt() const
245 {
246   return NearestPoint();
247 }
248 //=======================================================================
249 //function : LowerDistanceParameter
250 //purpose  : 
251 //=======================================================================
252
253 Standard_Real GeomAPI_ProjectPointOnCurve::LowerDistanceParameter() const
254 {
255   StdFail_NotDone_Raise_if
256     ( !myIsDone, "GeomAPI_ProjectPointOnCurve::LowerDistanceParameter");
257
258   return (myExtPC.Point(myIndex)).Parameter();
259 }
260 //=======================================================================
261 //function : LowerDistance
262 //purpose  : 
263 //=======================================================================
264 Standard_Real GeomAPI_ProjectPointOnCurve::LowerDistance() const
265 {
266   StdFail_NotDone_Raise_if
267     ( !myIsDone, "GeomAPI_ProjectPointOnCurve::LowerDistance");
268
269   return sqrt (myExtPC.SquareDistance(myIndex));
270 }
271 //=======================================================================
272 //function : operator
273 //purpose  : 
274 //=======================================================================
275 GeomAPI_ProjectPointOnCurve::operator Standard_Real() const
276 {
277   return LowerDistance();
278 }