0032832: Coding - get rid of unused headers [FairCurve to GeomAPI]
[occt.git] / src / GeomAPI / GeomAPI_ExtremaCurveSurface.cxx
1 // Created on: 1994-03-18
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 under
9 // the terms of the GNU Lesser General Public License 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
18 #include <Extrema_ExtCS.hxx>
19 #include <Extrema_POnCurv.hxx>
20 #include <Extrema_POnSurf.hxx>
21 #include <GeomAdaptor_Curve.hxx>
22 #include <GeomAdaptor_Surface.hxx>
23 #include <GeomAPI_ExtremaCurveSurface.hxx>
24 #include <gp_Pnt.hxx>
25 #include <Precision.hxx>
26 #include <Standard_OutOfRange.hxx>
27 #include <StdFail_NotDone.hxx>
28
29 //=======================================================================
30 //function : GeomAPI_ExtremaCurveSurface
31 //purpose  : 
32 //=======================================================================
33 GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface()
34 : myIsDone(Standard_False),
35   myIndex(0)
36 {
37 }
38
39
40 //=======================================================================
41 //function : GeomAPI_ExtremaCurveSurface
42 //purpose  : 
43 //=======================================================================
44
45 GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface
46   (const Handle(Geom_Curve)&   Curve,
47    const Handle(Geom_Surface)& Surface)
48 {
49   Init(Curve,Surface);
50 }
51
52
53 //=======================================================================
54 //function : GeomAPI_ExtremaCurveSurface
55 //purpose  : 
56 //=======================================================================
57
58 GeomAPI_ExtremaCurveSurface::GeomAPI_ExtremaCurveSurface
59   (const Handle(Geom_Curve)&   Curve,
60    const Handle(Geom_Surface)& Surface,
61    const Standard_Real         Wmin,
62    const Standard_Real         Wmax,
63    const Standard_Real         Umin,
64    const Standard_Real         Umax,
65    const Standard_Real         Vmin,
66    const Standard_Real         Vmax)
67 {
68   Init(Curve,Surface,Wmin,Wmax,Umin,Umax,Vmin,Vmax);
69 }
70
71
72 //=======================================================================
73 //function : Init
74 //purpose  : 
75 //=======================================================================
76
77 void GeomAPI_ExtremaCurveSurface::Init
78   (const Handle(Geom_Curve)&   Curve,
79    const Handle(Geom_Surface)& Surface)
80 {
81   GeomAdaptor_Curve   TheCurve   (Curve);
82   GeomAdaptor_Surface TheSurface (Surface);
83
84   Standard_Real Tol = Precision::PConfusion();
85   myExtCS.Initialize (TheSurface, Tol, Tol);
86   myExtCS.Perform (TheCurve, TheCurve.FirstParameter(), TheCurve.LastParameter());
87   myIsDone = myExtCS.IsDone() && (myExtCS.IsParallel() || myExtCS.NbExt() > 0);
88
89   if ( myIsDone) {
90
91     // evaluate the lower distance and its index;
92     
93     Standard_Real Dist2, Dist2Min = myExtCS.SquareDistance(1);
94     myIndex = 1;
95     
96     for ( Standard_Integer i = 2; i <= myExtCS.NbExt(); i++) {
97       Dist2 = myExtCS.SquareDistance(i);
98       if ( Dist2 < Dist2Min) {
99         Dist2Min = Dist2;
100         myIndex = i;
101       }
102     }
103   }
104 }
105
106
107 //=======================================================================
108 //function : Init
109 //purpose  : 
110 //=======================================================================
111
112 void GeomAPI_ExtremaCurveSurface::Init
113   (const Handle(Geom_Curve)&   Curve,
114    const Handle(Geom_Surface)& Surface,
115    const Standard_Real         Wmin,
116    const Standard_Real         Wmax,
117    const Standard_Real         Umin,
118    const Standard_Real         Umax,
119    const Standard_Real         Vmin,
120    const Standard_Real         Vmax)
121 {
122   GeomAdaptor_Curve   TheCurve   (Curve, Wmin, Wmax);
123   GeomAdaptor_Surface TheSurface (Surface, Umin, Umax, Vmin, Vmax);
124
125   Standard_Real Tol = Precision::PConfusion();
126   myExtCS.Initialize (TheSurface,
127                       Umin,Umax,Vmin,Vmax,Tol,Tol);
128   myExtCS.Perform (TheCurve, Wmin, Wmax);
129   myIsDone = myExtCS.IsDone() && (myExtCS.IsParallel() || myExtCS.NbExt() > 0);
130
131   if ( myIsDone) {
132
133     // evaluate the lower distance and its index;
134     
135     Standard_Real Dist2, Dist2Min = myExtCS.SquareDistance(1);
136     myIndex = 1;
137     
138     for ( Standard_Integer i = 2; i <= myExtCS.NbExt(); i++) {
139       Dist2 = myExtCS.SquareDistance(i);
140       if ( Dist2 < Dist2Min) {
141         Dist2Min = Dist2;
142         myIndex = i;
143       }
144     }
145   }
146 }
147
148
149 //=======================================================================
150 //function : NbExtrema
151 //purpose  : 
152 //=======================================================================
153
154 Standard_Integer GeomAPI_ExtremaCurveSurface::NbExtrema() const 
155 {
156   if ( myIsDone) 
157     return myExtCS.NbExt();
158   else
159     return 0;
160 }
161
162
163 //=======================================================================
164 //function : Points
165 //purpose  : 
166 //=======================================================================
167
168 void GeomAPI_ExtremaCurveSurface::Points
169   (const Standard_Integer Index,
170          gp_Pnt&          P1,
171          gp_Pnt&          P2) const 
172 {
173   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(),
174                                "GeomAPI_ExtremaCurveCurve::Points");
175
176   Extrema_POnCurv PC;
177   Extrema_POnSurf PS;
178   myExtCS.Points(Index,PC,PS);
179
180   P1 = PC.Value();
181   P2 = PS.Value();
182 }
183
184
185 //=======================================================================
186 //function : Parameters
187 //purpose  : 
188 //=======================================================================
189
190 void GeomAPI_ExtremaCurveSurface::Parameters
191   (const Standard_Integer Index,
192          Standard_Real&   W, 
193          Standard_Real&   U, 
194          Standard_Real&   V) const 
195 {
196   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(),
197                                "GeomAPI_ExtremaCurveCurve::Parameters");
198
199   Extrema_POnCurv PC;
200   Extrema_POnSurf PS;
201   myExtCS.Points(Index,PC,PS);
202
203   W = PC.Parameter();
204   PS.Parameter(U,V);
205 }
206
207
208 //=======================================================================
209 //function : Distance
210 //purpose  : 
211 //=======================================================================
212
213 Standard_Real GeomAPI_ExtremaCurveSurface::Distance
214   (const Standard_Integer Index) const 
215 {
216   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbExtrema(),
217                                "GeomAPI_ExtremaCurveCurve::Distance");
218
219   return sqrt (myExtCS.SquareDistance(Index));
220 }
221
222
223 //=======================================================================
224 //function : NearestPoints
225 //purpose  : 
226 //=======================================================================
227
228 void GeomAPI_ExtremaCurveSurface::NearestPoints(gp_Pnt& PC, gp_Pnt& PS) const 
229 {
230   StdFail_NotDone_Raise_if
231     (!myIsDone, "GeomAPI_ExtremaCurveSurface::NearestPoints");
232
233   Points(myIndex,PC,PS);
234 }
235
236
237 //=======================================================================
238 //function : LowerDistanceParameters
239 //purpose  : 
240 //=======================================================================
241
242 void GeomAPI_ExtremaCurveSurface::LowerDistanceParameters
243   (Standard_Real& W, 
244    Standard_Real& U, 
245    Standard_Real& V) const 
246 {
247   StdFail_NotDone_Raise_if
248     (!myIsDone, "GeomAPI_ExtremaCurveSurface::LowerDistanceParameters");
249
250   Parameters(myIndex,W,U,V);
251 }
252
253
254 //=======================================================================
255 //function : LowerDistance
256 //purpose  : 
257 //=======================================================================
258
259 Standard_Real GeomAPI_ExtremaCurveSurface::LowerDistance() const 
260 {
261   StdFail_NotDone_Raise_if
262     (!myIsDone, "GeomAPI_ExtremaCurveSurface::LowerDistance");
263
264   return sqrt (myExtCS.SquareDistance(myIndex));
265 }
266
267
268 //=======================================================================
269 //function : Standard_Integer
270 //purpose  : 
271 //=======================================================================
272
273 GeomAPI_ExtremaCurveSurface::operator Standard_Integer() const
274 {
275   return NbExtrema();
276 }
277
278
279 //=======================================================================
280 //function : Standard_Real
281 //purpose  : 
282 //=======================================================================
283
284 GeomAPI_ExtremaCurveSurface::operator Standard_Real() const
285 {
286   return LowerDistance();
287 }
288
289