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