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