summaryrefslogtreecommitdiff
path: root/inc/IntImpParGen_Intersector.gxx
blob: 3094f8d8c9b4f5910481a3e6d3821d86e388f493 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
// File :       IntImpParGen_Intersector.gxx
// Created :    Mon Mar 2 14:00:00 1992
// Author :     Laurent BUCHARD
//                <lbr@phobox>
// Copyright:   Matra Datavision 1992


#include <Standard_ConstructionError.hxx>
#include <IntRes2d_Domain.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntRes2d_IntersectionSegment.hxx>
#include <IntRes2d_SequenceOfIntersectionPoint.hxx>
#include <IntRes2d_SequenceOfIntersectionSegment.hxx>
#include <IntRes2d_Transition.hxx>
#include <IntRes2d_Position.hxx>
 
#include <IntImpParGen.hxx>

#include <math_FunctionSample.hxx>
#include <math_FunctionAllRoots.hxx>

#include <TColStd_Array1OfReal.hxx>
#include <gp.hxx>
#include <gp_Vec2d.hxx>

//======================================================================
#define EPSDIST Tol
#define EPSNUL  TolConf
#define EPSX    ParTool::EpsX(TheParCurve)
#define NB_ECHANTILLONS 

static Standard_Real PIpPI = Standard_PI+Standard_PI;



