0024624: Lost word in license statement in source files
[occt.git] / src / Geom2dAPI / Geom2dAPI_ExtremaCurveCurve.cxx
1 // Created on: 1994-03-23
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 #include <Geom2dAPI_ExtremaCurveCurve.ixx>
18
19 #include <Geom2dAdaptor_Curve.hxx>
20 #include <Extrema_POnCurv2d.hxx>
21
22 #include <Precision.hxx>
23
24 //=======================================================================
25 //function : Geom2dAPI_ExtremaCurveCurve
26 //purpose  : 
27 //=======================================================================
28
29 //Geom2dAPI_ExtremaCurveCurve::Geom2dAPI_ExtremaCurveCurve()
30 //{
31 //}
32
33
34 //=======================================================================
35 //function : Geom2dAPI_ExtremaCurveCurve
36 //purpose  : 
37 //=======================================================================
38
39 Geom2dAPI_ExtremaCurveCurve::Geom2dAPI_ExtremaCurveCurve
40   (const Handle(Geom2d_Curve)& C1,
41    const Handle(Geom2d_Curve)& C2,
42    const Standard_Real         U1min,
43    const Standard_Real         U1max,
44    const Standard_Real         U2min,
45    const Standard_Real         U2max)
46 {
47   myC1.Load(C1, U1min, U1max);
48   myC2.Load(C2, U2min, U2max);
49   Extrema_ExtCC2d theExtCC( myC1, myC2 );
50
51   myExtCC = theExtCC;
52
53   myIsDone = myExtCC.IsDone() && ( myExtCC.NbExt() > 0);
54
55
56   if ( myIsDone ) {
57     // evaluate the lower distance and its index;
58     
59     Standard_Real Dist2, Dist2Min = myExtCC.SquareDistance(1);
60     myIndex = 1;
61
62     for ( Standard_Integer i = 2; i <= myExtCC.NbExt(); i++) {
63       Dist2 = myExtCC.SquareDistance(i);
64       if ( Dist2 < Dist2Min) {
65         Dist2Min = Dist2;
66         myIndex = i;
67       }
68     }
69   }
70 }
71
72
73 //=======================================================================
74 //function : NbExtrema
75 //purpose  : 
76 //=======================================================================
77
78 Standard_Integer Geom2dAPI_ExtremaCurveCurve::NbExtrema() const 
79 {
80   if ( myIsDone)
81     return myExtCC.NbExt();
82   else
83     return 0;
84 }
85
86
87 //=======================================================================
88 //function : Points
89 //purpose  : 
90 //=======================================================================
91
92 void Geom2dAPI_ExtremaCurveCurve::Points
93   (const Standard_Integer Index,
94          gp_Pnt2d&        P1,
95          gp_Pnt2d&        P2) const 
96 {
97   Standard_OutOfRange_Raise_if
98     (Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve::Points");
99
100   Extrema_POnCurv2d PC1, PC2;
101   myExtCC.Points(Index,PC1,PC2);
102
103   P1 = PC1.Value();
104   P2 = PC2.Value();
105 }
106
107
108 //=======================================================================
109 //function : Parameters
110 //purpose  : 
111 //=======================================================================
112
113 void Geom2dAPI_ExtremaCurveCurve::Parameters
114   (const Standard_Integer Index, 
115          Standard_Real&   U1,
116          Standard_Real&   U2) const 
117 {
118   Standard_OutOfRange_Raise_if
119     (Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve::Parameters");
120
121   Extrema_POnCurv2d PC1, PC2;
122   myExtCC.Points(Index,PC1,PC2);
123
124   U1 = PC1.Parameter();
125   U2 = PC2.Parameter();
126 }
127
128
129 //=======================================================================
130 //function : Distance
131 //purpose  : 
132 //=======================================================================
133
134 Standard_Real Geom2dAPI_ExtremaCurveCurve::Distance
135   (const Standard_Integer Index) const
136 {
137   Standard_OutOfRange_Raise_if
138     (Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve:Distance");
139
140   return sqrt (myExtCC.SquareDistance(Index));
141 }
142
143
144 //=======================================================================
145 //function : NearestPoints
146 //purpose  : 
147 //=======================================================================
148
149 void Geom2dAPI_ExtremaCurveCurve::NearestPoints
150   (gp_Pnt2d& P1, gp_Pnt2d& P2) const 
151 {
152   StdFail_NotDone_Raise_if
153     ( !myIsDone, "Geom2dAPI_ExtremaCurveCurve:NearestPoints");
154
155   Points(myIndex,P1,P2);
156 }
157
158
159 //=======================================================================
160 //function : LowerDistanceParameters
161 //purpose  : 
162 //=======================================================================
163
164 void Geom2dAPI_ExtremaCurveCurve::LowerDistanceParameters
165   (Standard_Real& U1,
166    Standard_Real& U2) const 
167 {
168   StdFail_NotDone_Raise_if
169     ( !myIsDone, "Geom2dAPI_ExtremaCurveCurve:LowerDistanceParameters");
170
171   Parameters(myIndex,U1,U2);
172 }
173
174
175 //=======================================================================
176 //function : LowerDistance
177 //purpose  : 
178 //=======================================================================
179
180 Standard_Real Geom2dAPI_ExtremaCurveCurve::LowerDistance() const
181 {
182   StdFail_NotDone_Raise_if
183     (!myIsDone, "Geom2dAPI_ExtremaCurveCurve:LowerDistance");
184
185   return sqrt (myExtCC.SquareDistance(myIndex));
186 }
187
188
189 //=======================================================================
190 //function : Standard_Real
191 //purpose  : 
192 //=======================================================================
193
194 Geom2dAPI_ExtremaCurveCurve::operator Standard_Real() const
195 {
196   return LowerDistance();
197 }
198
199
200 //=======================================================================
201 //function : Standard_Integer
202 //purpose  : 
203 //=======================================================================
204
205 Geom2dAPI_ExtremaCurveCurve::operator Standard_Integer() const
206 {
207   return myExtCC.NbExt();
208 }