summaryrefslogtreecommitdiff
path: root/src/IntImpParGen/IntImpParGen.cxx
blob: b677b0ffabdcdade027d4b64c846afd186594c40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// File:	IntImpParGen_Tool.hxx
// Created:	Wed Jun 10 15:04:00 1992
// Author:	Laurent BUCHARD
//		<lbr@sdsun2>



#include <IntImpParGen.ixx>
#include <IntRes2d_Domain.hxx>
#include <IntRes2d_Position.hxx>
#include <IntRes2d_Transition.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Pnt2d.hxx>




#include <IntImpParGen_Tool.hxx>
#include <gp.hxx>


#define TOLERANCE_ANGULAIRE     0.00000001
#define DERIVEE_PREMIERE_NULLE  0.000000000001
//----------------------------------------------------------------------
Standard_Real IntImpParGen::NormalizeOnDomain(Standard_Real& Param,
					      const IntRes2d_Domain& TheDomain) {
  Standard_Real modParam = Param;
  if(TheDomain.IsClosed()) {
    Standard_Real Periode,t;
    TheDomain.EquivalentParameters(t,Periode);
    Periode-=t;
    while(   modParam<TheDomain.FirstParameter()
	  && modParam+Periode < TheDomain.LastParameter()) {
      modParam+=Periode;
    }
    while(   modParam>TheDomain.LastParameter()
	  && modParam-Periode > TheDomain.FirstParameter()) {
      modParam-=Periode;
    }
  }  
  return(modParam);
}
//----------------------------------------------------------------------
void IntImpParGen::DeterminePosition(IntRes2d_Position& Pos1,
				     const IntRes2d_Domain& TheDomain,
				     const gp_Pnt2d& Pnt1,
				     const Standard_Real Param1) {
  
  Pos1=IntRes2d_Middle;

  if(TheDomain.HasFirstPoint()) { 
    if(Pnt1.Distance(TheDomain.FirstPoint()) 
       <= TheDomain.FirstTolerance()) {
      Pos1=IntRes2d_Head; 	
    }
  }
   
  if(TheDomain.HasLastPoint()) {
    if(Pnt1.Distance(TheDomain.LastPoint()) 
       <= TheDomain.LastTolerance()) {
      if(Pos1==IntRes2d_Head) {
	if(Abs(Param1-TheDomain.LastParameter())
	   < Abs(Param1-TheDomain.FirstParameter()))
	  Pos1=IntRes2d_End; 	
      }
      else {
	Pos1=IntRes2d_End; 
      }
    } 
  }
}   
//----------------------------------------------------------------------
void IntImpParGen::DetermineTransition(const IntRes2d_Position    Pos1,
				       gp_Vec2d&                  Tan1,
				       const gp_Vec2d&            Norm1,
				       IntRes2d_Transition&       T1,
				       const IntRes2d_Position    Pos2,
				       gp_Vec2d&                  Tan2,
				       const gp_Vec2d&            Norm2,
				       IntRes2d_Transition&       T2,
				       const Standard_Real        ) {
  
  Standard_Boolean courbure1=Standard_True;
  Standard_Boolean courbure2=Standard_True;
  Standard_Boolean decide=Standard_True;
      
  T1.SetPosition(Pos1);
  T2.SetPosition(Pos2);


  if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
    Tan1=Norm1;
    courbure1=Standard_False;
    if (Tan1.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {    // transition undecided
      decide=Standard_False;
    }
  }
  
  if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {
    Tan2=Norm2;
    courbure2=Standard_False;
    if (Tan2.SquareMagnitude()<=DERIVEE_PREMIERE_NULLE) {    // transition undecided
      decide=Standard_False;
    }
  }
  
  if (!decide) {
    T1.SetValue(Pos1);
    T2.SetValue(Pos2);
  }
  else {
    Standard_Real sgn=Tan1.Crossed(Tan2);
    Standard_Real norm=Tan1.Magnitude()*Tan2.Magnitude();

    if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) {   // Transition TOUCH #########
      Standard_Boolean opos=(Tan1.Dot(Tan2))<0;
      if (!(courbure1||courbure2)) {
	T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
	T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
      }
      else {
	gp_Vec2d Norm;
	Tan1.Normalized();
	Norm.SetCoord(-Tan1.Y(),Tan1.X());
	Standard_Real Val1,Val2;
	if (!courbure1) {
	  Val1=0.0;
	}
	else {
	  Val1=Norm.Dot(Norm1);
	}
	if (!courbure2) {
	  Val2=0.0;
	}
	else {
	  Val2=Norm.Dot(Norm2);
	}
	
	if (Abs(Val1-Val2) <= TOLERANCE_ANGULAIRE) {
	  T1.SetValue(Standard_True,Pos1,IntRes2d_Unknown,opos);
	  T2.SetValue(Standard_True,Pos2,IntRes2d_Unknown,opos);
	}
	else if (Val2 > Val1) {
	  T2.SetValue(Standard_True,Pos2,IntRes2d_Inside,opos);
	  if (opos) {
	    T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
	  }
	  else {
	    T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
	  }
	}
	else {         // Val1 > Val2
	  T2.SetValue(Standard_True,Pos2,IntRes2d_Outside,opos);
	  if (opos) {
	    T1.SetValue(Standard_True,Pos1,IntRes2d_Outside,opos);
	  }
	  else {
	    T1.SetValue(Standard_True,Pos1,IntRes2d_Inside,opos);
	  }
	}
      }
    }
    else if (sgn<0) {
      T1.SetValue(Standard_False,Pos1,IntRes2d_In);
      T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
    }
    else {     // sgn>0
      T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
      T2.SetValue(Standard_False,Pos2,IntRes2d_In);
    }
  }
}

//----------------------------------------------------------------------
Standard_Boolean  IntImpParGen::DetermineTransition(const IntRes2d_Position    Pos1,
						    gp_Vec2d&                  Tan1,
						    IntRes2d_Transition&       T1,
						    const IntRes2d_Position    Pos2,
						    gp_Vec2d&                  Tan2,
						    IntRes2d_Transition&       T2,
						    const Standard_Real        ) {

  T1.SetPosition(Pos1);
  T2.SetPosition(Pos2);

  Standard_Real Tan1Magnitude = Tan1.Magnitude();
  if (Tan1Magnitude<=DERIVEE_PREMIERE_NULLE) {
    return(Standard_False);
  }

  Standard_Real Tan2Magnitude = Tan2.Magnitude();  
  if (Tan2Magnitude<=DERIVEE_PREMIERE_NULLE) {
    return(Standard_False);
  }

  Standard_Real sgn=Tan1.Crossed(Tan2);
  Standard_Real norm=Tan1Magnitude*Tan2Magnitude;
  
  if (Abs(sgn)<=TOLERANCE_ANGULAIRE*norm) {   // Transition TOUCH #########
    return(Standard_False);
  }
  else if (sgn<0) {
    T1.SetValue(Standard_False,Pos1,IntRes2d_In);
    T2.SetValue(Standard_False,Pos2,IntRes2d_Out);
  }
  else {     // sgn>0
    T1.SetValue(Standard_False,Pos1,IntRes2d_Out);
    T2.SetValue(Standard_False,Pos2,IntRes2d_In);
  }
  return(Standard_True);
}