Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopTrans / TopTrans_CurveTransition.cxx
CommitLineData
7fd59977 1// File: TopTrans_CurveTransition.cxx
2// Created: Thu Jan 23 18:57:37 1992
3// Author: Didier PIFFAULT
4// <dpf@sdsun1>
5// Copyright: Matra Datavision 1992
6
7#include <TopTrans_CurveTransition.ixx>
8#include <TopAbs.hxx>
9
10#define GREATER 1
11#define SAME 0
12#define LOWER -1
13
14//=======================================================================
15//function : TopTrans_CurveTransition
16//purpose : Empty Constructor.
17//=======================================================================
18
19TopTrans_CurveTransition::TopTrans_CurveTransition ()
20{
21}
22
23//=======================================================================
24//function : Reset
25//purpose : Initializer for a complex curve transition with the elements
26// of the intersecting curve.
27//=======================================================================
28
29void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt,
30 const gp_Dir& Norm,
31 const Standard_Real Curv)
32{
33 myTgt=Tgt; myNorm=Norm; myCurv=Curv; Init=Standard_True;
34}
35
36//=======================================================================
37//function : Reset
38//purpose : Initializer for a complex curve transition with the elements
39// of the intersecting straight line.
40//=======================================================================
41
42void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt)
43{
44 myTgt=Tgt; myCurv=0.; Init=Standard_True;
45}
46
47//=======================================================================
48//function : Compare
49//purpose : Compare the elements of an interference on an intersected
50// curve with the interference stored in the complex Transition.
51//=======================================================================
52
53void TopTrans_CurveTransition::Compare (const Standard_Real Tole,
54 const gp_Dir& T,
55 const gp_Dir& N,
56 const Standard_Real C,
57 const TopAbs_Orientation St,
58 const TopAbs_Orientation Or)
59{
60 // S is the transition, how the curve cross the boundary
61 // O is the orientation, how the intersection is set on the boundary
62 TopAbs_Orientation S = St;
63 TopAbs_Orientation O = Or;
64
65 // adjustment for INTERNAL transition
66 if (S == TopAbs_INTERNAL) {
67 if (T * myTgt < 0)
68 S = TopAbs::Reverse(O);
69 else
70 S = O;
71 }
72
73 // It is the first comparaison for this complex transition
74 if (Init) {
75 Init=Standard_False;
76 TgtFirst =T;
77 NormFirst=N;
78 CurvFirst=C;
79 TranFirst=S;
80 TgtLast =T;
81 NormLast =N;
82 CurvLast =C;
83 TranLast =S;
84 switch (O) {
85 // Interference en fin d'arete il faut inverser la tangente
86 case TopAbs_REVERSED :
87 TgtFirst.Reverse();
88 TgtLast.Reverse();
89 break;
90 case TopAbs_INTERNAL :
91 // Interference en milieu d'arete il faut inverser en fonction de la
92 // position de la tangente de reference
93 if (myTgt*T>0) TgtFirst.Reverse();
94 else TgtLast.Reverse();
95 break;
96 case TopAbs_FORWARD :
97 case TopAbs_EXTERNAL :
98 break;
99 }
100 }
101
102 // Compare with the existent first and last transition :
103 else {
104 Standard_Boolean FirstSet=Standard_False;
105 Standard_Real cosAngWithT=myTgt*T;
106 switch (O) {
107 case TopAbs_REVERSED :
108 cosAngWithT= -cosAngWithT;
109 break;
110 case TopAbs_INTERNAL :
111 if (cosAngWithT>0) cosAngWithT=-cosAngWithT;
112 break;
113 case TopAbs_FORWARD :
114 case TopAbs_EXTERNAL :
115 break;
116 }
117 Standard_Real cosAngWith1=myTgt*TgtFirst;
118
119 switch (Compare(cosAngWithT, cosAngWith1, Tole)) {
120
121 case LOWER :
122 // If the angle is greater than the first the new become the first
123 FirstSet=Standard_True;
124 TgtFirst =T;
125 switch (O) {
126 case TopAbs_REVERSED :
127 TgtFirst.Reverse();
128 break;
129 case TopAbs_INTERNAL :
130 if (myTgt*T>0) TgtFirst.Reverse();
131 break;
132 case TopAbs_FORWARD :
133 case TopAbs_EXTERNAL :
134 break;
135 }
136 NormFirst=N;
137 CurvFirst=C;
138 TranFirst=S;
139 break;
140
141 case SAME :
142 // If same angles we look at the Curvature
143 if (IsBefore(Tole, cosAngWithT, N, C, NormFirst, CurvFirst)) {
144 FirstSet=Standard_True;
145 TgtFirst =T;
146 switch (O) {
147 case TopAbs_REVERSED :
148 TgtFirst.Reverse();
149 break;
150 case TopAbs_INTERNAL :
151 if (myTgt*T>0) TgtFirst.Reverse();
152 break;
153 case TopAbs_FORWARD :
154 case TopAbs_EXTERNAL :
155 break;
156 }
157 NormFirst=N;
158 CurvFirst=C;
159 TranFirst=S;
160 }
161 break;
162
163 case GREATER:
164 break;
165 }
166
167 if (!FirstSet || O==TopAbs_INTERNAL) {
168 // Dans les cas de tangence le premier peut etre aussi le dernier
169 if (O==TopAbs_INTERNAL) cosAngWithT=-cosAngWithT;
170 Standard_Real cosAngWith2=myTgt*TgtLast;
171
172 switch (Compare(cosAngWithT, cosAngWith2, Tole)) {
173
174 case GREATER:
175 // If the angle is lower than the last the new become the last
176 TgtLast =T;
177 switch (O) {
178 case TopAbs_REVERSED :
179 TgtLast.Reverse();
180 break;
181 case TopAbs_INTERNAL :
182 if (myTgt*T<0) TgtLast.Reverse();
183 break;
184 case TopAbs_FORWARD :
185 case TopAbs_EXTERNAL :
186 break;
187 }
188 NormLast =N;
189 CurvLast =C;
190 TranLast =S;
191 break;
192
193 case SAME:
194 // If the angle is the same we look at the curvature
195 if (IsBefore(Tole, cosAngWithT, NormLast, CurvLast, N, C)) {
196 TgtLast =T;
197 switch (O) {
198 case TopAbs_REVERSED :
199 TgtLast.Reverse();
200 break;
201 case TopAbs_INTERNAL :
202 if (myTgt*T<0) TgtLast.Reverse();
203 break;
204 case TopAbs_FORWARD :
205 case TopAbs_EXTERNAL :
206 break;
207 }
208 NormLast=N;
209 CurvLast=C;
210 TranLast=S;
211 }
212 }
213 }
214 }
215}
216
217//=======================================================================
218//function : StateBefore
219//purpose : Give the state of the curv before the interference.
220//=======================================================================
221
222TopAbs_State TopTrans_CurveTransition::StateBefore () const
223{
224 if (Init) return TopAbs_UNKNOWN;
225 switch (TranFirst)
226 {
227 case TopAbs_FORWARD :
228 case TopAbs_EXTERNAL :
229 return TopAbs_OUT;
230 case TopAbs_REVERSED :
231 case TopAbs_INTERNAL :
232 return TopAbs_IN;
233 }
234 return TopAbs_OUT;
235}
236
237//=======================================================================
238//function : StateAfter
239//purpose : give the state of the curve after the interference.
240//=======================================================================
241
242TopAbs_State TopTrans_CurveTransition::StateAfter () const
243{
244 if (Init) return TopAbs_UNKNOWN;
245 switch (TranLast)
246 {
247 case TopAbs_FORWARD :
248 case TopAbs_INTERNAL :
249 return TopAbs_IN;
250 case TopAbs_REVERSED :
251 case TopAbs_EXTERNAL :
252 return TopAbs_OUT;
253 }
254 return TopAbs_OUT;
255}
256
257
258//=======================================================================
259//function : IsBefore
260//purpose : Compare the curvature of the two transition and return true
261// if T1 is before T2
262//=======================================================================
263
264Standard_Boolean TopTrans_CurveTransition::IsBefore
265 (const Standard_Real Tole,
266 const Standard_Real CosAngl,
267 const gp_Dir& N1,
268 const Standard_Real C1,
269 const gp_Dir& N2,
270 const Standard_Real C2) const
271{
272 Standard_Real TN1=myTgt*N1;
273 Standard_Real TN2=myTgt*N2;
274 Standard_Boolean OneBefore=Standard_False;
275
276 if (Abs(TN1)<=Tole || Abs(TN2)<=Tole) {
277 // Tangent : The first is the interference which have the nearest curvature
278 // from the reference.
279 if (myCurv==0) {
280 // The reference is straight
281 // The first is the interference which have the lowest curvature.
282 if (C1<C2) OneBefore=Standard_True;
283// Modified by Sergey KHROMOV - Wed Dec 27 17:08:49 2000 Begin
284 if (CosAngl>0)
285 OneBefore=!OneBefore;
286// Modified by Sergey KHROMOV - Wed Dec 27 17:08:50 2000 End
287 }
288 else {
289 // The reference is curv
290 // The first is the interference which have the nearest curvature
291 // in the direction
292 Standard_Real deltaC1, deltaC2;
293 if (C1==0. || myCurv==0.) {
294 deltaC1=C1-myCurv;
295 }
296 else {
297 deltaC1=(C1-myCurv)*(N1*myNorm);
298 }
299 if (C2==0. || myCurv==0.) {
300 deltaC2=C2-myCurv;
301 }
302 else {
303 deltaC2=(C2-myCurv)*(N2*myNorm);
304 }
305 if (deltaC1 < deltaC2) OneBefore=Standard_True;
306 if (CosAngl>0) OneBefore=!OneBefore;
307 }
308 }
309 else if (TN1<0) {
310 // Before the first interference we are in the curvature
311 if (TN2>0) {
312 // Before the second interference we are out the curvature
313 // The first interference is before /* ->)( */
314 OneBefore=Standard_True;
315 }
316 else {
317 // Before the second interference we are in the curvature
318 if (C1>C2) {
319 // We choice the greater curvature
320 // The first interference is before /* ->)) */
321 OneBefore=Standard_True;
322 }
323 }
324 }
325 else if (TN1>0) {
326 // Before the first interference we are out the curvature
327 if (TN2>0) {
328 // Before the second interference we are out the curvature /* ->(( */
329 if (C1<C2) {
330 // We choice the lower curvature
331 // The first interference is before
332 OneBefore=Standard_True;
333 }
334 }
335 }
336 return OneBefore;
337}
338
339
340//=======================================================================
341//function : Compare
342//purpose : Compare two angles
343//=======================================================================
344
345Standard_Integer TopTrans_CurveTransition::Compare(const Standard_Real Ang1,
346 const Standard_Real Ang2,
347 const Standard_Real Tole) const
348{
349 Standard_Integer res=SAME;
350 if (Ang1 - Ang2 > Tole) res=GREATER;
351 else if (Ang2 - Ang1 > Tole) res=LOWER;
352
353 return res;
354}