0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / IntRes2d / IntRes2d_Intersection.cxx
CommitLineData
7fd59977 1// File: IntRes2d_Intersection.cxx
2// Created: Tue Apr 28 10:21:36 1992
3// Author: Laurent BUCHARD
4// <lbr@topsn3>
5
6
7#include <IntRes2d_Intersection.ixx>
8
9#include <StdFail_NotDone.hxx>
10#include <Standard_OutOfRange.hxx>
11#include <IntRes2d_SequenceOfIntersectionPoint.hxx>
12#include <IntRes2d_SequenceOfIntersectionSegment.hxx>
13#include <IntRes2d_Position.hxx>
14
15
16#define PARAMEQUAL(a,b) (Abs((a)-(b))< (1e-8))
17
18
19static void InternalVerifyPosition(IntRes2d_Transition& T1,
20 IntRes2d_Transition& T2,
21 const Standard_Real PParamOnFirst,
22 const Standard_Real PParamOnSecond,
23 const Standard_Real FirstParam1,
24 const Standard_Real LastParam1,
25 const Standard_Real FirstParam2,
26 const Standard_Real LastParam2);
27
28
29
30//----------------------------------------------------------------------
31static Standard_Boolean TransitionEqual( const IntRes2d_Transition& T1
32 ,const IntRes2d_Transition& T2);
33
34
35Standard_Boolean TransitionEqual( const IntRes2d_Transition& T1
36 ,const IntRes2d_Transition& T2) {
37
38 if(T1.PositionOnCurve() == T2.PositionOnCurve()) {
39 if(T1.TransitionType() == T2.TransitionType()) {
40 if(T1.TransitionType() == IntRes2d_Touch) {
41 if(T1.IsTangent()==T2.IsTangent()) {
42 if(T1.Situation() == T2.Situation()) {
43 if(T1.IsOpposite() == T2.IsOpposite()) {
44 return(Standard_True);
45 }
46 }
47 }
48 }
49 else {
50 return(Standard_True);
51 }
52 }
53 }
54 return(Standard_False);
55}
56
57
58
59void IntRes2d_Intersection::Insert(const IntRes2d_IntersectionPoint& Pnt) {
60 Standard_Integer n = lpnt.Length();
61 if(n==0) {
62 lpnt.Append(Pnt);
63 }
64 else {
65 Standard_Real u = Pnt.ParamOnFirst();
66 Standard_Integer i = 1;
67 Standard_Integer b = n+1;
68 while(i<=n) {
69 const IntRes2d_IntersectionPoint& Pnti=lpnt(i);
70 Standard_Real ui = Pnti.ParamOnFirst();
71 if(ui >= u) { b=i; i=n; }
72 if(PARAMEQUAL(ui,u)) {
73 if(PARAMEQUAL((Pnt.ParamOnSecond()),(Pnti.ParamOnSecond()))) {
74 if( (TransitionEqual(Pnt.TransitionOfFirst(),Pnti.TransitionOfFirst()))
75 && (TransitionEqual(Pnt.TransitionOfSecond(),Pnti.TransitionOfSecond()))) {
76 b=0;
77 i=n;
78 }
79 }
80 }
81 //----------------------------------------------------------------
82
83 i++;
84 }
85 if(b>n) { lpnt.Append(Pnt); }
86 else if(b>0) { lpnt.InsertBefore(b,Pnt); }
87 }
88}
89
90void IntRes2d_Intersection::SetValues(const IntRes2d_Intersection& Other) {
91 Standard_Integer i ;
92 if(Other.done) {
93 lseg.Clear();
94 lpnt.Clear();
95 Standard_Integer N = Other.lpnt.Length();
96 for( i=1; i<= N ; i++) {
97 lpnt.Append(Other.lpnt(i));
98 }
99 N = Other.lseg.Length();
100 for(i=1; i<= N ; i++) {
101 lseg.Append(Other.lseg(i));
102 }
103 //-----------------------
104 //lpnt=Other.lpnt; Pose des problemes
105 //lseg=Other.lseg; pour des objets composites
106 //-----------------------
107 done=Standard_True;
108 }
109 else {
110 done=Standard_False;
111 }
112}
113
114//----------------------------------------------------------------------
115//-- Function used to Merge the results of two Intersections .
116//-- for Composite Curves only. FirstParam and LastParam are the
117//-- parameter of the bounds of the composite Curve
118//-- Merge of two Intersection Segments S1 and S2 when :
119//--
120//-- S1 : U1First,PosU1Fisrt --> U1Last,PosU1Last
121//-- V1First,PosV1Fisrt --> V1Last,PosV1Last
122//-- S2 : U2First,PosU2Fisrt --> U2Last,PosU2Last
123//-- V2First,PosV2Fisrt --> V2Last,PosV2Last
124//--
125//-- 1 U : X------1-------E H-----2-------X U -->
126//-- V : X------1-------X X-----2-------X <- V -> ?
127//--
128//-- PosU1Last == End && PosU2First == Head
129//-- && U1Last == U2First
130//-- && V1Last == V2First
131//--
132//-- OR
133//--
134//-- 2 U : X------1-------H E-----2-------X U <--
135//-- V : X------1-------X X-----2-------X <- V -> ?
136//--
137//-- PosU1Last == Head && PosU2First == End
138//-- && U1Last == U2First
139//-- && V1Last == V2First
140//--
141//-- merge the two Segment in :
142//--
143//-- U : X------1----------2-------X U
144//-- V : X------1----------2-------X <- V -> ?
145//--
146//--
147//--
148//-- The Position of Intersection Point is set to Middle
149//-- when the Parameters U et V are between FirstParam1, EndParam1
150//-- and FirstParam2, EndParam2
151//--
152void IntRes2d_Intersection::Append( const IntRes2d_Intersection& Other
153 ,const Standard_Real FirstParam1
154 ,const Standard_Real LastParam1
155 ,const Standard_Real FirstParam2
156 ,const Standard_Real LastParam2) {
157
158
159 if(Other.done) {
160 //-- Verification of the Position of the IntersectionPoints
161 Standard_Integer n=Other.lpnt.Length();
162 Standard_Integer i ;
163 for( i=1; i<=n ; i++) {
164
165 const IntRes2d_IntersectionPoint& P=Other.lpnt(i);
166 Standard_Real PParamOnFirst=P.ParamOnFirst();
167 Standard_Real PParamOnSecond=P.ParamOnSecond();
168 IntRes2d_Transition T1=P.TransitionOfFirst();
169 IntRes2d_Transition T2=P.TransitionOfSecond();
170 gp_Pnt2d Pt=P.Value();
171
172
173 InternalVerifyPosition(T1,T2
174 ,PParamOnFirst,PParamOnSecond
175 ,FirstParam1,LastParam1
176 ,FirstParam2,LastParam2);
177
178 this->Insert(IntRes2d_IntersectionPoint(Pt,
179 PParamOnFirst,
180 PParamOnSecond,
181 T1,T2,
182 Standard_False));
183 }
184
185 //--------------------------------------------------
186 //-- IntersectionSegment
187 //-- (we assume that a composite curve is always bounded)
188 //-- (a segment has always a FirstPoint and a LastPoint)
189 //--------------------------------------------------
190 n=Other.lseg.Length();
191 Standard_Real SegModif_P1First=0,SegModif_P1Second=0;
192 Standard_Real SegModif_P2First=0,SegModif_P2Second=0;
193
194 for(i=1; i<=n ; i++) {
195
196 const IntRes2d_IntersectionPoint& P1=Other.lseg(i).FirstPoint();
197
198 Standard_Real P1PParamOnFirst=P1.ParamOnFirst();
199 Standard_Real P1PParamOnSecond=P1.ParamOnSecond();
200 IntRes2d_Transition P1T1=P1.TransitionOfFirst();
201 IntRes2d_Transition P1T2=P1.TransitionOfSecond();
202 const gp_Pnt2d& P1Pt=P1.Value();
203
204 InternalVerifyPosition(P1T1,P1T2
205 ,P1PParamOnFirst,P1PParamOnSecond
206 ,FirstParam1,LastParam1
207 ,FirstParam2,LastParam2);
208
209 const IntRes2d_IntersectionPoint& P2=Other.lseg(i).LastPoint();
210
211 Standard_Real P2PParamOnFirst=P2.ParamOnFirst();
212 Standard_Real P2PParamOnSecond=P2.ParamOnSecond();
213 IntRes2d_Transition P2T1=P2.TransitionOfFirst();
214 IntRes2d_Transition P2T2=P2.TransitionOfSecond();
215 const gp_Pnt2d& P2Pt=P2.Value();
216
217 Standard_Boolean Opposite=Other.lseg(i).IsOpposite();
218
219 InternalVerifyPosition(P2T1,P2T2
220 ,P2PParamOnFirst,P2PParamOnSecond
221 ,FirstParam1,LastParam1
222 ,FirstParam2,LastParam2);
223
224
225
226 //-- Loop on the previous segments
227 //--
228 Standard_Integer an=lseg.Length();
229 Standard_Boolean NotYetModified=Standard_True;
230
231 for(Standard_Integer j=1;(j<=an)&&(NotYetModified);j++) {
232
233 const IntRes2d_IntersectionPoint& AnP1=lseg(j).FirstPoint();
234 Standard_Real AnP1PParamOnFirst=AnP1.ParamOnFirst();
235 Standard_Real AnP1PParamOnSecond=AnP1.ParamOnSecond();
7fd59977 236
237 const IntRes2d_IntersectionPoint& AnP2=lseg(j).LastPoint();
238 Standard_Real AnP2PParamOnFirst=AnP2.ParamOnFirst();
239 Standard_Real AnP2PParamOnSecond=AnP2.ParamOnSecond();
7fd59977 240
241 if(Opposite == lseg(j).IsOpposite()) {
242 //---------------------------------------------------------------
243 //-- AnP1---------AnP2
244 //-- P1-------------P2
245 //--
246 if( PARAMEQUAL(P1PParamOnFirst,AnP2PParamOnFirst)
247 &&PARAMEQUAL(P1PParamOnSecond,AnP2PParamOnSecond)) {
248 NotYetModified=Standard_False;
249 lseg(j)=IntRes2d_IntersectionSegment(AnP1,P2,
250 Opposite,Standard_False);
251 SegModif_P1First = AnP1PParamOnFirst;
252 SegModif_P1Second = AnP1PParamOnSecond;
253 SegModif_P2First = P2PParamOnFirst;
254 SegModif_P2Second = P2PParamOnSecond;
255 }
256 //---------------------------------------------------------------
257 //-- AnP1---------AnP2
258 //-- P1-------------P2
259 //--
260 else if( PARAMEQUAL(P2PParamOnFirst,AnP1PParamOnFirst)
261 &&PARAMEQUAL(P2PParamOnSecond,AnP1PParamOnSecond)) {
262 NotYetModified=Standard_False;
263 lseg(j)=IntRes2d_IntersectionSegment(P1,AnP2,
264 Opposite,Standard_False);
265 SegModif_P1First = P1PParamOnFirst;
266 SegModif_P1Second = P1PParamOnSecond;
267 SegModif_P2First = AnP2PParamOnFirst;
268 SegModif_P2Second = AnP2PParamOnSecond;
269 }
270 //---------------------------------------------------------------
271 //-- AnP2---------AnP1
272 //-- P1-------------P2
273 //--
274 if( PARAMEQUAL(P1PParamOnFirst,AnP1PParamOnFirst)
275 &&PARAMEQUAL(P1PParamOnSecond,AnP1PParamOnSecond)) {
276 NotYetModified=Standard_False;
277 lseg(j)=IntRes2d_IntersectionSegment(AnP2,P2,
278 Opposite,Standard_False);
279 SegModif_P1First = P2PParamOnFirst;
280 SegModif_P1Second = P2PParamOnSecond;
281 SegModif_P2First = AnP2PParamOnFirst;
282 SegModif_P2Second = AnP2PParamOnSecond;
283 }
284 //---------------------------------------------------------------
285 //-- AnP2---------AnP1
286 //-- P1-------------P2
287 //--
288 else if( PARAMEQUAL(P2PParamOnFirst,AnP2PParamOnFirst)
289 &&PARAMEQUAL(P2PParamOnSecond,AnP2PParamOnSecond)) {
290 NotYetModified=Standard_False;
291 lseg(j)=IntRes2d_IntersectionSegment(P1,AnP1,
292 Opposite,Standard_False);
293 SegModif_P1First = P1PParamOnFirst;
294 SegModif_P1Second = P1PParamOnSecond;
295 SegModif_P2First = AnP1PParamOnFirst;
296 SegModif_P2Second = AnP1PParamOnSecond;
297 }
298 }
299 }
300 if(NotYetModified) {
301 this->Append(IntRes2d_IntersectionSegment(
302 IntRes2d_IntersectionPoint(P1Pt,
303 P1PParamOnFirst,
304 P1PParamOnSecond,
305 P1T1,P1T2,
306 Standard_False),
307 IntRes2d_IntersectionPoint(P2Pt,
308 P2PParamOnFirst,
309 P2PParamOnSecond,
310 P2T1,P2T2,
311 Standard_False),
312 Opposite,Standard_False));
313
314 } //-- if(NotYetModified)
315 else {
316 //--------------------------------------------------------------
317 //-- Are some Existing Points in this segment ?
318 //--------------------------------------------------------------
319 Standard_Integer rnbpts=lpnt.Length();
320 for(Standard_Integer rp=1; (rp<=rnbpts)&&(rp>=1); rp++) {
321 Standard_Real PonFirst=lpnt(rp).ParamOnFirst();
322 Standard_Real PonSecond=lpnt(rp).ParamOnSecond();
323
324 if( ((PonFirst >= SegModif_P1First && PonFirst <= SegModif_P2First)
325 ||(PonFirst <= SegModif_P1First && PonFirst >= SegModif_P2First))
326 && ((PonSecond >= SegModif_P1Second && PonSecond <= SegModif_P2Second)
327 ||(PonSecond<= SegModif_P1Second && PonSecond >= SegModif_P2Second))) {
328 lpnt.Remove(rp);
329 rp--;
330 rnbpts--;
331 }
332 } //-- for(Standard_Integer rp=1; (rp<=rnbpts)&&(rp>=1); rp++)
333 }
334 }
335 //--------------------------------------------------
336 //-- Remove some Points ?
337 //-- Example : Points which lie in a segment.
338 //--------------------------------------------------
339
340 done=Standard_True;
341 }
342 else {
343 done=Standard_False;
344 }
345}
346
347
348//----------------------------------------------------------------------
349//--
350#define DEBUGPOSITION 0
351
352#if DEBUGPOSITION
353void AffPosition(IntRes2d_Transition& T,const Standard_Real u,const char *Texte);
354void AffPosition(IntRes2d_Transition& T,const Standard_Real u,const char *Texte) {
355 if(T.PositionOnCurve() == IntRes2d_End) { cout <<Texte<<" Param :"<<u<<" End "<<endl; }
356 if(T.PositionOnCurve() == IntRes2d_Middle) { cout <<Texte<<" Param :"<<u<<" Middle "<<endl; }
357 if(T.PositionOnCurve() == IntRes2d_Head) { cout <<Texte<<" Param :"<<u<<" Head "<<endl; }
358}
359#endif
360
361void InternalVerifyPosition(IntRes2d_Transition& T1,
362 IntRes2d_Transition& T2,
363 const Standard_Real PParamOnFirst,
364 const Standard_Real PParamOnSecond,
365 const Standard_Real FirstParam1,
366 const Standard_Real LastParam1,
367 const Standard_Real FirstParam2,
368 const Standard_Real LastParam2) {
369#if DEBUGPOSITION
370AffPosition(T1,PParamOnFirst," Point 1 ");
371AffPosition(T2,PParamOnSecond," Point 2 ");
372#endif
373 if(T1.PositionOnCurve() != IntRes2d_Middle) {
374 if(!( PARAMEQUAL(PParamOnFirst,FirstParam1)
375 || PARAMEQUAL(PParamOnFirst,LastParam1))) {
376 //-- Middle on the Curve 1
377
378 // modified by NIZHNY-MKK Tue Nov 26 14:23:24 2002.BEGIN
379 if((PParamOnFirst > FirstParam1) && (PParamOnFirst < LastParam1))
380 // modified by NIZHNY-MKK Tue Nov 26 14:23:27 2002.END
381 T1.SetPosition(IntRes2d_Middle);
382 }
383 }
384 if(T2.PositionOnCurve() != IntRes2d_Middle) {
385 if(!( PARAMEQUAL(PParamOnSecond,FirstParam2)
386 || PARAMEQUAL(PParamOnSecond,LastParam2))) {
387
388 // modified by NIZHNY-MKK Tue Nov 26 14:24:15 2002.BEGIN
389 if((PParamOnSecond > FirstParam2) && (PParamOnSecond < LastParam2))
390 // modified by NIZHNY-MKK Tue Nov 26 14:24:19 2002.END
391 T2.SetPosition(IntRes2d_Middle);
392 }
393 }
394}
395//----------------------------------------------------------------------
396
397
398
399
400
401
402
403#if 0
404~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
405#define Debug(q) cout<<"IntRes2d_Intersection"<<"q ="<<q<<endl;
406
407char *DebugPos(const IntRes2d_Position P);
408
409Debug(FirstParam1);
410Debug(LastParam1);
411Debug(FirstParam2);
412Debug(LastParam2);
413Debug(PParamOnFirst);
414Debug(PParamOnSecond);
415cout<<" ##### T1 <> Middle ###### "<<DebugPos(T1.PositionOnCurve())<<endl;
416char *DebugPos(const IntRes2d_Position P) {
417 if(P==IntRes2d_Middle) return(" Middle ");
418 if(P==IntRes2d_Head) return(" Head ");
419 if(P==IntRes2d_End) return(" End ");
420}
421~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
422#endif
423