//======================================================================
void IntImpParGen_Intersector::And_Domaine_Objet1_Intersections(const ImpTool& TheImpTool,
			      const ParCurve& TheParCurve,
			      const IntRes2d_Domain& TheImpCurveDomain,
			      const IntRes2d_Domain& TheParCurveDomain,
			      Standard_Integer& NbResultats,
		      	      TColStd_Array1OfReal& Inter2_And_Domain2,
			      TColStd_Array1OfReal& Inter1,
			      TColStd_Array1OfReal& Resultat1,
		      	      TColStd_Array1OfReal& Resultat2,
			      const Standard_Real EpsNul) const {

  
  Standard_Integer Nb_Bornes_Intersection=NbResultats;
  NbResultats=0;
  
  for(Standard_Integer i=1; i<=Nb_Bornes_Intersection; i+=2) {
    
    Standard_Real param1=Inter1.Value(i);
    Standard_Real param2=Inter1.Value(i+1);

    Standard_Integer indice_1=i;
    Standard_Integer indice_2=i+1;

    if(param1>param2) {
      Standard_Real t=param1; param1=param2; param2=t;
      indice_1=i+1;
      indice_2=i;
    }

    gp_Pnt2d Pt1=TheImpTool.Value(param1);
    gp_Pnt2d Pt2=TheImpTool.Value(param2);
    gp_Pnt2d Pt;

    Standard_Boolean IsOnTheImpCurveDomain1=Standard_True;

    Standard_Boolean IsOnTheImpCurveDomain2=Standard_True;
    //--------------------------------------------------------------------
    if(TheImpCurveDomain.HasFirstPoint()) { 
      if(param1<TheImpCurveDomain.FirstParameter()) {             
	if(Pt1.Distance(TheImpCurveDomain.FirstPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain1=Standard_False; 
	}
      }
    }
    if(IsOnTheImpCurveDomain1 && TheImpCurveDomain.HasLastPoint()) {
      if(param1>TheImpCurveDomain.LastParameter()) {
	if(Pt1.Distance(TheImpCurveDomain.LastPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain1=Standard_False; 
	}
      }
    }
    //--------------------------------------------------------------------
    if(TheImpCurveDomain.HasFirstPoint()) { 
      if(param2<TheImpCurveDomain.FirstParameter()) {             
	if(Pt2.Distance(TheImpCurveDomain.FirstPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain2=Standard_False; 
	}
      }
    }
    if(IsOnTheImpCurveDomain2 && TheImpCurveDomain.HasLastPoint()) {
      if(param2>TheImpCurveDomain.LastParameter()) {
	if(Pt2.Distance(TheImpCurveDomain.LastPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain2=Standard_False; 
	}
      }
    }

    if(IsOnTheImpCurveDomain1) {
      //------------------------------------------------------------------
      //---                 la borne 1 est sur le domaine               --
      NbResultats++;
      Resultat1.SetValue(NbResultats,Inter1.Value(indice_1));
      Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_1));
      //---               la borne2 est aussi sur le domaine           ---
      if(IsOnTheImpCurveDomain2) {
	NbResultats++;
	Resultat1.SetValue(NbResultats,Inter1.Value(indice_2));
	Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_2));
      }
      else {
	//---    Borne1 sur domaine et Borne 2 Hors Domaine           ---
	Standard_Real t;
	NbResultats++;
	t=TheImpCurveDomain.LastParameter();  
	Resultat1.SetValue(NbResultats,t);
//	Standard_Real popResult = FindV(t,Pt,TheImpTool,TheParCurve,
//								  TheParCurveDomain,
//								  Inter2_And_Domain2.Value(indice_1),
//								  Inter2_And_Domain2.Value(indice_2),
//								  EpsNul);
//	
//	Resultat2.SetValue(NbResultats,popResult);
	Resultat2.SetValue(NbResultats,
			   IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
							   TheParCurveDomain,
							   Inter2_And_Domain2.Value(indice_1),
							   Inter2_And_Domain2.Value(indice_2),
							   EpsNul));
      }
    }
    else { //======= la borne1 n est pas sur le domaine ========
      if(IsOnTheImpCurveDomain2) {
	Standard_Real t;
	NbResultats++;
	t=TheImpCurveDomain.FirstParameter(); 
	
	Resultat1.SetValue(NbResultats,t);
	Resultat2.SetValue(NbResultats,
			   IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
				 TheParCurveDomain,
				 Inter2_And_Domain2.Value(indice_1),
				 Inter2_And_Domain2.Value(indice_2),
				 EpsNul));
	
	NbResultats++;
	Resultat1.SetValue(NbResultats,Inter1.Value(indice_2));
	Resultat2.SetValue(NbResultats,Inter2_And_Domain2.Value(indice_2));
      }
      else {  //====== la borne2 et la borne1 sont hors domaine =====
	if(param1<TheImpCurveDomain.FirstParameter()
	   && param2>TheImpCurveDomain.LastParameter()) {
	  Standard_Real t;
	  NbResultats++;
	  t=TheImpCurveDomain.FirstParameter();
	  Resultat1.SetValue(NbResultats,t);
	  Resultat2.SetValue(NbResultats,
			     IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
							     TheParCurveDomain,
							     Inter2_And_Domain2.Value(indice_1),
							     Inter2_And_Domain2.Value(indice_2),
							     EpsNul));


	  
	  NbResultats++;
	  t=TheImpCurveDomain.LastParameter();
	  Resultat1.SetValue(NbResultats,t);
	  Resultat2.SetValue(NbResultats,
			     IntImpParGen_Intersector::FindV(t,Pt,TheImpTool,TheParCurve,
				   TheParCurveDomain,
				   Inter2_And_Domain2.Value(indice_1),
				   Inter2_And_Domain2.Value(indice_2),
				   EpsNul));
	  
	}
      }
    }
  }
}
//======================================================================
//--     C o n s t r u c t e u r s     e t     P e r f o r m 
IntImpParGen_Intersector::IntImpParGen_Intersector() {
  done=Standard_False;
}
//----------------------------------------------------------------------
//--
IntImpParGen_Intersector::IntImpParGen_Intersector(const ImpTool& TheImpTool,
                                        const IntRes2d_Domain& TheImpCurveDomain,
                                        const ParCurve& TheParCurve,
                                        const IntRes2d_Domain& TheParCurveDomain,
					const Standard_Real TolConf,
					const Standard_Real Tol) {
  Perform(TheImpTool,TheImpCurveDomain,TheParCurve,TheParCurveDomain,TolConf,Tol);
}
//----------------------------------------------------------------------
//--
void IntImpParGen_Intersector::Perform(const ImpTool& TheImpTool,
                                        const IntRes2d_Domain& TheImpCurveDomain,
                                        const ParCurve& TheParCurve,
                                        const IntRes2d_Domain& TheParCurveDomain,
					const Standard_Real TolConf,
					const Standard_Real Tol) {


  Standard_Integer i,nb_segments_solution, nb_points_solution;
  Standard_Real param1,param2,EpsX, EpsNul, EpsDist;
  
  IntRes2d_Transition Trans1,Trans2;
  gp_Pnt2d pt1,pt2;
  gp_Vec2d Tan1,Tan2,Norm1,Norm2;
  IntRes2d_Position Pos1,Pos2;


  //----------------------------------------------
  //-- On teste apres appel aux maths si les bornes 
  //-- des domaines sont des solutions
  //-- 
  Standard_Boolean HeadOnImp =Standard_False;
  Standard_Boolean HeadOnPar =Standard_False;
  Standard_Boolean EndOnImp  =Standard_False;
  Standard_Boolean EndOnPar  =Standard_False;

  this->ResetFields();

  IntImpParGen_MyImpParTool TheImpParTool(TheImpTool,TheParCurve);

  if (! (TheParCurveDomain.HasFirstPoint() &&
         TheParCurveDomain.HasLastPoint())) {
    Standard_ConstructionError::Raise("Domaine sur courbe incorrect");
    }
  
  Standard_Integer nb_echantillons = ParTool::NbSamples(TheParCurve,
							TheParCurveDomain.FirstParameter(),
							TheParCurveDomain.LastParameter());

  EpsX = EPSX;
  if(EpsX>1.0e-10) EpsX = 1.0e-10;
  EpsNul=(TolConf<=1.0e-10)? 1.0e-10: TolConf;
  EpsDist=(Tol<=1.0e-10)? 1.0e-10: Tol;
  
  Standard_Real Tolerance_Angulaire=EpsDist;  
  


  if((TheParCurveDomain.LastParameter() - TheParCurveDomain.FirstParameter()) < 100.0*EpsX) {
    EpsX = (TheParCurveDomain.LastParameter() - TheParCurveDomain.FirstParameter())*0.01;
  }

    math_FunctionSample Sample2(TheParCurveDomain.FirstParameter(),
				TheParCurveDomain.LastParameter(),
				nb_echantillons);
    
    math_FunctionAllRoots Sol(TheImpParTool,
			      Sample2,
			      EpsX,
			      EpsDist,
			      EpsNul);
    
    if(!Sol.IsDone()) {done = Standard_False; return; }
    
    nb_segments_solution=Sol.NbIntervals();
    nb_points_solution=Sol.NbPoints();
    
    //--------------------------------------------------------------------
  //--   T r a i t e m e n t    d e s   P o i n t s   S o l u t i o n s
  for(i=1; i<=nb_points_solution; i++) {
    gp_Pnt2d Pt;
    param2=Sol.GetPoint(i);
    param1=FindU(param2,Pt,TheParCurve,TheImpTool);
  
    if(TheImpCurveDomain.IsClosed()) {
      param1 = IntImpParGen::NormalizeOnDomain( param1
				 ,TheImpCurveDomain);
    }
    
    Standard_Boolean IsOnTheImpCurveDomain=Standard_True;
    if(TheImpCurveDomain.HasFirstPoint()) { 
      if(param1<TheImpCurveDomain.FirstParameter()) {             
	if(Pt.Distance(TheImpCurveDomain.FirstPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain=Standard_False; 
	}
      }
    }
    if(IsOnTheImpCurveDomain && TheImpCurveDomain.HasLastPoint()) {
      if(param1>TheImpCurveDomain.LastParameter()) {
	if(Pt.Distance(TheImpCurveDomain.LastPoint()) 
	   > TheImpCurveDomain.FirstTolerance()) {
	  IsOnTheImpCurveDomain=Standard_False; 
	}
      }
    }
    
    if(IsOnTheImpCurveDomain) {
      TheImpTool.D2(param1,pt1,Tan1,Norm1);
      ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
      
      IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,pt1,param1);
      IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,pt2,param2);
      
      if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
      else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
      if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
      else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;

      IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
			   Pos2,Tan2,Norm2,Trans2,
			   Tolerance_Angulaire);

      IntRes2d_IntersectionPoint IP(pt1,param1,param2
				    ,Trans1,Trans2
				    ,ReversedParameters());
      Insert(IP);
    }
  } 
  //-- F i n   d u   T r a i t e m e n t   d e s   P t s   S o l.


  //--------------------------------------------------------------------
  //--        T r a i t e m e n t   D e s   S e g m e n t s          ---
  //--------------------------------------------------------------------
  //--  On a N segments solution sur le domaine de V    soit au pire :
  //--    --> N segments solution sur le domaine de U 
  //--    -->2N segments si la courbe en U est fermee
  //--   

  TColStd_Array1OfReal Inter2_and_Domaine2(1,2+8*nb_segments_solution);
  TColStd_Array1OfReal Inter1(1,2+8*nb_segments_solution);

  Standard_Integer nb_segments_crees=0;

  for (Standard_Integer j2=1,j=1;j<=nb_segments_solution;j++,j2+=2) {
    Standard_Real param2_inf,param2_sup;
    Standard_Real param1_inf,param1_sup;
    gp_Pnt2d Ptemp;
    
    Sol.GetInterval(j,param2_inf,param2_sup);
    param1_inf=FindU(param2_inf,Ptemp,TheParCurve,TheImpTool);
    param1_sup=FindU(param2_sup,Ptemp,TheParCurve,TheImpTool);    

    //----------------------------------------------------------------------
    //--         C o u r b e    I m p l i c i t e    F e r m e e 

    if(TheImpCurveDomain.IsClosed()) {

      gp_Pnt2d Ptemp;
      gp_Vec2d T1,T2,N1,N2;
      Standard_Real param1_origine,param1_fin;

      TheImpCurveDomain.EquivalentParameters(param1_origine,param1_fin);
      Standard_Real Periode=param1_fin-param1_origine;

      while(param1_inf<param1_origine) { param1_inf+=Periode; }
      while(param1_sup<param1_origine) { param1_sup+=Periode; }      

      ParTool::D2(TheParCurve,param2_inf,Ptemp,T2,N2);
      TheImpTool.D2(param1_inf,Ptemp,T1,N1);
      if(T1.Magnitude()<=gp::Resolution()) T1=N1;
      if(T2.Magnitude()<=gp::Resolution()) T2=N2;

      if(T1.Dot(T2) >=0.0) {
	//---  param1_inf designe un point entrant (et T1 est vers la matiere)
	if(param1_inf>=param1_sup) {    param1_sup+=Periode;	}
      }
      else { //---  param1_inf : point sortant (et T1 est Hors matiere)
	if(param1_inf<=param1_sup) {    param1_inf+=Periode;     }
      }
      //--- On cree un nouveau segment decale de Periode
      //--  Exemple de Pb : Domaine PI/4  PI/2   et intervalle 0,PI
      //--                  Domaine 1.5PI 2.5PI  et intervalle 0,PI
      //--        -2pi                  0                2pi     
      //--   ------|--------------------|-----------------|-----------
      //--            [----------------------------]               Domaine
      //--                                   [~~~~~~~~~~~~~~~~~]   Inters.
      //--
      //--  On cree un nouvel intervalle 
      //--   interv decale
      //--  [a~~~~~~~~~~~~b]                 [a~~~~~~~~~~~~~~~b]  et  [a~~~]
      //--
      //

      if(TheImpCurveDomain.LastParameter() 
	 > ((param1_inf>param1_sup)? (param1_sup+Periode): 
	                              (param1_inf+Periode))) {
	Inter2_and_Domaine2.SetValue(j2,param2_inf);
	Inter1.SetValue(j2,param1_inf+Periode);
      
	Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
	Inter1.SetValue(j2+1,param1_sup+Periode);     
	j2+=2;
	nb_segments_crees++;
      }
								       
      if(TheImpCurveDomain.FirstParameter() 
	 <((param1_inf<param1_sup)? (param1_sup-Periode): (param1_inf-Periode))) {
	Inter2_and_Domaine2.SetValue(j2,param2_inf);
	Inter1.SetValue(j2,param1_inf-Periode);
	
	Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
	Inter1.SetValue(j2+1,param1_sup-Periode);     
	j2+=2;
	nb_segments_crees++;
      }
    }
    //--   F i n     C o u r b e    I m p l i c i t e    F e r m e e 
    //----------------------------------------------------------------------


    Inter2_and_Domaine2.SetValue(j2,param2_inf);
    Inter1.SetValue(j2,param1_inf);
    
    Inter2_and_Domaine2.SetValue(j2+1,param2_sup);
    Inter1.SetValue(j2+1,param1_sup);
  } 
  
  //------------------------------------------------------------------
  //--  INTER2_DOMAINE2 : Intersection AND CurveDomain : Function of PARAM2
  //--    INTER1        : Intersection AND CurveDomain : Function of PARAM1
  //------------------------------------------------------------------  
  //--
  TColStd_Array1OfReal Resultat1(1,2+(1+nb_segments_solution)*2);
  TColStd_Array1OfReal Resultat2(1,2+(1+nb_segments_solution)*2);
  nb_segments_solution+=nb_segments_crees;
  Standard_Integer NbResultats=nb_segments_solution*2;

  And_Domaine_Objet1_Intersections(TheImpTool,
				   TheParCurve,
				   TheImpCurveDomain,
				   TheParCurveDomain,
				   NbResultats,
				   Inter2_and_Domaine2,Inter1,
				   Resultat1,Resultat2,EpsNul);

  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //Calcule_Toutes_Transitions(NbResultats,
  //			     Resultat1,Resultat2,
  //			     TheImpTool,
  //			     TheImpCurveDomain,
  //			     TheParCurve,
  //			     TheParCurveDomain); 
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //~~~ Fonction Calcule_Toutes_Transitions Repportee ici pour cause ~~~~~
  //~~~~~       D acces aux methodes Protected APPEND
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  {
    IntRes2d_Position Pos1,Pos2;
    IntRes2d_Transition Trans1,Trans2;
    gp_Vec2d Tan1,Tan2,Norm1,Norm2;
    gp_Pnt2d Pt1_on1,Pt2_on1,Pt1_on2,Pt2_on2;
    Standard_Real Param1_on1,Param2_on1,Param1_on2,Param2_on2;
    
    Standard_Real Dist_Mini_ImpCurve=EPSNUL;
    Standard_Real Tolerance_Angulaire=Dist_Mini_ImpCurve; 
    
    
    for(Standard_Integer i=1; i<=NbResultats ; i+=2) {
      Standard_Integer ip1=i+1;
      Standard_Boolean OnlyOnePoint=Standard_False;
      
      Param1_on1=Resultat1.Value(i);
      Param1_on2=Resultat2.Value(i);
      Param2_on1=Resultat1.Value(ip1);
      Param2_on2=Resultat2.Value(ip1);

      Pt1_on1=TheImpTool.Value(Param1_on1);
      Pt2_on1=TheImpTool.Value(Param2_on1);
      Pt1_on2=ParTool::Value(TheParCurve,Param1_on2);
      Pt2_on2=ParTool::Value(TheParCurve,Param2_on2);
      
      if(!TheImpCurveDomain.IsClosed()) { 
	if( Pt1_on1.Distance(Pt2_on1) <= Dist_Mini_ImpCurve ) {
	  if( Pt1_on2.Distance(Pt2_on2) <= Dist_Mini_ImpCurve ) {
	    OnlyOnePoint=Standard_True;
	  }
	}
      }  

      Param1_on1=IntImpParGen::NormalizeOnDomain(Param1_on1,TheImpCurveDomain);
      Param1_on2=IntImpParGen::NormalizeOnDomain(Param1_on2,TheParCurveDomain);

      TheImpTool.D2(Param1_on1,Pt1_on1,Tan1,Norm1);
      ParTool::D2(TheParCurve,Param1_on2,Pt1_on2,Tan2,Norm2);
      
      IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,Pt1_on1,Param1_on1);
      IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,Pt1_on2,Param1_on2);

      if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
      else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
      if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
      else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;
      

      IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
			   Pos2,Tan2,Norm2,Trans2,
			   Tolerance_Angulaire);
      
      //============== Detection du cas : L intersection est en bout
      //==============  sur les 2 domaines
      
      if(Pos1!=IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
	Standard_Real m=0.5*(Pt1_on1.X() + Pt1_on2.X());
	Pt1_on1.SetX(m);
	m=0.5*(Pt1_on1.Y() + Pt1_on2.Y());
	Pt1_on1.SetY(m);
      }

      IntRes2d_IntersectionPoint new_p1(Pt1_on1
					,Param1_on1,Param1_on2
					,Trans1,Trans2
					,ReversedParameters());
      if(!OnlyOnePoint) {
	IntRes2d_IntersectionPoint new_p2;

	Param2_on1=IntImpParGen::NormalizeOnDomain(Param2_on1,TheImpCurveDomain);
	Param2_on2=IntImpParGen::NormalizeOnDomain(Param2_on2,TheParCurveDomain);

	TheImpTool.D2(Param2_on1,Pt2_on1,Tan1,Norm1);
	ParTool::D2(TheParCurve,Param2_on2,Pt2_on2,Tan2,Norm2);
	
	IntImpParGen::DeterminePosition(Pos1,TheImpCurveDomain,Pt2_on1,Param2_on1);
	IntImpParGen::DeterminePosition(Pos2,TheParCurveDomain,Pt2_on2,Param2_on2);
	
	if(Pos1==IntRes2d_End)  EndOnImp  = Standard_True;
	else if(Pos1==IntRes2d_Head) HeadOnImp = Standard_True;
	if(Pos2==IntRes2d_End)  EndOnPar  = Standard_True;
	else if(Pos2==IntRes2d_Head) HeadOnPar = Standard_True;

	IntImpParGen::DetermineTransition(Pos1,Tan1,Norm1,Trans1,
					  Pos2,Tan2,Norm2,Trans2,
					  Tolerance_Angulaire);
	
	
	//============== Detection du cas : L intersection est en bout
	//==============  sur les 2 domaines 
	
	if(Pos1!=IntRes2d_Middle && Pos2!=IntRes2d_Middle) {
	  Standard_Real m=0.5*(Pt2_on1.X() + Pt2_on2.X() );
	  Pt2_on1.SetX(m);
	  m=0.5*(Pt2_on1.Y() + Pt2_on2.Y());
	  Pt2_on1.SetY(m);
	}

	new_p2.SetValues(Pt2_on1,Param2_on1,Param2_on2
			 ,Trans1,Trans2
			 ,ReversedParameters());

	Standard_Boolean segopposite=((Tan1.Dot(Tan2) < 0.0)? 
				      Standard_True : Standard_False);
	
	IntRes2d_IntersectionSegment new_seg(new_p1,new_p2
					     ,segopposite
					     ,ReversedParameters());
	Append(new_seg);
      }
      else {
	Insert(new_p1); 
      }
    }
  } //~~~~~~~~~~~~  Fin du corps de la fonction Calc...Transitions~~~~~~~~~~
  
  //-------------------------------------------
  //-- On teste les points en bouts solutions
  //-- 
  if(!HeadOnImp && TheImpCurveDomain.HasFirstPoint()) { 
    if(!HeadOnPar) { 
      if(TheImpCurveDomain.FirstPoint().Distance(TheParCurveDomain.FirstPoint()) 
	 <= Max(TheImpCurveDomain.FirstTolerance(),TheParCurveDomain.FirstTolerance())) { 
	param1 = TheImpCurveDomain.FirstParameter();
	param2 = TheParCurveDomain.FirstParameter();
	TheImpTool.D2(param1,pt1,Tan1,Norm1);
	ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
	IntImpParGen::DetermineTransition(IntRes2d_Head,Tan1,Norm1,Trans1,
					  IntRes2d_Head,Tan2,Norm2,Trans2,
					  Tolerance_Angulaire);
	IntRes2d_IntersectionPoint IP(TheImpCurveDomain.FirstPoint(),
				      param1,param2,
				      Trans1,Trans2,
				      ReversedParameters());
	Insert(IP);
      }
    }
    if(!EndOnPar) { 
      if(TheImpCurveDomain.FirstPoint().Distance(TheParCurveDomain.LastPoint()) 
	 <= Max(TheImpCurveDomain.FirstTolerance(),TheParCurveDomain.LastTolerance())) { 
	param1 = TheImpCurveDomain.FirstParameter();
	param2 = TheParCurveDomain.LastParameter();
	TheImpTool.D2(param1,pt1,Tan1,Norm1);
	ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
	IntImpParGen::DetermineTransition(IntRes2d_Head,Tan1,Norm1,Trans1,
					  IntRes2d_End ,Tan2,Norm2,Trans2,
					  Tolerance_Angulaire);
	IntRes2d_IntersectionPoint IP(TheImpCurveDomain.FirstPoint(),
				      param1,param2,
				      Trans1,Trans2,
				      ReversedParameters());
	Insert(IP);
      }
    }
  }
  
  if(!EndOnImp && TheImpCurveDomain.HasLastPoint()) { 
    if(!HeadOnPar) { 
      if(TheImpCurveDomain.LastPoint().Distance(TheParCurveDomain.FirstPoint()) 
	 <= Max(TheImpCurveDomain.LastTolerance(),TheParCurveDomain.FirstTolerance())) {
	param1 = TheImpCurveDomain.LastParameter();
	param2 = TheParCurveDomain.FirstParameter();
	TheImpTool.D2(param1,pt1,Tan1,Norm1);
	ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
	IntImpParGen::DetermineTransition(IntRes2d_End,Tan1,Norm1,Trans1,
					  IntRes2d_Head,Tan2,Norm2,Trans2,
					  Tolerance_Angulaire);
	IntRes2d_IntersectionPoint IP(TheImpCurveDomain.LastPoint(),
				      param1,param2,
				      Trans1,Trans2,
				      ReversedParameters());
	Insert(IP);
      }
    }
    if(!EndOnPar) { 
      if(TheImpCurveDomain.LastPoint().Distance(TheParCurveDomain.LastPoint()) 
	 <= Max(TheImpCurveDomain.LastTolerance(),TheParCurveDomain.LastTolerance())) {
	param1 = TheImpCurveDomain.LastParameter();
	param2 = TheParCurveDomain.LastParameter();
	TheImpTool.D2(param1,pt1,Tan1,Norm1);
	ParTool::D2(TheParCurve,param2,pt2,Tan2,Norm2);
	IntImpParGen::DetermineTransition(IntRes2d_End,Tan1,Norm1,Trans1,
					  IntRes2d_End,Tan2,Norm2,Trans2,
					  Tolerance_Angulaire);
	IntRes2d_IntersectionPoint IP(TheImpCurveDomain.LastPoint(),
				      param1,param2,
				      Trans1,Trans2,
				      ReversedParameters());
	Insert(IP);
      }
    }
  }
  done=Standard_True; 
}






