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
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.
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.
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.
22 #include <TopTrans_CurveTransition.ixx>
29 //=======================================================================
30 //function : TopTrans_CurveTransition
31 //purpose : Empty Constructor.
32 //=======================================================================
34 TopTrans_CurveTransition::TopTrans_CurveTransition ()
38 //=======================================================================
40 //purpose : Initializer for a complex curve transition with the elements
41 // of the intersecting curve.
42 //=======================================================================
44 void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt,
46 const Standard_Real Curv)
48 myTgt=Tgt; myNorm=Norm; myCurv=Curv; Init=Standard_True;
51 //=======================================================================
53 //purpose : Initializer for a complex curve transition with the elements
54 // of the intersecting straight line.
55 //=======================================================================
57 void TopTrans_CurveTransition::Reset (const gp_Dir& Tgt)
59 myTgt=Tgt; myCurv=0.; Init=Standard_True;
62 //=======================================================================
64 //purpose : Compare the elements of an interference on an intersected
65 // curve with the interference stored in the complex Transition.
66 //=======================================================================
68 void TopTrans_CurveTransition::Compare (const Standard_Real Tole,
71 const Standard_Real C,
72 const TopAbs_Orientation St,
73 const TopAbs_Orientation Or)
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;
80 // adjustment for INTERNAL transition
81 if (S == TopAbs_INTERNAL) {
83 S = TopAbs::Reverse(O);
88 // It is the first comparaison for this complex transition
100 // Interference en fin d'arete il faut inverser la tangente
101 case TopAbs_REVERSED :
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();
111 case TopAbs_FORWARD :
112 case TopAbs_EXTERNAL :
117 // Compare with the existent first and last transition :
119 Standard_Boolean FirstSet=Standard_False;
120 Standard_Real cosAngWithT=myTgt*T;
122 case TopAbs_REVERSED :
123 cosAngWithT= -cosAngWithT;
125 case TopAbs_INTERNAL :
126 if (cosAngWithT>0) cosAngWithT=-cosAngWithT;
128 case TopAbs_FORWARD :
129 case TopAbs_EXTERNAL :
132 Standard_Real cosAngWith1=myTgt*TgtFirst;
134 switch (Compare(cosAngWithT, cosAngWith1, Tole)) {
137 // If the angle is greater than the first the new become the first
138 FirstSet=Standard_True;
141 case TopAbs_REVERSED :
144 case TopAbs_INTERNAL :
145 if (myTgt*T>0) TgtFirst.Reverse();
147 case TopAbs_FORWARD :
148 case TopAbs_EXTERNAL :
157 // If same angles we look at the Curvature
158 if (IsBefore(Tole, cosAngWithT, N, C, NormFirst, CurvFirst)) {
159 FirstSet=Standard_True;
162 case TopAbs_REVERSED :
165 case TopAbs_INTERNAL :
166 if (myTgt*T>0) TgtFirst.Reverse();
168 case TopAbs_FORWARD :
169 case TopAbs_EXTERNAL :
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;
187 switch (Compare(cosAngWithT, cosAngWith2, Tole)) {
190 // If the angle is lower than the last the new become the last
193 case TopAbs_REVERSED :
196 case TopAbs_INTERNAL :
197 if (myTgt*T<0) TgtLast.Reverse();
199 case TopAbs_FORWARD :
200 case TopAbs_EXTERNAL :
209 // If the angle is the same we look at the curvature
210 if (IsBefore(Tole, cosAngWithT, NormLast, CurvLast, N, C)) {
213 case TopAbs_REVERSED :
216 case TopAbs_INTERNAL :
217 if (myTgt*T<0) TgtLast.Reverse();
219 case TopAbs_FORWARD :
220 case TopAbs_EXTERNAL :
232 //=======================================================================
233 //function : StateBefore
234 //purpose : Give the state of the curv before the interference.
235 //=======================================================================
237 TopAbs_State TopTrans_CurveTransition::StateBefore () const
239 if (Init) return TopAbs_UNKNOWN;
242 case TopAbs_FORWARD :
243 case TopAbs_EXTERNAL :
245 case TopAbs_REVERSED :
246 case TopAbs_INTERNAL :
252 //=======================================================================
253 //function : StateAfter
254 //purpose : give the state of the curve after the interference.
255 //=======================================================================
257 TopAbs_State TopTrans_CurveTransition::StateAfter () const
259 if (Init) return TopAbs_UNKNOWN;
262 case TopAbs_FORWARD :
263 case TopAbs_INTERNAL :
265 case TopAbs_REVERSED :
266 case TopAbs_EXTERNAL :
273 //=======================================================================
274 //function : IsBefore
275 //purpose : Compare the curvature of the two transition and return true
276 // if T1 is before T2
277 //=======================================================================
279 Standard_Boolean TopTrans_CurveTransition::IsBefore
280 (const Standard_Real Tole,
281 const Standard_Real CosAngl,
283 const Standard_Real C1,
285 const Standard_Real C2) const
287 Standard_Real TN1=myTgt*N1;
288 Standard_Real TN2=myTgt*N2;
289 Standard_Boolean OneBefore=Standard_False;
291 if (Abs(TN1)<=Tole || Abs(TN2)<=Tole) {
292 // Tangent : The first is the interference which have the nearest curvature
293 // from the reference.
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
300 OneBefore=!OneBefore;
301 // Modified by Sergey KHROMOV - Wed Dec 27 17:08:50 2000 End
304 // The reference is curv
305 // The first is the interference which have the nearest curvature
307 Standard_Real deltaC1, deltaC2;
308 if (C1==0. || myCurv==0.) {
312 deltaC1=(C1-myCurv)*(N1*myNorm);
314 if (C2==0. || myCurv==0.) {
318 deltaC2=(C2-myCurv)*(N2*myNorm);
320 if (deltaC1 < deltaC2) OneBefore=Standard_True;
321 if (CosAngl>0) OneBefore=!OneBefore;
325 // Before the first interference we are in the curvature
327 // Before the second interference we are out the curvature
328 // The first interference is before /* ->)( */
329 OneBefore=Standard_True;
332 // Before the second interference we are in the curvature
334 // We choice the greater curvature
335 // The first interference is before /* ->)) */
336 OneBefore=Standard_True;
341 // Before the first interference we are out the curvature
343 // Before the second interference we are out the curvature /* ->(( */
345 // We choice the lower curvature
346 // The first interference is before
347 OneBefore=Standard_True;
355 //=======================================================================
357 //purpose : Compare two angles
358 //=======================================================================
360 Standard_Integer TopTrans_CurveTransition::Compare(const Standard_Real Ang1,
361 const Standard_Real Ang2,
362 const Standard_Real Tole) const
364 Standard_Integer res=SAME;
365 if (Ang1 - Ang2 > Tole) res=GREATER;
366 else if (Ang2 - Ang1 > Tole) res=LOWER;