0024168: Eliminate CLang compiler warning -Wunused-variable
[occt.git] / src / IntImpParGen / IntImpParGen_Tool.cxx
1 // Created on: 1992-06-10
2 // Created by: Laurent BUCHARD
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
21
22 #include <IntImpParGen_Tool.hxx>
23 #include <gp.hxx>
24
25
26 #define TOLERANCE_ANGULAIRE 0.00000001
27
28 //----------------------------------------------------------------------
29 Standard_Real NormalizeOnDomain(Standard_Real& Param,const IntRes2d_Domain& TheDomain) {
30   Standard_Real modParam = Param;
31   if(TheDomain.IsClosed()) {
32     Standard_Real Periode,t;
33     TheDomain.EquivalentParameters(t,Periode);
34     Periode-=t;
35     if(TheDomain.HasFirstPoint()) {
36       while(modParam<TheDomain.FirstParameter()) {
37         modParam+=Periode;
38       }
39     }
40     if(TheDomain.HasLastPoint()) {
41       if(modParam>TheDomain.LastParameter()) {
42         modParam-=Periode;
43       }
44     }
45   }
46   return(modParam);
47 }
48 //----------------------------------------------------------------------
49 void Determine_Position(IntRes2d_Position& Pos1,
50                         const IntRes2d_Domain& TheDomain,
51                         const gp_Pnt2d& Pnt1,
52                         const Standard_Real Param1) {
53   
54   Pos1=IntRes2d_Middle;
55
56   if(TheDomain.HasFirstPoint()) { 
57     if(Pnt1.Distance(TheDomain.FirstPoint()) 
58        <= TheDomain.FirstTolerance()) {
59       Pos1=IntRes2d_Head;       
60     }
61   }
62    
63   if(TheDomain.HasLastPoint()) {
64     if(Pnt1.Distance(TheDomain.LastPoint()) 
65        <= TheDomain.LastTolerance()) {
66       if(Pos1==IntRes2d_Head) {
67         if(Abs(Param1-TheDomain.LastParameter())
68            < Abs(Param1-TheDomain.FirstParameter()))
69           Pos1=IntRes2d_End;    
70       }
71       else {
72         Pos1=IntRes2d_End; 
73       }
74     } 
75   }
76 }   
77 //----------------------------------------------------------------------
78 void Determine_Transition(const IntRes2d_Position    Pos1,
79                           gp_Vec2d&                  Tan1,
80                           const gp_Vec2d&            Norm1,
81                           IntRes2d_Transition&       T1,
82                           const IntRes2d_Position    Pos2,
83                           gp_Vec2d&                  Tan2,
84                           const gp_Vec2d&            Norm2,
85                           IntRes2d_Transition&       T2,
86 //                        const Standard_Real        Tolerance_Angulaire) {
87                           const Standard_Real        ) {
88   
89   Standard_Boolean courbure1=Standard_True;
90   Standard_Boolean courbure2=Standard_True;
91   Standard_Boolean decide=Standard_True;
92   if (Tan1.Magnitude()<=gp::Resolution()) {
93     Tan1=Norm1;
94     courbure1=Standard_False;
95     if (Tan1.Magnitude()<=gp::Resolution()) {    // transition undecided
96       decide=Standard_False;
97     }
98   }
99   
100   if (Tan2.Magnitude()<=gp::Resolution()) {
101     Tan2=Norm2;
102     courbure2=Standard_False;
103     if (Tan2.Magnitude()<=gp::Resolution()) {    // transition undecided
104       decide=Standard_False;
105     }
106   }
107   
108   if (!decide) {
109     T1.SetValue(Pos1);
110     T2.SetValue(Pos2);
111   }
112   else {
113     Standard_Real sgn=Tan1.Crossed(Tan2);
114     Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();
115
116     if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) {   // Transition TOUCH #########
117       Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
118       if (!(courbure1||courbure2)) {
119         T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
120         T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
121       }
122       else {
123         gp_Vec2d Norm;
124         Tan1.Normalized();
125         Norm.SetCoord(-Tan1.Y(),Tan1.X());
126         Standard_Real Val1,Val2;
127         if (!courbure1) {
128           Val1=0.0;
129         }
130         else {
131           Val1=Norm.Dot(Norm1);
132         }
133         if (!courbure2) {
134           Val2=0.0;
135         }
136         else {
137           Val2=Norm.Dot(Norm2);
138         }
139         
140         if (Abs(Val1-Val2) <= gp::Resolution()) {
141           T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
142           T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
143         }
144         else if (Val2 > Val1) {
145           T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
146           if (opos) {
147             T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
148           }
149           else {
150             T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
151           }
152         }
153         else {         // Val1 > Val2
154           T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
155           if (opos) {
156             T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
157           }
158           else {
159             T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
160           }
161         }
162       }
163     }
164     else if (sgn<0) {
165       T1.SetValue(Standard_False,Pos1,IntRes2d_In);
166       T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
167     }
168     else {     // sgn>0
169       T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
170       T2.SetValue(Standard_False,Pos2,IntRes2d_In);
171     }
172   }
173 }
174