Standard_Real IntImpParGen_Intersector::FindU(const Standard_Real parameter
					      ,gp_Pnt2d& point
					      ,const ParCurve& TheParCurve
					      ,const ImpTool& TheImpTool) const 
{
  point=ParTool::Value(TheParCurve,parameter);
  return(TheImpTool.FindParameter(point));
}

Standard_Real IntImpParGen_Intersector::FindV(const Standard_Real parameter
		  ,gp_Pnt2d& point
		  ,const ImpTool& TheImpTool
		  ,const ParCurve& TheParCurve
		  ,const IntRes2d_Domain& TheParCurveDomain
		  ,const Standard_Real V0
		  ,const Standard_Real V1
		  ,const Standard_Real Tolerance) const 
{
  point=TheImpTool.Value(parameter);
  if(TheParCurveDomain.IsClosed()) {
    Standard_Real V = ProjectOnPCurveTool::FindParameter(TheParCurve,
							 point,
							 Tolerance);
    return(IntImpParGen::NormalizeOnDomain(V,TheParCurveDomain));
  }
  else {
    Standard_Real VV0 = V0;
    Standard_Real VV1 = V1;
    if(V1<V0) { VV0 = V1; VV1 = V0; } 
    //-- ??????????????????????????????????????????????????????????????????????
    //-- Modif le 15 Septembre 1992 : On Teste le parametre retourne 
    //--??????????????????????????????????????????????????????????????????????
    Standard_Real X = ProjectOnPCurveTool::FindParameter(TheParCurve,
							 point,
							 VV0,VV1,Tolerance);
    if(X>VV1) X=VV1; else if(X<VV0) X=VV0;
    return(X);
  }
}