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