b311480e |
1 | // Created on: 1994-03-23 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <Geom2dAPI_ProjectPointOnCurve.ixx> |
18 | |
19 | #include <Geom2dAdaptor_Curve.hxx> |
20 | |
21 | |
22 | //======================================================================= |
23 | //function : Geom2dAPI_ProjectPointOnCurve |
24 | //purpose : |
25 | //======================================================================= |
26 | |
27 | Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve() |
28 | { |
29 | myIsDone = Standard_False; |
30 | } |
31 | |
32 | |
33 | //======================================================================= |
34 | //function : Geom2dAPI_ProjectPointOnCurve |
35 | //purpose : |
36 | //======================================================================= |
37 | |
38 | Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve |
39 | (const gp_Pnt2d& P, |
40 | const Handle(Geom2d_Curve)& Curve) |
41 | { |
42 | Init(P,Curve); |
43 | } |
44 | |
45 | |
46 | //======================================================================= |
47 | //function : Geom2dAPI_ProjectPointOnCurve |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve |
52 | (const gp_Pnt2d& P, |
53 | const Handle(Geom2d_Curve)& Curve, |
54 | const Standard_Real Umin, |
55 | const Standard_Real Usup) |
56 | { |
57 | Init(P,Curve,Umin,Usup); |
58 | } |
59 | |
60 | |
61 | //======================================================================= |
62 | //function : Init |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | void Geom2dAPI_ProjectPointOnCurve::Init |
67 | (const gp_Pnt2d& P, |
68 | const Handle(Geom2d_Curve)& Curve) |
69 | { |
70 | Init(P,Curve,Curve->FirstParameter(),Curve->LastParameter()); |
71 | } |
72 | |
73 | |
74 | //======================================================================= |
75 | //function : Init |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | void Geom2dAPI_ProjectPointOnCurve::Init |
80 | (const gp_Pnt2d& P, |
81 | const Handle(Geom2d_Curve)& Curve, |
82 | const Standard_Real Umin, |
83 | const Standard_Real Usup ) |
84 | { |
85 | myC.Load(Curve,Umin,Usup); |
86 | |
87 | Extrema_ExtPC2d theExtPC2d(P, myC); |
88 | |
89 | myExtPC = theExtPC2d; |
90 | |
91 | myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0); |
92 | |
93 | |
94 | // evaluate the lower distance and its index; |
95 | |
96 | if ( myIsDone) { |
97 | Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1); |
98 | myIndex = 1; |
99 | |
100 | for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) { |
101 | Dist2 = myExtPC.SquareDistance(i); |
102 | if ( Dist2 < Dist2Min) { |
103 | Dist2Min = Dist2; |
104 | myIndex = i; |
105 | } |
106 | } |
107 | } |
108 | } |
109 | |
110 | |
111 | //======================================================================= |
112 | //function : NbPoints |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | Standard_Integer Geom2dAPI_ProjectPointOnCurve::NbPoints() const |
117 | { |
118 | if ( myIsDone) |
119 | return myExtPC.NbExt(); |
120 | else |
121 | return 0; |
122 | } |
123 | |
124 | |
125 | //======================================================================= |
126 | //function : Point |
127 | //purpose : |
128 | //======================================================================= |
129 | |
130 | gp_Pnt2d Geom2dAPI_ProjectPointOnCurve::Point |
131 | (const Standard_Integer Index) const |
132 | { |
133 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
134 | "Geom2dAPI_ProjectPointOnCurve::Point"); |
135 | return (myExtPC.Point(Index)).Value(); |
136 | } |
137 | |
138 | |
139 | //======================================================================= |
140 | //function : Parameter |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | Standard_Real Geom2dAPI_ProjectPointOnCurve::Parameter |
145 | (const Standard_Integer Index) const |
146 | { |
147 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
148 | "Geom2dAPI_ProjectPointOnCurve::Parameter"); |
149 | return (myExtPC.Point(Index)).Parameter(); |
150 | } |
151 | |
152 | |
153 | //======================================================================= |
154 | //function : Parameter |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | void Geom2dAPI_ProjectPointOnCurve::Parameter |
159 | (const Standard_Integer Index, |
160 | Standard_Real& U ) const |
161 | { |
162 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
163 | "Geom2dAPI_ProjectPointOnCurve::Parameter"); |
164 | U = (myExtPC.Point(Index)).Parameter(); |
165 | } |
166 | |
167 | |
168 | //======================================================================= |
169 | //function : Distance |
170 | //purpose : |
171 | //======================================================================= |
172 | |
173 | Standard_Real Geom2dAPI_ProjectPointOnCurve::Distance |
174 | (const Standard_Integer Index) const |
175 | { |
176 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
177 | "Geom2dAPI_ProjectPointOnCurve::Distance"); |
178 | return sqrt(myExtPC.SquareDistance(Index)); |
179 | } |
180 | |
181 | |
182 | //======================================================================= |
183 | //function : NearestPoint |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | gp_Pnt2d Geom2dAPI_ProjectPointOnCurve::NearestPoint() const |
188 | { |
189 | StdFail_NotDone_Raise_if |
190 | (!myIsDone, "Geom2dAPI_ProjectPointOnCurve:NearestPoint"); |
191 | |
192 | return (myExtPC.Point(myIndex)).Value(); |
193 | } |
194 | |
195 | |
196 | //======================================================================= |
197 | //function : Standard_Integer |
198 | //purpose : |
199 | //======================================================================= |
200 | |
201 | Geom2dAPI_ProjectPointOnCurve::operator Standard_Integer() const |
202 | { |
203 | return NbPoints(); |
204 | } |
205 | |
206 | |
207 | //======================================================================= |
208 | //function : gp_Pnt2d |
209 | //purpose : |
210 | //======================================================================= |
211 | |
212 | Geom2dAPI_ProjectPointOnCurve::operator gp_Pnt2d() const |
213 | { |
214 | return NearestPoint(); |
215 | } |
216 | |
217 | |
218 | //======================================================================= |
219 | //function : LowerDistanceParameter |
220 | //purpose : |
221 | //======================================================================= |
222 | |
223 | Standard_Real Geom2dAPI_ProjectPointOnCurve::LowerDistanceParameter() const |
224 | { |
225 | StdFail_NotDone_Raise_if |
226 | (!myIsDone, "Geom2dAPI_ProjectPointOnCurve:LowerDistanceParameter"); |
227 | |
228 | return (myExtPC.Point(myIndex)).Parameter(); |
229 | } |
230 | |
231 | |
232 | //======================================================================= |
233 | //function : LowerDistance |
234 | //purpose : |
235 | //======================================================================= |
236 | |
237 | Standard_Real Geom2dAPI_ProjectPointOnCurve::LowerDistance() const |
238 | { |
239 | StdFail_NotDone_Raise_if |
240 | (!myIsDone,"Geom2dAPI_ProjectPointOnCurve:LowerDistance"); |
241 | |
242 | return sqrt (myExtPC.SquareDistance(myIndex)); |
243 | } |
244 | |
245 | |
246 | //======================================================================= |
247 | //function : operator |
248 | //purpose : |
249 | //======================================================================= |
250 | |
251 | Geom2dAPI_ProjectPointOnCurve::operator Standard_Real() const |
252 | { |
253 | return LowerDistance(); |
254 | } |