summaryrefslogtreecommitdiff
path: root/src/Bisector/Bisector_BisecPC.cxx
blob: 20ca97fd91651647d688734767e566d85ed31d6f (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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
// File:	Bisector_BisecPC.cxx
// Created:	Thu Mar 10 17:54:52 1994
// Author:	Yves FRICAUD
//		<yfr@phylox>

#include <Bisector_BisecPC.ixx>
#include <Bisector.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2dInt_GInter.hxx>
#include <Geom2dGcc.hxx>
#include <GccEnt_Position.hxx>
#include <Geom2dGcc_Circ2d2TanRad.hxx>
#include <Geom2dGcc_QualifiedCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2dAPI_ProjectPointOnCurve.hxx>
#include <Geom2dLProp_CLProps2d.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Ax2d.hxx>  
#include <gp.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <IntRes2d_IntersectionPoint.hxx>

#include <Standard_DivideByZero.hxx>
#include <Standard_NotImplemented.hxx>

//=============================================================================
//function :
// purpose :
//=============================================================================
Bisector_BisecPC::Bisector_BisecPC()
{
}

//=============================================================================
//function :
// purpose :
//=============================================================================
Bisector_BisecPC::Bisector_BisecPC(const Handle(Geom2d_Curve)& Cu, 
				   const gp_Pnt2d&             P,
				   const Standard_Real         Side,
				   const Standard_Real         DistMax)
{
  Perform (Cu,P,Side,DistMax);
}

//=============================================================================
//function :
// purpose :
//=============================================================================
Bisector_BisecPC::Bisector_BisecPC(const Handle(Geom2d_Curve)& Cu, 
				   const gp_Pnt2d&             P,
				   const Standard_Real         Side,
				   const Standard_Real         UMin,
				   const Standard_Real         UMax)

{
  curve    = Handle (Geom2d_Curve)::DownCast(Cu->Copy());
  point    = P;
  sign     = Side;
  startIntervals.Append(UMin);
  endIntervals  .Append(UMax);  
  bisInterval    = 1;
  extensionStart = Standard_False;
  extensionEnd   = Standard_False; 
  pointStartBis  = Value(UMin);
  pointEndBis    = Value(UMax);
  isConvex = Bisector::IsConvex(curve,sign);
}

//=============================================================================
//function : Perform
// purpose :
//=============================================================================
void  Bisector_BisecPC::Perform(const Handle(Geom2d_Curve)& Cu, 
				const gp_Pnt2d&             P,
				const Standard_Real         Side,
				const Standard_Real         DistMax)
{
  curve    = Handle (Geom2d_Curve)::DownCast(Cu->Copy());
  point    = P;
  distMax  = DistMax;
  sign     = Side;
  isConvex = Bisector::IsConvex(curve,sign);
  //--------------------------------------------
  // Calcul intervalle de definition.
  //--------------------------------------------
  ComputeIntervals();
  if (isEmpty) return;

  //-------------------------
  // Construction extensions.
  //-------------------------  
  bisInterval    = 1;
  extensionStart = Standard_False;
  extensionEnd   = Standard_False;
  pointStartBis  = Value(startIntervals.First());
  pointEndBis    = Value(endIntervals  .Last());

  if (!isConvex) {
    if (point.IsEqual(curve->Value(curve->FirstParameter()),
		      Precision::Confusion())               ) {
      extensionStart = Standard_True;
      Standard_Real UFirst = startIntervals.First() - P.Distance(pointStartBis);
      startIntervals.InsertBefore(1,UFirst);
      endIntervals  .InsertBefore(1,startIntervals.Value(2));
      bisInterval = 2;
    }
    else if (point.IsEqual(curve->Value(curve->LastParameter()),
			   Precision::Confusion())              ) {
      extensionEnd = Standard_True;      
      Standard_Real ULast = endIntervals.Last() + P.Distance(pointEndBis);
      startIntervals.Append(endIntervals.Last());
      endIntervals  .Append(ULast);
      bisInterval = 1;
    }
  }
}

//=============================================================================
//function : IsExtendAtStart
//purpose  :
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsExtendAtStart() const
{
  return extensionStart;
}

//=============================================================================
//function : IsExtendAtEnd
//purpose  :
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsExtendAtEnd() const
{
  return extensionEnd;
}

//=============================================================================
//function : Reverse
//purpose  :
//=============================================================================
void Bisector_BisecPC::Reverse()
{
  Standard_NotImplemented::Raise();
}

//=============================================================================
//function : ReversedParameter
//purpose  :
//=============================================================================
Standard_Real  Bisector_BisecPC::ReversedParameter(const Standard_Real U) const
{
 return LastParameter() + FirstParameter() - U;
}

//=============================================================================
//function : Copy
//purpose  :
//=============================================================================
Handle(Geom2d_Geometry) Bisector_BisecPC::Copy() const
{
  Handle(Geom2d_Curve) CopyC = Handle(Geom2d_Curve)::DownCast(curve->Copy());
  Handle(Bisector_BisecPC) C = new Bisector_BisecPC();

  C->Init (CopyC,point,sign,
	   startIntervals,endIntervals,bisInterval,currentInterval,
	   shiftParameter,distMax,isEmpty,isConvex,extensionStart,extensionEnd,
	   pointStartBis,pointEndBis);
  return C;  
}

//=============================================================================
//function : Transform
//purpose  :
//=============================================================================
void Bisector_BisecPC::Transform(const gp_Trsf2d& T)
{
  curve        ->Transform(T);
  point        . Transform(T);
  pointStartBis. Transform(T);
  pointEndBis  . Transform(T);
}

//=============================================================================
//function : IsCN
//purpose  :
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsCN(const Standard_Integer N) const 
{
  return curve->IsCN(N+1);
}

//=============================================================================
//function : FirstParameter
//purpose  :
//=============================================================================
Standard_Real Bisector_BisecPC::FirstParameter() const
{
 return startIntervals.First();
}

//=============================================================================
//function : LastParameter
//purpose  :
//=============================================================================
Standard_Real Bisector_BisecPC::LastParameter() const
{
 return endIntervals.Last();
}

//=============================================================================
//function : Continuity
//purpose  :
//=============================================================================
GeomAbs_Shape Bisector_BisecPC::Continuity() const 
{
  GeomAbs_Shape Cont = curve->Continuity();
  switch (Cont) {
  case GeomAbs_C1 : return GeomAbs_C0; 
  case GeomAbs_C2 : return GeomAbs_C1;
  case GeomAbs_C3 : return GeomAbs_C2;
  case GeomAbs_CN : return GeomAbs_CN;  
#ifndef DEB
  default: break;
#endif
  }
  return GeomAbs_C0;
}

//=============================================================================
//function : NbIntervals
//purpose  :
//=============================================================================
Standard_Integer Bisector_BisecPC::NbIntervals() const
{
  return startIntervals.Length();
}

//=============================================================================
//function : IntervalFirst
//purpose  :
//=============================================================================
Standard_Real Bisector_BisecPC::IntervalFirst(const Standard_Integer I) const
{
  return startIntervals.Value(I);
}
    
//=============================================================================
//function : IntervalLast
//purpose  :
//=============================================================================
Standard_Real Bisector_BisecPC::IntervalLast(const Standard_Integer I) const
{
  return endIntervals.Value(I);
}

//=============================================================================
//function : IntervalContinuity
//purpose  :
//=============================================================================
GeomAbs_Shape Bisector_BisecPC::IntervalContinuity() const
{
  GeomAbs_Shape Cont = curve->Continuity();
  switch (Cont) {
  case GeomAbs_C1 : return GeomAbs_C0; 
  case GeomAbs_C2 : return GeomAbs_C1;
  case GeomAbs_C3 : return GeomAbs_C2;
  case GeomAbs_CN : return GeomAbs_CN;  
#ifndef DEB
  default: break;
#endif
  }
  return GeomAbs_C0; 
}

//=============================================================================
//function : IsClosed
//purpose  :
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsClosed() const
{
  if (curve->IsClosed()) {
    //-----------------------------------------------------------------------
    // La bisectrice est fermee si la curve est fermee et que la bissectrice
    // a un seul domaine de continuite egale a celui de la courbe.
    // -----------------------------------------------------------------------
    if (startIntervals.First() == curve->FirstParameter() &&
	endIntervals  .First() == curve->LastParameter ()    )
      return Standard_True;
  }
  return Standard_False;
}

//=============================================================================
//function : IsPeriodic
//purpose  :
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsPeriodic() const
{
  return Standard_False;
}

//=============================================================================
//function : Extension
// purpose :
//=============================================================================
void Bisector_BisecPC::Extension(const Standard_Real    U,
				       gp_Pnt2d&        P,
				       gp_Vec2d&        V1,
				       gp_Vec2d&        V2,
				       gp_Vec2d&        V3 ) const
{
  gp_Dir2d      DirExt;
  Standard_Real dU;

  if      ( U < startIntervals.Value(bisInterval)) {
    dU = U - startIntervals.Value(bisInterval);
    DirExt.SetCoord(pointStartBis.X() - point.X(),
		    pointStartBis.Y() - point.Y());
    P.SetCoord(pointStartBis.X() + dU*DirExt.X(),
	       pointStartBis.Y() + dU*DirExt.Y());
  }
  else if ( U > endIntervals.Value(bisInterval)) { 
    dU =  U - endIntervals.Value(bisInterval);
    DirExt.SetCoord(point.X() - pointEndBis.X(),
		    point.Y() - pointEndBis.Y()); 
    P.SetCoord(pointEndBis.X() + dU*DirExt.X(),
	       pointEndBis.Y() + dU*DirExt.Y());
  }
  V1.SetCoord(DirExt.X(),DirExt.Y());
  V2.SetCoord(0.        ,0.        );
  V3.SetCoord(0.        ,0.        );
}


//=============================================================================
//function : Values
// purpose : A chaque point de la courbe est associe un point sur la 
//           bissectrice. l equation de la bissectrice est:
//                              || PP(u)||**2
//           F(u) = P(u) - 1/2* -------------- * N(u)
//                              (N(u)|PP(u))
//
//           N(u) normale a la courbe en u.
//           ( | ) designe le produit scalaire.
//=============================================================================
void Bisector_BisecPC::Values(const Standard_Real    U,
			      const Standard_Integer N,
			            gp_Pnt2d&        P,
			            gp_Vec2d&        V1,
			            gp_Vec2d&        V2,
				    gp_Vec2d&        V3 ) const
{
  if ( U < startIntervals.Value(bisInterval)) {
    Extension(U,P,V1,V2,V3);
    return;
  }
  else if ( U > endIntervals.Value(bisInterval)) { 
    Extension(U,P,V1,V2,V3);
    return;
  }
  Standard_Real UOnCurve = LinkBisCurve(U);

  gp_Vec2d      Tu,Tuu,T3u;
  gp_Pnt2d      PC;

  switch (N) {
  case 0 :  {curve->D1(UOnCurve,PC,Tu)        ;break;}
  case 1 :  {curve->D2(UOnCurve,PC,Tu,Tuu)    ;break;}
  case 2 :  {curve->D3(UOnCurve,PC,Tu,Tuu,T3u);break;}
  }
  
  gp_Vec2d ppc(PC.X() - point.X(), PC.Y() - point.Y());
  gp_Vec2d Nor( - Tu.Y(), Tu.X());
  
  Standard_Real SquarePPC = ppc.SquareMagnitude();
  Standard_Real NorPPC    = Nor.Dot(ppc);
  Standard_Real A1;

  if (Abs(NorPPC) > gp::Resolution() && (NorPPC*sign) < 0.) {
    A1 = 0.5*SquarePPC/NorPPC;
    P.SetCoord(PC.X() - Nor.X()*A1, PC.Y() - Nor.Y()*A1);
  }
  else {return; }
  
  if (N == 0) return;                                 // Fin Calcul Point;

  gp_Vec2d      Nu ( - Tuu.Y() , Tuu.X());            // derivee de la normale en U.
  Standard_Real NuPPC     = Nu .Dot(ppc);
  Standard_Real TuPPC     = Tu .Dot(ppc);
  Standard_Real NorPPCE2  = NorPPC*NorPPC;
  Standard_Real A2        = TuPPC/NorPPC - 0.5*NuPPC*SquarePPC/NorPPCE2;

//--------------------------
  V1 = Tu - A1*Nu - A2*Nor;
//--------------------------
  if (N == 1) return;                                       //Fin calcul D1.

  gp_Vec2d Nuu ( - T3u.Y() , T3u.X());
  
  Standard_Real NorPPCE4 = NorPPCE2*NorPPCE2;
  Standard_Real NuuPPC   = Nuu.Dot(ppc);
  Standard_Real TuuPPC   = Tuu.Dot(ppc);
  
  Standard_Real A21 = TuuPPC/NorPPC - TuPPC*NuPPC/NorPPCE2;
  Standard_Real A22 = (0.5*NuuPPC*SquarePPC + NuPPC*TuPPC)/NorPPCE2 - 
                      NuPPC*SquarePPC*NorPPC*NuPPC/NorPPCE4;
  Standard_Real A2u = A21 - A22;      
//----------------------------------------
  V2  = Tuu - 2*A2*Nu - A1*Nuu - A2u*Nor;
//----------------------------------------
}

//=============================================================================
//function : Curvature
//purpose  :
//=============================================================================
// Unused :
#ifdef DEB
static Standard_Real Curvature (const Handle(Geom2d_Curve)& C,
				      Standard_Real         U,
				      Standard_Real         Tol)
{
  Standard_Real K1;
  gp_Vec2d      D1,D2;
  gp_Pnt2d      P;
  C->D2(U,P,D1,D2);
  Standard_Real Norm2 = D1.SquareMagnitude();;
  if (Norm2 < Tol) {
    K1 = 0.0;
  }
  else {
    K1   = (D1^D2)/(Norm2*sqrt(Norm2));
  }
  return K1;
}
#endif

//=============================================================================
//function : Distance
//purpose  : distance au carre du point de parametre U a la courbe et au point:
//
//            2             ||PP(u)||**4           2
//           d =   1/4* ------------------- ||Nor||
//                         (Nor(u)/PP(u))**2 
//
//           ou Nor est la normale a la courbe en U. 
//=============================================================================
Standard_Real Bisector_BisecPC::Distance (const Standard_Real U) const
{
  gp_Vec2d Tan;
  gp_Pnt2d PC;

  Standard_Real UOnCurve = LinkBisCurve(U);
  
  curve->D1(UOnCurve,PC,Tan);
  gp_Vec2d ppc(PC.X() - point.X(), PC.Y() - point.Y());
  gp_Vec2d Nor( - Tan.Y(), Tan.X());

  Standard_Real NorNor       = Nor.SquareMagnitude();
  Standard_Real SquareMagPPC = ppc.SquareMagnitude();
  Standard_Real Prosca       = Nor.Dot(ppc);
  
  if (point.IsEqual(PC,Precision::Confusion())) {
    if (isConvex) { return 0.;}
    //----------------------------------------------------
    // le point est sur une courbe concave. 
    // Le point voulu n est pas le point commun.
    // ceci pour evite la discontinuite de la bisectrice.
    //----------------------------------------------------
    else { return Precision::Infinite();} 
  }

  if (Abs(Prosca) < Precision::Confusion() || (Prosca*sign) > 0. ) {
    return Precision::Infinite();
  }
  else {    
    Standard_Real A  = 0.5*SquareMagPPC/Prosca;
    Standard_Real Dist = A*A*NorNor;
    //----------------------------------------
    // Test Courbure si la courbe est concave.
    //----------------------------------------
//    if (!isConvex){
//      Standard_Real K  = Curvature(curve,UOnCurve,Precision::Confusion());
//      if (K  != 0.) {
//	if (Dist > 1/(K*K)) { Dist = Precision::Infinite();}
//      }
//    }
    return Dist;
  }
}



//=============================================================================
//function : D0
// purpose : 
//=============================================================================
void Bisector_BisecPC::D0(const Standard_Real     U,
			        gp_Pnt2d&         P) const
{
  P = point;
  gp_Vec2d V1,V2,V3;
  Values(U,0,P,V1,V2,V3);
}


//=============================================================================
//function : D1
// purpose : 
//=============================================================================
void Bisector_BisecPC::D1(const Standard_Real     U,
			        gp_Pnt2d&         P,
			        gp_Vec2d&         V ) const
{
  P = point;
  V.SetCoord(0.,0.);
  gp_Vec2d V2,V3;
  Values(U,1,P,V,V2,V3);
}


//=============================================================================
//function : D2
// purpose : 
//=============================================================================
void Bisector_BisecPC::D2(const Standard_Real     U,
			        gp_Pnt2d&         P,
			        gp_Vec2d&         V1,
			        gp_Vec2d&         V2) const
{
  P = point;
  V1.SetCoord(0.,0.);
  V2.SetCoord(0.,0.);
  gp_Vec2d V3;
  Values(U,2,P,V1,V2,V3);
}

//=============================================================================
//function : D3
// purpose : 
//=============================================================================
void Bisector_BisecPC::D3(const Standard_Real     U,
			        gp_Pnt2d&         P,
			        gp_Vec2d&         V1,
			        gp_Vec2d&         V2,
			        gp_Vec2d&         V3) const
{
  P = point;
  V1.SetCoord(0.,0.);
  V2.SetCoord(0.,0.);
  V3.SetCoord(0.,0.);
  Values(U,3,P,V1,V2,V3);
}


//=============================================================================
//function : DN
// purpose : 
//=============================================================================
gp_Vec2d Bisector_BisecPC::DN (const Standard_Real     U,
			       const Standard_Integer  N) const
{
  gp_Pnt2d P = point;
  gp_Vec2d V1(0.,0.);
  gp_Vec2d V2(0.,0.);
  gp_Vec2d V3(0.,0.);
  Values (U,N,P,V1,V2,V3);
  switch (N) {
  case 1 : return V1;
  case 2 : return V2;
  case 3 : return V3;
  default: {
    Standard_NotImplemented::Raise();
    }
  }
  return V1;
}

//=============================================================================
//function : SearchBound
// purpose : 
//=============================================================================
Standard_Real Bisector_BisecPC::SearchBound (const Standard_Real U1,
					     const Standard_Real U2) const
{
  Standard_Real Dist1,DistMid,U11,U22; 
#ifndef DEB
  Standard_Real UMid = 0.;
#else
  Standard_Real UMid;
#endif
  Standard_Real Tol      = Precision::PConfusion();
  Standard_Real DistMax2 = distMax*distMax;
  U11 = U1; U22 = U2;
  Dist1 = Distance(U11);
  
  while ((U22 - U11) > Tol) {
    UMid    = 0.5*( U22 + U11);
    DistMid = Distance(UMid);
    if ((Dist1 > DistMax2) == (DistMid > DistMax2)) {
      U11    = UMid;
      Dist1 = DistMid;
    }
    else {
      U22    = UMid;
    }
  }
  return UMid;
}

//=============================================================================
//function : CuspFilter
// purpose : 
//=============================================================================
void Bisector_BisecPC::CuspFilter()
{
  Standard_NotImplemented::Raise();
}

//=============================================================================
//function : ComputeIntervals
// purpose : 
//=============================================================================
void Bisector_BisecPC::ComputeIntervals ()
{
#ifndef DEB
  Standard_Real U1 =0.,U2 =0.,UProj =0.;
#else
  Standard_Real U1,U2,UProj;
#endif
  Standard_Real UStart,UEnd;
  Standard_Real Dist1,Dist2,DistProj;
  isEmpty        = Standard_False;     
  shiftParameter = 0.;
  Standard_Boolean YaProj   = Standard_False;
  Standard_Real    DistMax2 = distMax*distMax;

  U1 = curve->FirstParameter();
  U2 = curve->LastParameter();
  Dist1    = Distance(U1);
  Dist2    = Distance(U2);
  DistProj = Precision::Infinite();

  Geom2dAPI_ProjectPointOnCurve Proj(point,curve,U1,U2);
  if (Proj.NbPoints() > 0) {
    UProj    = Proj.LowerDistanceParameter();
    DistProj = Distance(UProj);
    YaProj   = Standard_True;
  } 

  if (Dist1 < DistMax2 && Dist2 < DistMax2) {
    if (DistProj > DistMax2 && YaProj) {
      isEmpty = Standard_True;
    }
    else {
      startIntervals.Append(U1);
      endIntervals  .Append(U2);
    }
    return;
  }
  else if (Dist1 > DistMax2 && Dist2 > DistMax2) {
    if (DistProj < DistMax2) {
      UStart = SearchBound(U1,UProj);
      UEnd   = SearchBound(UProj,U2);
    }
     else {
      isEmpty = Standard_True;
      return;
    }
  }
  else if (Dist1 < DistMax2) {
    UStart = U1;
    UEnd = SearchBound(U1,U2);
  }
  else if (Dist2 < DistMax2) {
    UEnd = U2;
    UStart = SearchBound(U1,U2);
  }
  startIntervals.Append(UStart);
  endIntervals  .Append(UEnd);

  //------------------------------------------------------------------------
  // Decalage eventuel du parametre sur la courbe par rapport a celui sur
  // la curve. Le decalage est effectue si la curve est periodique. et
  // que le point de parametre initial est interieure a un interval de cont
  // inuite.
  //------------------------------------------------------------------------
  if (curve->IsPeriodic()) {
    if (startIntervals.Length() > 1) {               // Plusieurs intervals.
      if (endIntervals  .Last()  == curve->LastParameter() &&
	  startIntervals.First() == curve->FirstParameter()   ) {
	//---------------------------------------------------------------
	// la bissectrice est definie a l origine.
	// => Fusion du premier et du dernier interval.
	// => le 0 sur la bisectrice devient le debut du premier interval
	// => decalage de parametre sur toutes les bornes des intervals.
	//---------------------------------------------------------------
	startIntervals.Remove(1);
	endIntervals  .Remove(endIntervals.Length());
	
	shiftParameter = Period() - startIntervals.First() ;
	for (Standard_Integer k = 1; k <= startIntervals.Length(); k++) {
	  endIntervals  .ChangeValue(k) += shiftParameter;
	  startIntervals.ChangeValue(k) += shiftParameter;
	}
	startIntervals.ChangeValue(1) = 0.;
      }
    }
  }
}

//=============================================================================
//function : LinkBisCurve
//purpose  : 
//=============================================================================
Standard_Real Bisector_BisecPC::LinkBisCurve(const Standard_Real U) const 
{
  return (U - shiftParameter);
} 

//=============================================================================
//function : LinkCurveBis
//purpose  : 
//=============================================================================
Standard_Real Bisector_BisecPC::LinkCurveBis(const Standard_Real U) const 
{
  return (U + shiftParameter);
} 

//=============================================================================
//function : IsEmpty
//purpose  : 
//=============================================================================
Standard_Boolean Bisector_BisecPC::IsEmpty() const
{
  return isEmpty;
}

//==========================================================================
//function : Parameter
//purpose  :
//==========================================================================
Standard_Real Bisector_BisecPC::Parameter(const gp_Pnt2d& P) const
{
  Standard_Real    Tol     = Precision::Confusion();

  if (P.IsEqual(pointStartBis,Tol)) {return startIntervals.Value(bisInterval);}
  if (P.IsEqual(pointEndBis  ,Tol)) {return endIntervals  .Value(bisInterval);}

  if (extensionStart) {
    gp_Ax2d Axe(pointStartBis,gp_Dir2d(pointStartBis.X() - P.X(),
				       pointStartBis.Y() - P.Y()));
    Standard_Real U    = ElCLib::LineParameter(Axe,P);
    gp_Pnt2d      Proj = ElCLib::LineValue(U,Axe);
    if (Proj.IsEqual(P,Tol) && U < 0.) {
      return U + startIntervals.Value(bisInterval);
    }
  }
  if (extensionEnd)   {    
    gp_Ax2d Axe(pointEndBis,gp_Dir2d(P.X() - pointEndBis.X(),
				     P.Y() - pointEndBis.Y()));
    Standard_Real U    = ElCLib::LineParameter(Axe,P);
    gp_Pnt2d      Proj = ElCLib::LineValue(U,Axe);
    if (Proj.IsEqual(P,Tol) && U > 0.) {
      return U + endIntervals.Value(bisInterval);
    }
  }
#ifndef DEB
  Standard_Real                 UOnCurve = 0.;
#else
  Standard_Real                 UOnCurve;
#endif
  Geom2dAPI_ProjectPointOnCurve Proj(P,curve,
				     curve->FirstParameter(),curve->LastParameter());
  if (Proj.NbPoints() > 0) {
    UOnCurve = Proj.LowerDistanceParameter();
  }
  return LinkCurveBis(UOnCurve);
}


//=============================================================================
//function : Indent
// purpose : 
//=============================================================================
static void Indent(const Standard_Integer Offset) {
  if (Offset > 0) {
    for (Standard_Integer i = 0; i < Offset; i++) {cout << " ";}
  }
}

//=============================================================================
//function : Init
// purpose : 
//=============================================================================
void Bisector_BisecPC::Init (const Handle_Geom2d_Curve&    Curve, 
			     const gp_Pnt2d&               Point, 
			     const Standard_Real           Sign, 
			     const TColStd_SequenceOfReal& StartIntervals, 
			     const TColStd_SequenceOfReal& EndIntervals, 
			     const Standard_Integer        BisInterval, 
			     const Standard_Integer        CurrentInterval, 
			     const Standard_Real           ShiftParameter, 
			     const Standard_Real           DistMax, 
			     const Standard_Boolean        IsEmpty, 
			     const Standard_Boolean        IsConvex, 
			     const Standard_Boolean        ExtensionStart, 
			     const Standard_Boolean        ExtensionEnd, 
			     const gp_Pnt2d&               PointStartBis, 
			     const gp_Pnt2d&               PointEndBis)
{
  curve           = Curve;
  point           = Point; 
  sign            = Sign ;
  startIntervals  = StartIntervals; 
  endIntervals    = EndIntervals;
  bisInterval     = BisInterval;
  currentInterval = CurrentInterval;
  shiftParameter  = ShiftParameter;
  distMax         = DistMax;
  isEmpty         = IsEmpty;
  isConvex        = IsConvex;
  extensionStart  = ExtensionStart;
  extensionEnd    = ExtensionEnd;
  pointStartBis   = PointStartBis;
  pointEndBis     = PointEndBis;   
}

//=============================================================================
//function : Dump
// purpose : 
//=============================================================================
//void Bisector_BisecPC::Dump(const Standard_Integer Deep, 
void Bisector_BisecPC::Dump(const Standard_Integer , 
			    const Standard_Integer Offset) const 
{
  Indent (Offset);
  cout <<"Bisector_BisecPC :"<<endl;
  Indent (Offset);
  cout <<"Point :"<<endl;
  cout <<" X = "<<point.X()<<endl;
  cout <<" Y = "<<point.Y()<<endl;
  cout <<"Sign  :"<<sign<<endl;
  cout <<"Number Of Intervals :"<<startIntervals.Length()<<endl;
  for (Standard_Integer i = 1; i <= startIntervals.Length(); i++) {
    cout <<"Interval number :"<<i<<"Start :"<<startIntervals.Value(i)
                                 <<"  end :"<<  endIntervals.Value(i)<<endl ;
  }
  cout <<"Index Current Interval :"<<currentInterval<<endl;
}