summaryrefslogtreecommitdiff
path: root/src/IntCurve/IntCurve_IntConicConic_1.cxx
blob: 275e849275b3bd9436e88b2621d3e57792550a69 (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
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
// File:	IntCurve_IntConicConic_1.cxx
// Created:	Wed May  6 16:00:06 1992
// Author:	Laurent BUCHARD
//		<lbr@topsn3>
// a modifier le cas de 2 points confondus ( Insert a la place d'append ? ) 

#include <IntCurve_IntConicConic.jxx>

#include <IntCurve_IConicTool.hxx>
#include <IntCurve_PConic.hxx>
#include <IntRes2d_Domain.hxx>
#include <gp.hxx>
#include <IntCurve_IntConicConic_Tool.hxx>
#include <IntImpParGen.hxx>
#include <IntCurve_IntConicConic_1.hxx>
#include <ElCLib.hxx>
#include <Standard_ConstructionError.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntRes2d_IntersectionSegment.hxx>

#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
#include <Precision.hxx>

Standard_Boolean Affichage=Standard_False;
Standard_Boolean AffichageGraph=Standard_True;

//modified by NIZHNY-MKK  Tue Feb 15 10:53:34 2000.BEGIN
// #define TOLERANCE_ANGULAIRE 0.00000001
#define TOLERANCE_ANGULAIRE 1.e-15 //the reason is at least to make an accordance between transition and position computation.
//modified by NIZHNY-MKK  Tue Feb 15 10:53:45 2000.END

const Standard_Real PIsur2 = 0.5*PI;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IntRes2d_Position FindPositionLL(Standard_Real&,const IntRes2d_Domain&);
const IntRes2d_IntersectionPoint SegmentToPoint( const IntRes2d_IntersectionPoint& Pa
						,const IntRes2d_Transition& T1a
						,const IntRes2d_Transition& T2a
						,const IntRes2d_IntersectionPoint& Pb
						,const IntRes2d_Transition& T1b
						,const IntRes2d_Transition& T2b);  
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ProjectOnC2AndIntersectWithC2Domain(const gp_Circ2d& Circle1
                                         ,const gp_Circ2d& Circle2
					 ,PeriodicInterval& C1DomainAndRes
					 ,PeriodicInterval& DomainC2
					 ,PeriodicInterval* SolutionC1
					 ,PeriodicInterval* SolutionC2
					 ,Standard_Integer &NbSolTotal
					 ,const Standard_Boolean IdentCircles)
{
  
  if(C1DomainAndRes.IsNull()) return;
  //-------------------------------------------------------------------------
  //--  On cherche l intervalle correspondant sur C2
  //--  Puis on intersecte l intervalle avec le domaine de C2
  //--  Enfin, on cherche l intervalle correspondant sur C1
  //--
  Standard_Real C2inf = 
    ElCLib::CircleParameter(Circle2.Axis()
			    ,ElCLib::CircleValue(C1DomainAndRes.Binf
						 ,Circle1.Axis(),Circle1.Radius()));
  Standard_Real C2sup = 
    ElCLib::CircleParameter(Circle2.Axis()
			    ,ElCLib::CircleValue(C1DomainAndRes.Bsup
						 ,Circle1.Axis(),Circle1.Radius()));

  PeriodicInterval C2Inter(C2inf,C2sup);

  if(!IdentCircles) {
    if(C2Inter.Length() > PI)
      C2Inter.Complement();
  }
  else {
    if(C2sup<=C2inf) C2sup+=PIpPI;
    if(C2inf>=PIpPI) {
      C2sup-=PIpPI;
      C2inf-=PIpPI;
    }
    C2Inter.Binf=C2inf;
    C2Inter.Bsup=C2sup; //--- Verifier la longueur de l'intervalle sur C2
    C2Inter.Bsup=C2inf+C1DomainAndRes.Bsup-C1DomainAndRes.Binf;
  }
  
  PeriodicInterval C2InterAndDomain[2];
  
  for(Standard_Integer i=0; i<2 ; i++) {
    C2InterAndDomain[i]=(i==0)?  DomainC2.FirstIntersection(C2Inter)
                               : DomainC2.SecondIntersection(C2Inter);
  
    if(!C2InterAndDomain[i].IsNull()) {

      Standard_Real C1inf = 
	ElCLib::CircleParameter(Circle1.Axis()
				,ElCLib::CircleValue(C2InterAndDomain[i].Binf
					,Circle2.Axis(),Circle2.Radius()));
      Standard_Real C1sup = 
	ElCLib::CircleParameter(Circle1.Axis()
				,ElCLib::CircleValue(C2InterAndDomain[i].Bsup
					,Circle2.Axis(),Circle2.Radius()));

      SolutionC1[NbSolTotal]=PeriodicInterval(C1inf,C1sup);
      if(!IdentCircles) {
	if(SolutionC1[NbSolTotal].Length() > PI)
	  SolutionC1[NbSolTotal].Complement();
      }
      else {
	if(SolutionC1[NbSolTotal].Bsup <= SolutionC1[NbSolTotal].Binf) {
	  SolutionC1[NbSolTotal].Bsup+=PIpPI;
	}
	if(SolutionC1[NbSolTotal].Binf>=PIpPI) {
	  SolutionC1[NbSolTotal].Binf-=PIpPI;
	  SolutionC1[NbSolTotal].Bsup-=PIpPI;	  
	}
      }
      SolutionC2[NbSolTotal]=C2InterAndDomain[i];
      NbSolTotal++;
    }
  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void CircleCircleGeometricIntersection(const gp_Circ2d& C1
				       ,const gp_Circ2d& C2
				       ,const Standard_Real Tol
				       ,const Standard_Real TolTang
				       ,PeriodicInterval& C1_Res1
				       ,PeriodicInterval& C1_Res2
				       ,Standard_Integer& nbsol) {
  
  Standard_Real C1_binf1,C1_binf2=0,C1_bsup1,C1_bsup2=0;
  Standard_Real dO1O2=(C1.Location()).Distance(C2.Location());
  Standard_Real R1=C1.Radius();
  Standard_Real R2=C2.Radius();
  Standard_Real AbsR1mR2=Abs(R1-R2);
  //---------------------------------------------------------------- 
  if(dO1O2 > (R1+R2+Tol)) {
    if(dO1O2 > (R1+R2+TolTang)) { 
      nbsol=0; 
      return; 
    }
    else { 
      C1_binf1 = 0.0;
      C1_bsup1 = 0.0;
      nbsol = 1;
    }
  }
  //---------------------------------------------------------------- 
  else if(dO1O2 <= Tol  &&  AbsR1mR2<=Tol)  { 
    nbsol=3; 
    return; 
  }
  else { 
    //---------------------------------------------------------------- 
    Standard_Real R1pR2=R1+R2;
    Standard_Real R1pTol=R1+Tol;
    Standard_Real R1mTol=R1-Tol;
//    Standard_Real R1R1=R1*R1;
    Standard_Real R2R2=R2*R2;
    Standard_Real R1pTolR1pTol=R1pTol*R1pTol;
    Standard_Real R1mTolR1mTol=R1mTol*R1mTol;
    Standard_Real dO1O2dO1O2=dO1O2*dO1O2;
    Standard_Real dAlpha1;
    //--------------------------------------------------------------- Cas 
    //-- C2 coupe le cercle C1+ (=C(x1,y1,R1+Tol))
    //--            1 seul segment donne par Inter C2 C1+
    //--
    if(dO1O2 > R1pR2-Tol) { 
      Standard_Real dx=(R1pTolR1pTol+dO1O2dO1O2-R2R2)/(dO1O2+dO1O2);
      Standard_Real dy=(R1pTolR1pTol-dx*dx);
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      dAlpha1=ATan2(dy,dx);
      
      C1_binf1=-dAlpha1;  
      C1_bsup1=dAlpha1;
      nbsol=1;
    }
    //--------------------------------------------------------------------
    //--           2 segments donnes par Inter C2 avec C1- C1 C1+
    //-- Seul le signe de dx change si dO1O2 < Max(R1,R2)
    //-- 
    else if(dO1O2 > AbsR1mR2-Tol) {  // -- + 
      //------------------- Intersection C2 C1+ --------------------------
      Standard_Real dx=(R1pTolR1pTol+dO1O2dO1O2-R2R2)/(dO1O2+dO1O2);
      Standard_Real dy=(R1pTolR1pTol-dx*dx); 
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      
      dAlpha1=ATan2(dy,dx);
      C1_binf1=-dAlpha1;  C1_bsup2=dAlpha1;  //--  |...?     ?...|   Sur C1
      
      //------------------ Intersection C2 C1- -------------------------
      dx=(R1mTolR1mTol+dO1O2dO1O2-R2R2)/(dO1O2+dO1O2);
      dy=(R1mTolR1mTol-dx*dx);
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      dAlpha1=ATan2(dy,dx);
      
      C1_binf2=dAlpha1;  C1_bsup1=-dAlpha1;  //--  |...x     x...|   Sur C1
      nbsol=2;    
      //------------------------------
      //-- Les 2 intervalles sont ils 
      //-- en fait un seul inter ? 
      //-- 
      if(dy==0) {    //-- Les 2 bornes internes sont identiques 
	C1_bsup1 = C1_bsup2; 
	nbsol = 1;
      }
      else { 
	if(C1_binf1>C1_bsup1) { 
	  dAlpha1 = C1_binf1; C1_binf1 = C1_bsup1; C1_bsup1 = dAlpha1; 
	}
	if(C1_binf2>C1_bsup2) { 
	  dAlpha1 = C1_binf2; C1_binf2 = C1_bsup2; C1_bsup2 = dAlpha1; 
	}
	if(   ((C1_binf1<=C1_bsup2) && (C1_binf1>=C1_binf2))
	   || ((C1_bsup1<=C1_bsup2) && (C1_bsup1>=C1_binf2))) { 
	  if(C1_binf1 > C1_binf2) C1_binf1 = C1_binf2;
	  if(C1_binf1 > C1_bsup2) C1_binf1 = C1_bsup2;
	  if(C1_bsup1 < C1_binf2) C1_bsup1 = C1_binf2;
	  if(C1_bsup1 < C1_bsup2) C1_bsup1 = C1_bsup2;
	  nbsol=1;
	}
      }
    }
    //--------------------------------------------------------------
    //--    1 seul segment donne par Inter C2 avec C1- ou C1+
    else if(dO1O2 > AbsR1mR2-Tol) {
      
      Standard_Real dx=(R1mTolR1mTol+dO1O2dO1O2-R2R2)/(dO1O2+dO1O2);
      Standard_Real dy=(R1mTolR1mTol-dx*dx);
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      dAlpha1=ATan2(dy,dx);
      
      dx=(R1pTolR1pTol+dO1O2dO1O2-R2R2)/(dO1O2+dO1O2);
      dy=(R1pTolR1pTol-dx*dx);
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      Standard_Real dAlpha2=ATan2(dy,dx);
      
      if(dAlpha2>dAlpha1) dAlpha1 = dAlpha2;
      C1_binf1=-dAlpha1;  C1_bsup1=dAlpha1;
      nbsol=1;
    }
    //--------------------------------------------------------------
    else {
      if((dO1O2 > AbsR1mR2-TolTang) && (AbsR1mR2-TolTang)>0.0) { 
	C1_binf1=0.0;  
	C1_bsup1=0.0;
	nbsol = 1;
      }
      else { 
	nbsol=0; return ;
      }
    }
  }

  //-- cout<<" C1_binf1:"<<C1_binf1;
  //-- cout<<" C1_bsup1:"<<C1_bsup1;
  //-- cout<<" C1_binf2:"<<C1_binf2;
  //-- cout<<" C1_bsup2:"<<C1_bsup2<<endl;
  //----------------------------------------------------------------
  //-- Mise en forme des resultats : 
  //--    Les calculs ont ete fait dans le repere x1,y1, (O1,O2)
  //--    On se ramene au repere propre a C1

  gp_Vec2d Axe1=C1.XAxis().Direction();
  gp_Vec2d AxeO1O2=gp_Vec2d(C1.Location(),C2.Location());
  
  Standard_Real dAngle1;
  if(AxeO1O2.Magnitude() <= gp::Resolution()) 
    dAngle1=Axe1.Angle(C2.XAxis().Direction());
  else
    dAngle1=Axe1.Angle(AxeO1O2);

  if(C1.IsDirect() == Standard_False) { 
    dAngle1 = -dAngle1; 
  }


  C1_binf1+=dAngle1;  C1_bsup1+=dAngle1;
  
  //-- par construction aucun des segments ne peut exceder PI
  //-- (permet de ne pas gerer trop de cas differents)

  C1_Res1.SetValues(C1_binf1,C1_bsup1);
  if(C1_Res1.Length() > PI) C1_Res1.Complement();

  if(nbsol==2) {
    C1_binf2+=dAngle1;  C1_bsup2+=dAngle1;
    C1_Res2.SetValues(C1_binf2,C1_bsup2);
    if(C1_Res2.Length() > PI) C1_Res2.Complement();
  }
  else {
    C1_Res2.SetNull(); 
  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ProjectOnLAndIntersectWithLDomain(const gp_Circ2d& Circle
				       ,const gp_Lin2d& Line
				       ,PeriodicInterval& CDomainAndRes
				       ,Interval& LDomain
				       ,PeriodicInterval* CircleSolution
				       ,Interval* LineSolution
				       ,Standard_Integer &NbSolTotal
				       ,const IntRes2d_Domain& RefLineDomain
//				       ,const IntRes2d_Domain& )
				       ,const IntRes2d_Domain& )
{
  
  
  if(CDomainAndRes.IsNull()) return;
  //-------------------------------------------------------------------------
  //--  On cherche l intervalle correspondant sur C2
  //--  Puis on intersecte l intervalle avec le domaine de C2
  //--  Enfin, on cherche l intervalle correspondant sur C1
  //--

  Standard_Real Linf=ElCLib::Parameter(Line
			     ,ElCLib::CircleValue(CDomainAndRes.Binf
						 ,Circle.Axis()
						 ,Circle.Radius()));
  Standard_Real Lsup=ElCLib::Parameter(Line
			     ,ElCLib::CircleValue(CDomainAndRes.Bsup
						 ,Circle.Axis()
						 ,Circle.Radius()));

  Interval LInter(Linf,Lsup);   //-- Necessairement Borne 
  
  Interval LInterAndDomain=LDomain.IntersectionWithBounded(LInter);

  if(!LInterAndDomain.IsNull) {

    Standard_Real DomLinf = (RefLineDomain.HasFirstPoint())? RefLineDomain.FirstParameter() : -Precision::Infinite();
    Standard_Real DomLsup = (RefLineDomain.HasLastPoint())? RefLineDomain.LastParameter() : Precision::Infinite();
    
    Linf = LInterAndDomain.Binf;
    Lsup = LInterAndDomain.Bsup;

    if(Linf<DomLinf) {
      Linf = DomLinf; 
    }
    if(Lsup<DomLinf) { 
      Lsup = DomLinf; 
    }
    
    if(Linf>DomLsup) {
      Linf = DomLsup; 
    }
    if(Lsup>DomLsup) { 
      Lsup = DomLsup; 
    }
  
    LInterAndDomain.Binf = Linf;
    LInterAndDomain.Bsup = Lsup;

#if 0     
    Standard_Real Cinf = 
      ElCLib::CircleParameter(Circle.Axis()					       
			      ,ElCLib::LineValue(LInterAndDomain.Binf,
					Line.Position()));
    Standard_Real Csup = 
      ElCLib::CircleParameter(Circle.Axis()
			      ,ElCLib::LineValue(LInterAndDomain.Bsup
					,Line.Position()));

    if(Cinf<CDomainAndRes.Binf) Cinf = CDomainAndRes.Binf;
    if(Csup>CDomainAndRes.Bsup) Csup = CDomainAndRes.Bsup;
#else
    Standard_Real Cinf=CDomainAndRes.Binf;
    Standard_Real Csup=CDomainAndRes.Bsup;
#endif
    if(Cinf>=Csup) { Cinf = CDomainAndRes.Binf; Csup = CDomainAndRes.Bsup; } 
    CircleSolution[NbSolTotal]=PeriodicInterval(Cinf,Csup);
    if(CircleSolution[NbSolTotal].Length() > PI)
      CircleSolution[NbSolTotal].Complement();
    
    LineSolution[NbSolTotal]=LInterAndDomain;
    NbSolTotal++;
  }
}

//=======================================================================
//function : LineCircleGeometricIntersection
//purpose  : 
//~~ On cherche des segments d intersection dans le `tuyau` 
//~~   R+Tol   R-Tol  ( Tol est TolConf : Tolerance de confusion d arc)
//~~ On Cherche un point d intersection a une distance TolTang du cercle.   
//=======================================================================
void LineCircleGeometricIntersection(const gp_Lin2d& Line,
				     const gp_Circ2d& Circle,
				     const Standard_Real Tol,
				     const Standard_Real TolTang,
				     PeriodicInterval& CInt1,
				     PeriodicInterval& CInt2,
				     Standard_Integer& nbsol) 
{
  

  Standard_Real dO1O2=Line.Distance(Circle.Location());
  Standard_Real R=Circle.Radius();
  Standard_Real RmTol=R-Tol;
  Standard_Real binf1,binf2=0,bsup1,bsup2=0;
    
  //---------------------------------------------------------------- 
  if(dO1O2 > (R+Tol))  {  //-- pas d intersection avec le 'tuyau'
    if(dO1O2 > (R+TolTang)) {  
      nbsol=0; 
      return;
    }
    else { 
      binf1=0.0;  
      bsup1=0.0;
      nbsol=1;
    }
  }
  else { 
    //---------------------------------------------------------------- 
    Standard_Boolean b2Sol;
    Standard_Real dAlpha1;
    //---------------------------------------------------------------
    //-- Line coupe le cercle Circle+ (=C(x1,y1,R1+Tol))
    //modified by NIZNHY-PKV Thu May 12 12:25:17 2011f
    b2Sol=Standard_False;
    if (R>dO1O2+TolTang) {
      Standard_Real aX2, aTol2;
      //
      aTol2=Tol*Tol;
      aX2=4.*(R*R-dO1O2*dO1O2);
      if (aX2>aTol2) {
	b2Sol=!b2Sol;
      }
    }
    if(dO1O2 > RmTol && !b2Sol) { 
    //if(dO1O2 > RmTol) { 
    //modified by NIZNHY-PKV Thu May 12 12:25:20 2011t
      Standard_Real dx=dO1O2;
      Standard_Real dy=0.0;     //(RpTol*RpTol-dx*dx); //Patch !!!
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      dAlpha1=ATan2(dy,dx);
      
      binf1=-dAlpha1;  
      bsup1=dAlpha1;
      nbsol=1;
    }  
    //--------------------------------------------------------------------
    //--           2 segments donnes par Inter Line avec Circle-  Circle+
    //-- 
    else {
      //------------------- Intersection Line Circle+ --------------------------
      Standard_Real dx=dO1O2;
      Standard_Real dy=R*R-dx*dx;    //(RpTol*RpTol-dx*dx); //Patch !!!
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      
      dAlpha1=ATan2(dy,dx);
      binf1=-dAlpha1;  bsup2=dAlpha1;  //--  |...?     ?...|   Sur C1
      
      //------------------ Intersection Line Circle-  -------------------------
      dy=R*R-dx*dx;                  //(RmTol*RmTol-dx*dx); //Patch !!!
      dy=(dy>=0.0)? Sqrt(dy) : 0.0;
      dAlpha1=ATan2(dy,dx);
      
      binf2=dAlpha1;  bsup1=-dAlpha1;  //--  |...x     x...|   Sur C1

      if((dAlpha1*R)<(Max(Tol,TolTang))) { 
	bsup1 = bsup2; 
	nbsol = 1;
      }
      else { 
	nbsol=2;
      }
    }
  }
  //--------------------------------------------------------------
  //-- Mise en forme des resultats : 
  //--    Les calculs ont ete fait dans le repere x1,y1, (O1,O2)
  //--    On se ramene au repere propre a C1
  
  Standard_Real dAngle1=(Circle.XAxis().Direction()).Angle(Line.Direction());
  
#if 0 
  //---------------------------------------------
  //-- Si le cercle est indirect alors l origine
  //-- est vue en -dAngle1. 
  //--
  if(Circle.IsDirect() == Standard_False) { 
    dAngle1 = -dAngle1;
  }
#endif  
  
  
  Standard_Real a,b,c,d;
  Line.Coefficients(a,b,c);
  
  d = a*Circle.Location().X() + b*Circle.Location().Y() + c;
  
  if(d>0.0)  dAngle1+= PIsur2;
  else       dAngle1-= PIsur2;

     
  if(dAngle1<0.0) dAngle1+=PIpPI;
  else if(dAngle1>PIpPI) dAngle1-=PIpPI;
  
  
  binf1+=dAngle1;  bsup1+=dAngle1;
  
  //-- par construction aucun des segments ne peut exceder PI
  //-- (permet de ne pas gerer trop de cas differents)
  
  if(Circle.IsDirect() == Standard_False) {
    Standard_Real t=binf1; binf1=bsup1; bsup1=t;
    binf1 = -binf1;
    bsup1 = -bsup1;
  }


  CInt1.SetValues(binf1,bsup1);
  if(CInt1.Length() > PI) CInt1.Complement();
  

  if(nbsol==2) {
    binf2+=dAngle1;  bsup2+=dAngle1;

    if(Circle.IsDirect() == Standard_False) {
      Standard_Real t=binf2; binf2=bsup2; bsup2=t;
      binf2 = -binf2;
      bsup2 = -bsup2;
    }

    CInt2.SetValues(binf2,bsup2);
    if(CInt2.Length() > PI) CInt2.Complement();
  }
//  Modified by Sergey KHROMOV - Thu Oct 26 17:51:05 2000 Begin
  else {
    if (CInt1.Bsup > PIpPI && CInt1.Binf < PIpPI) {
      nbsol = 2;
      binf2 = CInt1.Binf;
      bsup2 = PIpPI;
      binf1 = 0.;
      CInt1.SetValues(binf1,CInt1.Bsup - PIpPI);
      if(CInt1.Length() > PI) CInt1.Complement();
      CInt2.SetValues(binf2,bsup2);
      if(CInt2.Length() > PI) CInt2.Complement();
    }
  }
//  Modified by Sergey KHROMOV - Thu Oct 26 17:51:13 2000 End
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void DomainIntersection(const IntRes2d_Domain& Domain
			,const Standard_Real U1inf
			,const Standard_Real U1sup
			,Standard_Real& Res1inf
			,Standard_Real& Res1sup
			,IntRes2d_Position& PosInf
			,IntRes2d_Position& PosSup) {
  
  if(Domain.HasFirstPoint()) {
    if(U1sup < (Domain.FirstParameter()-Domain.FirstTolerance())) {
      Res1inf=1; Res1sup=-1; 
      return;
    }
    if(U1inf>(Domain.FirstParameter()+Domain.FirstTolerance())) {
      Res1inf=U1inf;
      PosInf=IntRes2d_Middle;
    }
    else {
      Res1inf=Domain.FirstParameter(); 
      PosInf=IntRes2d_Head;
    }
  }
  else {
    Res1inf=U1inf; 
    PosInf=IntRes2d_Middle;
  }
  
  if(Domain.HasLastPoint()) {
    if(U1inf >(Domain.LastParameter()+Domain.LastTolerance())) {
      Res1inf=1; Res1sup=-1;
      return;
    }
    if(U1sup<(Domain.LastParameter()-Domain.LastTolerance())) {
      Res1sup=U1sup; 
      PosSup=IntRes2d_Middle;
    }
    else {
      Res1sup=Domain.LastParameter();
      PosSup=IntRes2d_End;
    }
  }
  else {
    Res1sup=U1sup;
    PosSup=IntRes2d_Middle;
  }
  //-- Si un des points est en bout ,
  //-- on s assure que les parametres sont corrects
  if(Res1inf>Res1sup) { 
    if(PosSup==IntRes2d_Middle) {
      Res1sup=Res1inf;
    }
    else {
      Res1inf=Res1sup;
    }
  }
  //--- Traitement des cas ou une intersection vraie est dans la tolerance
  //--  d un des bouts
  if(PosInf==IntRes2d_Head) {
    if(Res1sup <= (Res1inf+Domain.FirstTolerance())) {
      Res1sup=Res1inf;
      PosSup=IntRes2d_Head;
    }
  }
  if(PosSup==IntRes2d_End) {
    if(Res1inf >= (Res1sup-Domain.LastTolerance())) {
      Res1inf=Res1sup;
      PosInf=IntRes2d_End;
    }
  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void LineLineGeometricIntersection(const gp_Lin2d& L1
				   ,const gp_Lin2d& L2
				   ,const Standard_Real Tol
				   ,Standard_Real& U1
				   ,Standard_Real& U2
				   ,Standard_Real& SinDemiAngle
				   ,Standard_Integer& nbsol) {
  
  Standard_Real U1x=L1.Direction().X();
  Standard_Real U1y=L1.Direction().Y();
  Standard_Real U2x=L2.Direction().X();
  Standard_Real U2y=L2.Direction().Y();
  Standard_Real Uo21x = L2.Location().X() - L1.Location().X();
  Standard_Real Uo21y = L2.Location().Y() - L1.Location().Y();
  
  Standard_Real D=U1y*U2x-U1x*U2y;

//modified by NIZHNY-MKK  Tue Feb 15 10:54:04 2000.BEGIN
//   if(Abs(D)<1e-15) { //-- Droites //
  if(Abs(D) < TOLERANCE_ANGULAIRE) {
//modified by NIZHNY-MKK  Tue Feb 15 10:54:11 2000.END
    D=U1y*Uo21x - U1x*Uo21y;
    nbsol=(Abs(D)<=Tol)? 2 : 0;
  }
  else {
    U1=(Uo21y * U2x - Uo21x * U2y)/D;
    U2=(Uo21y * U1x - Uo21x * U1y)/D;
    
    //------------------- Calcul du Sin du demi angle  entre L1 et L2
    //---- 
    if(D<0.0) D=-D;
    if(D>1.0) D=1.0;                      //-- Deja vu !
    SinDemiAngle=Sin(0.5*ASin(D));
    nbsol=1;
  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*IntCurve_IntConicConic::IntCurve_IntConicConic(const gp_Lin2d& L1
					       ,const IntRes2d_Domain& D1
					       ,const gp_Lin2d& L2
					       ,const IntRes2d_Domain& D2
					       ,const Standard_Real TolConf
					       ,const Standard_Real Tol)  {
  Perform(L1,D1,L2,D2,TolConf,Tol);
}


IntCurve_IntConicConic::IntCurve_IntConicConic(const gp_Lin2d& L1
					       ,const IntRes2d_Domain& D1
					       ,const gp_Circ2d& C2
					       ,const IntRes2d_Domain& D2
					       ,const Standard_Real TolConf
					       ,const Standard_Real Tol) {
  
  Perform(L1,D1,C2,D2,TolConf,Tol);
}


IntCurve_IntConicConic::IntCurve_IntConicConic(const gp_Circ2d& C1
                                              ,const IntRes2d_Domain& D1
                                              ,const gp_Circ2d& C2
                                              ,const IntRes2d_Domain& D2
					      ,const Standard_Real TolConf
                                              ,const Standard_Real Tol) {
  SetReversedParameters(Standard_False);
  Perform(C1,D1,C2,D2,TolConf,Tol);
}*/ //amv OCC12547
//----------------------------------------------------------------------
void IntCurve_IntConicConic::Perform(const gp_Circ2d& Circle1
				,const IntRes2d_Domain& DomainCirc1
				,const gp_Circ2d& _Circle2
				,const IntRes2d_Domain& _DomainCirc2
				,const Standard_Real TolConf,const Standard_Real Tol) {


//-- TRES TRES MAL FAIT    A REPRENDRE UN JOUR ....   (lbr Octobre 98) 
  gp_Circ2d Circle2=_Circle2;
  IntRes2d_Domain  DomainCirc2=_DomainCirc2;
  Standard_Boolean IndirectCircles=Standard_False;
  if(Circle1.IsDirect() != _Circle2.IsDirect()) { 
    IndirectCircles=Standard_True;
    Circle2=_Circle2.Reversed();
    DomainCirc2.SetValues(_DomainCirc2.LastPoint(),
			  PIpPI-_DomainCirc2.LastParameter(),
			  _DomainCirc2.LastTolerance(),
			  _DomainCirc2.FirstPoint(),
			  PIpPI-_DomainCirc2.FirstParameter(),
			  _DomainCirc2.FirstTolerance());
    DomainCirc2.SetEquivalentParameters(0.0,PIpPI);
  }
  
  this->ResetFields();
  Standard_Integer nbsol=0;
  PeriodicInterval C1_Int1,C1_Int2;

  //------- Intersection sans tenir compte du domaine  ----> nbsol=0,1,2,3 
  CircleCircleGeometricIntersection(Circle1,Circle2,TolConf,Tol,C1_Int1,C1_Int2,nbsol);
  done=Standard_True;

  if(nbsol==0) { //-- Pas de solutions 
    return;
  }

  PeriodicInterval C1Domain(DomainCirc1); 
  //-- On se ramene entre 0 et 2PI
  Standard_Real deltat = C1Domain.Bsup-C1Domain.Binf;
  if(deltat>=PIpPI) { deltat=PIpPI-1e-14; } 
  
  while(C1Domain.Binf >= PIpPI) C1Domain.Binf-=PIpPI;
  while(C1Domain.Binf <  0.0)   C1Domain.Binf+=PIpPI;
  C1Domain.Bsup=C1Domain.Binf+deltat;

  PeriodicInterval C2Domain(DomainCirc2); 
  deltat = C2Domain.Bsup-C2Domain.Binf;
  if(deltat>=PIpPI) { deltat=PIpPI-1e-14; } 

  while(C2Domain.Binf >= PIpPI) C2Domain.Binf-=PIpPI;
  while(C2Domain.Binf <  0.0)   C2Domain.Binf+=PIpPI;
  C2Domain.Bsup=C2Domain.Binf+deltat;

  Standard_Boolean IdentCircles=Standard_False;

  if(nbsol>2) {       
    //-- Les 2 cercles sont confondus a Tol pres
    C1_Int1.SetValues(0,PIpPI);
    C1_Int2.SetNull(); 
    //---------------------------------------------------------------
    //-- Flag utilise pour specifier que les intervalles manipules
    //--   peuvent etre de longueur superieure a pi. 
    //-- Pour des cercles non identiques, on a necessairement cette
    //--   condition sur les resultats de l intersection geometrique
    //--   ce qui permet de normaliser rapidement les intervalles.
    //--   ex: -1 4 -> longueur > PI  
    //--        donc -1 4 devient  4 , 2*pi-1
    //---------------------------------------------------------------
    IdentCircles=Standard_True;
  }

  Standard_Integer NbSolTotal=0;
  PeriodicInterval SolutionC1[4];
  PeriodicInterval SolutionC2[4];
  
  //----------------------------------------------------------------------
  //----------- Traitement du premier intervalle Geometrique  C1_Int1 ----
  //----------------------------------------------------------------------
  //-- NbSolTotal est incremente a chaque Intervalle solution.
  //-- On stocke les intervalles dans les tableaux : SolutionC1(C2)
  //-- Dimensionnes a 4 elements.
  //-- des Exemples faciles donnent 3 Intersections
  //-- des Problemes numeriques peuvent en donner 4 ??????
  //--
  PeriodicInterval C1DomainAndRes=C1Domain.FirstIntersection(C1_Int1);
  
  ProjectOnC2AndIntersectWithC2Domain(Circle1,Circle2
				      ,C1DomainAndRes
				      ,C2Domain
				      ,SolutionC1,SolutionC2
				      ,NbSolTotal
				      ,IdentCircles);
  //----------------------------------------------------------------------
  //-- Seconde Intersection :  Par exemple :     2*PI-1  2*PI+1
  //--                         Intersecte avec     0.5   2*PI-0.5
  //--     Donne les intervalles : 0.5,1    et  2*PI-1,2*PI-0.5
  //--
  C1DomainAndRes=C1Domain.SecondIntersection(C1_Int1);
  
  ProjectOnC2AndIntersectWithC2Domain(Circle1,Circle2
				      ,C1DomainAndRes
				      ,C2Domain
				      ,SolutionC1,SolutionC2
				      ,NbSolTotal
				      ,IdentCircles);

  //----------------------------------------------------------------------
  //----------- Traitement du second intervalle Geometrique   C1_Int2 ----
  //----------------------------------------------------------------------
  if(nbsol==2) {
    C1DomainAndRes=C1Domain.FirstIntersection(C1_Int2);
    
    ProjectOnC2AndIntersectWithC2Domain(Circle1,Circle2
					,C1DomainAndRes
					,C2Domain
					,SolutionC1,SolutionC2
					,NbSolTotal
					,IdentCircles);
    //--------------------------------------------------------------------
    C1DomainAndRes=C1Domain.SecondIntersection(C1_Int2);
    
    ProjectOnC2AndIntersectWithC2Domain(Circle1,Circle2
					,C1DomainAndRes
					,C2Domain
					,SolutionC1,SolutionC2
					,NbSolTotal
					,IdentCircles);
  }
  //----------------------------------------------------------------------
  //-- Calcul de toutes les transitions et Positions.
  //--
  //----------------------------------------------------------------------
  //-- On determine si des intervalles sont reduit a des points 
  //--      ( Rayon * Intervalle.Length()    <    Tol   )
  //--
  Standard_Real R1=Circle1.Radius();
  Standard_Real R2=Circle2.Radius();
  Standard_Real Tol2=Tol+Tol;     //---- Pour eviter de toujours retourner
                                  //des segments
  Standard_Integer i ;
  if(Tol < (1e-10)) Tol2 = 1e-10; 
  for( i=0; i<NbSolTotal ; i++) { 
    if(((R1 * SolutionC1[i].Length()))<=Tol2 
       && ((R2 * SolutionC2[i].Length()))<=Tol2) {
      
      Standard_Real t=(SolutionC1[i].Binf+SolutionC1[i].Bsup)*0.5;
      SolutionC1[i].Binf=SolutionC1[i].Bsup=t;
      
      t=(SolutionC2[i].Binf+SolutionC2[i].Bsup)*0.5;
      SolutionC2[i].Binf=SolutionC2[i].Bsup=t;
    }
  }

  //----------------------------------------------------------------------
  //-- Traitement des intervalles (ou des points obtenus)
  //-- 
  gp_Ax22d Axis2C1=Circle1.Axis();
  gp_Ax22d Axis2C2=Circle2.Axis();
  gp_Pnt2d P1a,P1b,P2a,P2b;
  gp_Vec2d Tan1,Tan2,Norm1,Norm2;
  IntRes2d_Transition T1a,T1b,T2a,T2b;
  IntRes2d_Position Pos1a,Pos1b,Pos2a,Pos2b;

  Standard_Boolean Opposite=((Circle1.Location().SquareDistance(Circle2.Location()))
		   >(R1*R1+R2*R2))? Standard_True : Standard_False;

  //if(Circle1.IsDirect()) { cout<<" C1 Direct"<<endl; } else { cout<<" C1 INDirect"<<endl; }
  //if(Circle2.IsDirect()) { cout<<" C2 Direct"<<endl; } else { cout<<" C2 INDirect"<<endl; }

  for(i=0; i<NbSolTotal; i++) {
    Standard_Real C2inf=(Opposite)? SolutionC2[i].Bsup : SolutionC2[i].Binf;
    Standard_Real C2sup=(Opposite)? SolutionC2[i].Binf : SolutionC2[i].Bsup;

    Standard_Real C1inf=NormalizeOnCircleDomain(SolutionC1[i].Binf,DomainCirc1);
    C2inf=NormalizeOnCircleDomain(C2inf,DomainCirc2);

    if(IndirectCircles) { 
      
      ElCLib::CircleD2(C1inf,Axis2C1,R1,P1a,Tan1,Norm1); 
      ElCLib::CircleD2(C2inf,Axis2C2,R2,P2a,Tan2,Norm2);
      Tan2.Reverse();
      
      IntImpParGen::DeterminePosition(Pos1a,DomainCirc1,P1a,C1inf);
      IntImpParGen::DeterminePosition(Pos2a,_DomainCirc2,P2a,PIpPI-C2inf);
      Determine_Transition_LC(Pos1a,Tan1,Norm1,T1a , Pos2a,Tan2,Norm2,T2a, Tol);
      
      
      IntRes2d_IntersectionPoint NewPoint1(P1a,C1inf,PIpPI-C2inf,T1a,T2a,Standard_False);
      
      if((SolutionC1[i].Length()>0.0 ) || (SolutionC2[i].Length() >0.0)) {
	//-- On traite un intervalle non reduit a un point
	Standard_Real C1sup=NormalizeOnCircleDomain(SolutionC1[i].Bsup,DomainCirc1);
	if(C1sup<C1inf) C1sup+=PIpPI;
	C2sup=NormalizeOnCircleDomain(C2sup,DomainCirc2);
	
	ElCLib::CircleD2(C1sup,Axis2C1,R1,P1b,Tan1,Norm1); 
	ElCLib::CircleD2(C2sup,Axis2C2,R2,P2b,Tan2,Norm2);
	Tan2.Reverse();

	IntImpParGen::DeterminePosition(Pos1b,DomainCirc1,P1b,C1sup);
	IntImpParGen::DeterminePosition(Pos2b,_DomainCirc2,P2b,PIpPI-C2sup);
	Determine_Transition_LC(Pos1b,Tan1,Norm1,T1b , Pos2b,Tan2,Norm2,T2b, Tol);
	
	//--------------------------------------------------
	
	if(Opposite) {
	  if(nbsol!=3) { 
	    if(C2inf<C2sup) C2inf+=PIpPI;
	  }
	}
	else {
	  if(nbsol!=3) { 
	    if(C2sup<C2inf) C2sup+=PIpPI;
	  }
	}
	
	IntRes2d_IntersectionPoint NewPoint2(P1b,C1sup,PIpPI-C2sup,T1b,T2b,Standard_False);
	IntRes2d_IntersectionSegment NewSeg(NewPoint1,NewPoint2,
					    (Opposite==Standard_True)? Standard_False : Standard_True,
					    Standard_False);
	Append(NewSeg);
	
      }
      else {
	Append(NewPoint1);
      }
      
    }
    else { 
      
      ElCLib::CircleD2(C1inf,Axis2C1,R1,P1a,Tan1,Norm1); 
      ElCLib::CircleD2(C2inf,Axis2C2,R2,P2a,Tan2,Norm2);
      
      IntImpParGen::DeterminePosition(Pos1a,DomainCirc1,P1a,C1inf);
      IntImpParGen::DeterminePosition(Pos2a,DomainCirc2,P2a,C2inf);
      Determine_Transition_LC(Pos1a,Tan1,Norm1,T1a , Pos2a,Tan2,Norm2,T2a, Tol);
      
      
      IntRes2d_IntersectionPoint NewPoint1(P1a,C1inf,C2inf,T1a,T2a,Standard_False);
      
      if((SolutionC1[i].Length()>0.0 ) || (SolutionC2[i].Length() >0.0)) {
	//-- On traite un intervalle non reduit a un point
	Standard_Real C1sup=NormalizeOnCircleDomain(SolutionC1[i].Bsup,DomainCirc1);
	if(C1sup<C1inf) C1sup+=PIpPI;
	C2sup=NormalizeOnCircleDomain(C2sup,DomainCirc2);
	
	ElCLib::CircleD2(C1sup,Axis2C1,R1,P1b,Tan1,Norm1); 
	ElCLib::CircleD2(C2sup,Axis2C2,R2,P2b,Tan2,Norm2);
	
	IntImpParGen::DeterminePosition(Pos1b,DomainCirc1,P1b,C1sup);
	IntImpParGen::DeterminePosition(Pos2b,DomainCirc2,P2b,C2sup);
	Determine_Transition_LC(Pos1b,Tan1,Norm1,T1b , Pos2b,Tan2,Norm2,T2b, Tol);
	
	//--------------------------------------------------
	
	if(Opposite) {
	  if(nbsol!=3) { 
	    if(C2inf<C2sup) C2inf+=PIpPI;
	  }
	}
	else {
	  if(nbsol!=3) { 
	    if(C2sup<C2inf) C2sup+=PIpPI;
	  }
	}
	
	IntRes2d_IntersectionPoint NewPoint2(P1b,C1sup,C2sup,T1b,T2b,Standard_False);
	IntRes2d_IntersectionSegment NewSeg(NewPoint1,NewPoint2,Opposite,Standard_False);
	Append(NewSeg);
	
      }
      else {
	Append(NewPoint1);
      }
    }
  }
}
//----------------------------------------------------------------------
IntRes2d_Position FindPositionLL(Standard_Real &Param
				 ,const IntRes2d_Domain& Domain) {
  if(Domain.HasFirstPoint()) {
    if(Abs(Param-Domain.FirstParameter())<=Domain.FirstTolerance()) {
      Param=Domain.FirstParameter();
      return(IntRes2d_Head);
    }
  }
  if(Domain.HasLastPoint()) {
    if(Abs(Param-Domain.LastParameter())<=Domain.LastTolerance()) {
      Param=Domain.LastParameter();
      return(IntRes2d_End);
    }
  }
  return(IntRes2d_Middle);
}
//----------------------------------------------------------------------
void IntCurve_IntConicConic::Perform(const gp_Lin2d& L1
				     ,const IntRes2d_Domain& Domain1
				     ,const gp_Lin2d& L2
				     ,const IntRes2d_Domain& Domain2
				     ,const Standard_Real,const Standard_Real TolR) {  
  this->ResetFields();

  //-- Coordonnees du point d intersection sur chacune des 2 droites
  Standard_Real U1,U2; 
  //-- Nombre de points solution : 1 : Intersection
  //--                             0 : Non Confondues
  //--                             2 : Confondues a la tolerance pres
  Standard_Integer nbsol;
  IntRes2d_IntersectionPoint PtSeg1,PtSeg2;
  Standard_Real SINL1L2;
  Standard_Real Tol = TolR;
  if(TolR< 1e-10) Tol = 1e-10;
  

  LineLineGeometricIntersection(L1,L2,Tol,U1,U2,SINL1L2,nbsol);

  gp_Vec2d Tan1=L1.Direction();
  gp_Vec2d Tan2=L2.Direction();
  Standard_Boolean Opposite=(Tan1.Dot(Tan2) < 0.0)? Standard_True : Standard_False;

  done=Standard_True;

  if(nbsol==1) {
    //---------------------------------------------------
    //-- d: distance du point I a partir de laquelle  les 
    //--  points de parametre U1+d et U2+-d sont ecartes
    //--  d une distance superieure a Tol.
    //---------------------------------------------------
    IntRes2d_Position Pos1a,Pos2a,Pos1b,Pos2b;
    Standard_Real d=Tol/(SINL1L2);
    Standard_Real U1inf=U1-d;
    Standard_Real U1sup=U1+d;
    Standard_Real U1mU2=U1-U2;
    Standard_Real U1pU2=U1+U2;
    Standard_Real Res1inf,Res1sup;
    Standard_Real ProdVectTan;
    

    //---------------------------------------------------
    //-- On agrandit la zone U1inf U1sup pour tenir compte 
    //-- des tolerances des points en bout
    //--
    if(Domain1.HasFirstPoint()) { 
      if(L2.Distance(Domain1.FirstPoint()) < Domain1.FirstTolerance()) { 
	if(U1inf > Domain1.FirstParameter()) { 
	  U1inf = Domain1.FirstParameter();
	}
	if(U1sup < Domain1.FirstParameter()) { 
	  U1sup = Domain1.FirstParameter();
	}
      }
    }
    if(Domain1.HasLastPoint()) { 
      if(L2.Distance(Domain1.LastPoint()) < Domain1.LastTolerance()) { 
	if(U1inf > Domain1.LastParameter()) { 
	  U1inf = Domain1.LastParameter();
	}
	if(U1sup < Domain1.LastParameter()) { 
	  U1sup = Domain1.LastParameter();
	}
      }
    }      
    if(Domain2.HasFirstPoint()) { 
      if(L1.Distance(Domain2.FirstPoint()) < Domain2.FirstTolerance()) { 
	Standard_Real p = ElCLib::Parameter(L1,Domain2.FirstPoint());
	if(U1inf > p) { 
	  U1inf = p;
	}
	if(U1sup < p) { 
	  U1sup = p;
	}
      }
    }
    if(Domain2.HasLastPoint()) { 
      if(L1.Distance(Domain2.LastPoint()) < Domain2.LastTolerance()) { 
	Standard_Real p = ElCLib::Parameter(L1,Domain2.LastPoint());
	if(U1inf > p) { 
	  U1inf = p;
	}
	if(U1sup < p) { 
	  U1sup = p;
	}
      }
    }
    //-----------------------------------------------------------------

    DomainIntersection(Domain1,U1inf,U1sup,Res1inf,Res1sup,Pos1a,Pos1b);
    
    if((Res1sup-Res1inf)<0.0) {
      //-- Si l intersection est vide       
      //-- 
    }
    else { //-- (Domain1  INTER   Zone Intersection)    non vide

      ProdVectTan=Tan1.Crossed(Tan2);
      
      Standard_Boolean IsInDomain=Standard_True;

      //#####################################################################
      //##  Longueur Minimale d un segment    Sur Courbe 1 
      //##################################################################### 

      Standard_Real LongMiniSeg=Tol;


      if(((Res1sup-Res1inf)<=LongMiniSeg)
	 || ((Pos1a==Pos1b)&&(Pos1a!=IntRes2d_Middle)))     {
	//-------------------------------  Un seul Point -------------------
	//--- lorsque la longueur du segment est inferieure a ??
	//--- ou si deux points designent le meme bout
	Standard_Real Res2=Res1sup-U1;
	Res2=U2 + ((Opposite)? (-Res2) : (Res2));
	
	if(Domain2.HasFirstPoint()) 
	  if(Res2<(Domain2.FirstParameter()-Domain2.FirstTolerance()))
	    IsInDomain=Standard_False;
	
	if(IsInDomain) {
	  if(Domain2.HasLastPoint()) {
	    if((Domain2.LastParameter()+Domain2.LastTolerance()) < Res2) 
	      IsInDomain=Standard_False;
	  }
	  if(IsInDomain) { 
	    //------ Calcul des attributs du point d intersection --
	    IntRes2d_Transition T1,T2;
	    Pos1a=FindPositionLL(Res1sup,Domain1);
	    Pos2a=FindPositionLL(Res2,Domain2);
	    if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
	      T1.SetValue(Standard_False,Pos1a,IntRes2d_Out);
	      T2.SetValue(Standard_False,Pos2a,IntRes2d_In);
	    }
	    else {
	      if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
		T1.SetValue(Standard_False,Pos1a,IntRes2d_In);
		T2.SetValue(Standard_False,Pos2a,IntRes2d_Out);
	      }
	      else  { 
		T1.SetValue(Standard_False,Pos1a,IntRes2d_Unknown,Opposite);
		T2.SetValue(Standard_False,Pos2a,IntRes2d_Unknown,Opposite);
	      }
	    }
	    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	    gp_Pnt2d Pt1;
	    if(Pos1a==IntRes2d_Middle) {
	      Pt1=ElCLib::Value(Res2,L2);
	      Res1sup=ElCLib::Parameter(L1,Pt1);
	    }
	    else {
	      Pt1=ElCLib::Value(Res1sup,L1);
	      Res2=ElCLib::Parameter(L2,Pt1);
	    }
	    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	     // modified by NIZHNY-4426  Wed Nov 19 11:21:26 2003 .b
	    gp_Pnt2d IP(U1,U2);
	    Standard_Real pL1 = ElCLib::Parameter(L1,IP);
	    Standard_Real pL2 = ElCLib::Parameter(L2,IP);
	    if((U1inf <= pL1 && pL1 <= U1sup) &&
	       (U1inf <= pL2 && pL2 <= U1sup) ) {
	      IntRes2d_IntersectionPoint NewPoint1(IP,pL1,pL2,T1,T2,Standard_False);
	      Append(NewPoint1);
	    }
	    else {
	    // modified by NIZHNY-4426  Wed Nov 19 11:21:30 2003 .e
	      IntRes2d_IntersectionPoint NewPoint1(Pt1,Res1sup,Res2,T1,T2,Standard_False);
	      Append(NewPoint1);
	    }
	    //Append(NewPoint1);
	    //------------------------------------------------------
	  }
	}
      }  //---------------   Fin du cas  :   1 seul point --------------------
      
      else {
	//-- Intersection AND Domain1  --------> Segment ---------------------
	Standard_Real U2inf,U2sup;
	Standard_Real Res2inf,Res2sup;
	
	if(Opposite) { U2inf = U1pU2 -Res1sup;  U2sup= U1pU2-Res1inf;  }
	else         { U2inf = Res1inf-U1mU2;   U2sup= Res1sup-U1mU2;  }
	
	DomainIntersection(Domain2,U2inf,U2sup,Res2inf,Res2sup,Pos2a,Pos2b);

	//####################################################################
	//##  Test sur la longueur minimale d un segment sur Ligne2
	//####################################################################
	Standard_Real Res2sup_m_Res2inf = Res2sup-Res2inf;
	if(Res2sup_m_Res2inf < 0.0) {
	  //-- Pas de solutions On retourne Vide
	}
	else if(((Res2sup-Res2inf) > LongMiniSeg)  
		|| ((Pos2a==Pos2b)&&(Pos2a!=IntRes2d_Middle)))     {
	  //----------- Calcul des attributs du segment --------------
	  //-- Attention, les bornes Res1inf(sup) bougent donc il faut
	  //--  eventuellement recalculer les attributs
	  
	  if(Opposite) { Res1inf=U1pU2-Res2sup; Res1sup=U1pU2-Res2inf; 
			 Standard_Real Tampon=Res2inf; Res2inf=Res2sup; Res2sup=Tampon;
			 IntRes2d_Position Pos=Pos2a; Pos2a=Pos2b; Pos2b=Pos;
		       }
	  else         { Res1inf=U1mU2+Res2inf; Res1sup=U1mU2+Res2sup; }
	  
	  Pos1a=FindPositionLL(Res1inf,Domain1);
	  Pos1b=FindPositionLL(Res1sup,Domain1);	  
	  
	  IntRes2d_Transition T1a,T2a,T1b,T2b;
	  
	  if(ProdVectTan>=TOLERANCE_ANGULAIRE) {  // &&&&&&&&&&&&&&&
	    T1a.SetValue(Standard_False,Pos1a,IntRes2d_Out);      
	    T2a.SetValue(Standard_False,Pos2a,IntRes2d_In);
	  }
	  else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
	    T1a.SetValue(Standard_False,Pos1a,IntRes2d_In);      
	    T2a.SetValue(Standard_False,Pos2a,IntRes2d_Out);
	  }
	  else {
	    T1a.SetValue(Standard_False,Pos1a,IntRes2d_Unknown,Opposite);
	    T2a.SetValue(Standard_False,Pos2a,IntRes2d_Unknown,Opposite);
	  }
	  

	  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  //~~~~~~~  C O N V E N T I O N    -    S E G M E N T     ~~~~~~~
	  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  //~~ On Renvoie un segment dans les cas suivants :            ~~
	  //~~   (1) Extremite L1 L2   ------>    Extremite L1 L2       ~~
	  //~~   (2) Extremite L1 L2   ------>    Intersection          ~~
	  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  
	  Standard_Boolean ResultIsAPoint=Standard_False;

	  if(((Res1sup-Res1inf)<=LongMiniSeg) 
	     || (Abs(Res2sup-Res2inf)<=LongMiniSeg)) {
	    //-- On force la creation d un point
	    ResultIsAPoint=Standard_True;
	  }
	  else {
	    //------------------------------------------------------------
	    //-- On traite les cas ou l intersection est situee du 
	    //-- Mauvais cote du domaine 
	    //-- Attention : Res2inf <-> Pos2a        Res2sup <-> Pos2b
	    //--  et         Res1inf <-> Pos1a        Res1sup <-> Pos1b
	    //--             avec Res1inf <= Res1sup
	    //------------------------------------------------------------
	    //-- Le point sera : Res1inf,Res2inf,T1a(Pos1a),T2a(Pos2a)
	    //------------------------------------------------------------

	    if(Pos1a==IntRes2d_Head) { 
	      if(Pos1b!=IntRes2d_End && U1<Res1inf)    { ResultIsAPoint=Standard_True; U1=Res1inf; U2=Res2inf; }
	    }
	    if(Pos1b==IntRes2d_End)  { 
	      if(Pos1a!=IntRes2d_Head && U1>Res1sup)   { ResultIsAPoint=Standard_True; U1=Res1sup; U2=Res2sup; }
	    }
	
            if(Pos2a==IntRes2d_Head) { 
	      if(Pos2b!=IntRes2d_End && U2<Res2inf)    { ResultIsAPoint=Standard_True; U2=Res2inf; U1=Res1inf; }
	    }
	    else {
	      if(Pos2a==IntRes2d_End)  { 
		if(Pos2b!=IntRes2d_Head && U2>Res2inf) { ResultIsAPoint=Standard_True; U2=Res2inf; U1=Res1inf; }
	      }
	    }
	    if(Pos2b==IntRes2d_Head) { 
	      if(Pos2a!=IntRes2d_End && U2<Res2sup)    { ResultIsAPoint=Standard_True; U2=Res2sup; U1=Res1sup; }
	    }
	    else {
	      if(Pos2b==IntRes2d_End) {
		if(Pos2a!=IntRes2d_Head && U2>Res2sup) { ResultIsAPoint=Standard_True; U2=Res2sup; U1=Res1sup; }
	      }
	    }
	  }
	    
	  

	  if((!ResultIsAPoint) && (Pos1a!=IntRes2d_Middle || Pos2a!=IntRes2d_Middle)) {
	    IntRes2d_Transition T1b,T2b;
	    if(ProdVectTan>=TOLERANCE_ANGULAIRE) { //&&&&&&&&&&&&&&
	      T1b.SetValue(Standard_False,Pos1b,IntRes2d_Out);
	      T2b.SetValue(Standard_False,Pos2b,IntRes2d_In);
	    }
	    else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) { //&&&&&&&&&&&&&&
	      T1b.SetValue(Standard_False,Pos1b,IntRes2d_In);
	      T2b.SetValue(Standard_False,Pos2b,IntRes2d_Out);
	    }
	    else {
	      T1b.SetValue(Standard_False,Pos1b,IntRes2d_Unknown,Opposite);
	      T2b.SetValue(Standard_False,Pos2b,IntRes2d_Unknown,Opposite);
	    }
	    gp_Pnt2d Ptdebut;
	    if(Pos1a==IntRes2d_Middle) { 
	      Standard_Real t3;
	      if(Opposite) {
		t3 = (Pos2a == IntRes2d_Head)? Res2sup : Res2inf;
	      }
	      else {
		t3 = (Pos2a == IntRes2d_Head)? Res2inf : Res2sup;
	      }
	      Ptdebut=ElCLib::Value(t3,L2);
	      Res1inf=ElCLib::Parameter(L1,Ptdebut);
	    }
	    else {
	      Standard_Real t4 = (Pos1a == IntRes2d_Head)? Res1inf : Res1sup;
	      Ptdebut=ElCLib::Value(t4,L1);
	      Res2inf=ElCLib::Parameter(L2,Ptdebut);
	    }
	    PtSeg1.SetValues(Ptdebut,Res1inf,Res2inf,T1a,T2a,Standard_False);
	    if(Pos1b!=IntRes2d_Middle || Pos2b!=IntRes2d_Middle) {
	      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	      //~~ Ajustement des parametres et du point renvoye
	      gp_Pnt2d Ptfin;
	      if(Pos1b==IntRes2d_Middle) { 
		Ptfin=ElCLib::Value(Res2sup,L2);
		Res1sup=ElCLib::Parameter(L1,Ptfin);
	      }
	      else {
		Ptfin=ElCLib::Value(Res1sup,L1);
		Res2sup=ElCLib::Parameter(L2,Ptfin);
	      }
	      PtSeg2.SetValues(Ptfin,Res1sup,Res2sup,T1b,T2b,Standard_False);
	      IntRes2d_IntersectionSegment Segment(PtSeg1,PtSeg2
						   ,Opposite,Standard_False);
	      Append(Segment);  
	    } 
	    else { //-- Extremite(L1 ou L2)  ------>   Point Middle(L1 et L2)

	      Pos1b=FindPositionLL(U1,Domain1);
	      Pos2b=FindPositionLL(U2,Domain2);	  	
	      if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
		T1b.SetValue(Standard_False,Pos1b,IntRes2d_Out);
		T2b.SetValue(Standard_False,Pos2b,IntRes2d_In);
	      }
	      else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
		T1b.SetValue(Standard_False,Pos1b,IntRes2d_In);
		T2b.SetValue(Standard_False,Pos2b,IntRes2d_Out);
	      }
	      else {
		T1b.SetValue(Standard_False,Pos1b,IntRes2d_Unknown,Opposite);
		T2b.SetValue(Standard_False,Pos2b,IntRes2d_Unknown,Opposite);
	      }
	      
	      PtSeg2.SetValues(ElCLib::Value(U2,L2),U1,U2,T1b,T2b,Standard_False);

	      if((Abs(Res1inf-U1) >LongMiniSeg) && (Abs(Res2inf-U2) >LongMiniSeg)) {
		IntRes2d_IntersectionSegment Segment(PtSeg1,PtSeg2,Opposite,Standard_False);
		Append(Segment);  
	      }
	      else {
		Append(SegmentToPoint(PtSeg1,T1a,T2a,PtSeg2,T1b,T2b));
	      }
	    }

	  } //-- (Pos1a!=IntRes2d_Middle || Pos2a!=IntRes2d_Middle) --
	  else {  //-- Pos1a == Pos2a == Middle
	    if(Pos1b==IntRes2d_Middle) Pos1b=Pos1a;
	    if(Pos2b==IntRes2d_Middle) Pos2b=Pos2a;
	    if(ResultIsAPoint) {
	      //-- Middle sur le segment A 
	      //-- 
	      if(Pos1b!=IntRes2d_Middle || Pos2b!=IntRes2d_Middle) {
		gp_Pnt2d Ptfin;
		if(Pos1b==IntRes2d_Middle) {
		  Standard_Real t2;
		  if(Opposite) { 
		    t2 = (Pos2b == IntRes2d_Head)? Res2sup : Res2inf;
		  }
		  else {
		    t2 = (Pos2b == IntRes2d_Head)? Res2inf : Res2sup;
		  }
		  Ptfin=ElCLib::Value(t2,L2);
		  Res1sup=ElCLib::Parameter(L1,Ptfin);
//modified by NIZHNY-MKK  Tue Feb 15 10:54:51 2000.BEGIN
		  Pos1b=FindPositionLL(Res1sup,Domain1);
//modified by NIZHNY-MKK  Tue Feb 15 10:54:55 2000.END

		}
		else {
		  Standard_Real t1 = (Pos1b == IntRes2d_Head)? Res1inf : Res1sup;
		  Ptfin=ElCLib::Value(t1,L1);
		  Res2sup=ElCLib::Parameter(L2,Ptfin);
//modified by NIZHNY-MKK  Tue Feb 15 10:55:08 2000.BEGIN
		  Pos2b=FindPositionLL(Res2sup,Domain2);
//modified by NIZHNY-MKK  Tue Feb 15 10:55:11 2000.END
		}
		if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Out);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_In);
		}
		else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_In);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Out);
		}
		else {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Unknown,Opposite);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Unknown,Opposite);
		}
	        PtSeg2.SetValues(Ptfin,Res1sup,Res2sup,T1b,T2b,Standard_False);
		Append(PtSeg2);
	      }
	      else {
		Pos1b=FindPositionLL(U1,Domain1);
		Pos2b=FindPositionLL(U2,Domain2);	  	
		
		if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Out);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_In);
		}
		else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_In);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Out);
		}
		else {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Unknown,Opposite);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Unknown,Opposite);
		}
		PtSeg1.SetValues(ElCLib::Value(U2,L2),U1,U2,T1b,T2b,Standard_False);
		Append(PtSeg1); 
	      }
	    }
	    else {
	      PtSeg1.SetValues(ElCLib::Value(U2,L2),U1,U2,T1a,T2a,Standard_False);
	      
	      if((Pos1b!=IntRes2d_Middle || Pos2b!=IntRes2d_Middle)) {
		IntRes2d_Transition T1b,T2b;
		if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Out);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_In);
		}
		else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_In);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Out);
		}
		else {
		  T1b.SetValue(Standard_False,Pos1b,IntRes2d_Unknown,Opposite);
		  T2b.SetValue(Standard_False,Pos2b,IntRes2d_Unknown,Opposite);
		}
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		//~~ Ajustement des parametres et du point renvoye
		gp_Pnt2d Ptfin;             
		if(Pos1b==IntRes2d_Middle) {
		  Ptfin=ElCLib::Value(Res2sup,L2);
		  Res1sup=ElCLib::Parameter(L1,Ptfin);
		}
		else {
		  Ptfin=ElCLib::Value(Res1sup,L1);
		  Res2sup=ElCLib::Parameter(L2,Ptfin);
		}

	        PtSeg2.SetValues(Ptfin,Res1sup,Res2sup,T1b,T2b,Standard_False);
		
		if((Abs(U1-Res1sup)>LongMiniSeg)
		   ||(Abs(U2-Res2sup)>LongMiniSeg)) { 
		  //-- Modif du 1er Octobre 92 (Pour Composites)
		  
		  IntRes2d_IntersectionSegment Segment(PtSeg1,PtSeg2
						       ,Opposite,Standard_False);
		  Append(Segment);  
		}
		else {
		  Append(SegmentToPoint(PtSeg1,T1a,T2a,PtSeg2,T1b,T2b));
		}
	      }
	      else {
		Append(PtSeg1); 
	      }
	    }
	  }
	} //----- Fin Creation Segment ----(Res2sup-Res2inf>Tol)-------------
	else {
	  //------ (Intersection And Domain1)  AND  Domain2  --> Point ------
	  //-- Attention Res1sup peut etre  different de  U2
	  //--   Mais on a Res1sup-Res1inf < Tol 
	  IntRes2d_Transition T1,T2;
	  Res1sup=(Opposite)? (U1pU2-Res2inf) : (U1mU2+Res2sup);
	  
	  Pos1a=FindPositionLL(Res1sup,Domain1);
	  Pos2a=FindPositionLL(Res2sup,Domain2);
	  
	  //------ Calcul des attributs du point d intersection --
	  if(ProdVectTan>=TOLERANCE_ANGULAIRE) {
	    T1.SetValue(Standard_False,Pos1a,IntRes2d_Out);
	    T2.SetValue(Standard_False,Pos2a,IntRes2d_In);
	  }
	  else if(ProdVectTan<=-TOLERANCE_ANGULAIRE) {
	    T1.SetValue(Standard_False,Pos1a,IntRes2d_In);
	    T2.SetValue(Standard_False,Pos2a,IntRes2d_Out);
	  }
	  else {
	    T1.SetValue(Standard_False,Pos1a,IntRes2d_Unknown,Opposite);
	    T2.SetValue(Standard_False,Pos2a,IntRes2d_Unknown,Opposite);
	  }	  
	  gp_Pnt2d Pt1=ElCLib::Value(Res2sup,L2);
	  IntRes2d_IntersectionPoint NewPoint1(Pt1,Res1sup,Res2sup,T1,T2,Standard_False);
	  Append(NewPoint1);
	  //------------------------------------------------------
	}
      }
    }
  }
  else {
    if(nbsol==2) {  //== Droites confondues a la tolerance pres 
      //--On traite ici le cas de segments resultats non neccess. bornes
      //-- 
      //--On prend la droite D1 comme reference ( pour le sens positif )
      //--
      Standard_Integer ResHasFirstPoint=0;    
      Standard_Integer ResHasLastPoint=0;
      Standard_Real ParamStart = 0.0,ParamStart2,ParamEnd = 0.0,ParamEnd2;
      Standard_Real Org2SurL1=ElCLib::Parameter(L1,L2.Location());
      //== 3 : L1 et L2 bornent
      //== 2 :       L2 borne
      //== 1 : L1 borne
      if(Domain1.HasFirstPoint()) ResHasFirstPoint=1;
      if(Domain1.HasLastPoint())   ResHasLastPoint=1;
      if(Opposite) {
	if(Domain2.HasLastPoint())     ResHasFirstPoint+=2;
	if(Domain2.HasFirstPoint())   ResHasLastPoint+=2;
      }
      else {
	if(Domain2.HasLastPoint())     ResHasLastPoint+=2;
	if(Domain2.HasFirstPoint())   ResHasFirstPoint+=2;
      }
      if(ResHasFirstPoint==0 && ResHasLastPoint==0) {
	//~~~~ Creation d un segment infini avec Opposite
	Append(IntRes2d_IntersectionSegment(Opposite));
      }
      else {  //-- On obtient au pire une demi-droite
	switch(ResHasFirstPoint) {
	case 1: 
	  ParamStart=Domain1.FirstParameter(); 
	  ParamStart2=(Opposite)? (Org2SurL1-ParamStart) 
	                         :(ParamStart-Org2SurL1); 
	  break;
	case 2:
	  if(Opposite) {
	    ParamStart2=Domain2.LastParameter();
	    ParamStart=Org2SurL1 - ParamStart2; 
	  }
	  else {
	    ParamStart2=Domain2.FirstParameter();
	    ParamStart=Org2SurL1 + ParamStart2;
	  }
	  break;
	case 3:
	  if(Opposite) {
	    ParamStart2=Domain2.LastParameter();
	    ParamStart=Org2SurL1 - ParamStart2; 
	    if(ParamStart < Domain1.FirstParameter()) {
	      ParamStart=Domain1.FirstParameter();
	      ParamStart2=Org2SurL1 -  ParamStart;
	    }
	  }
	  else {
	    ParamStart2=Domain2.FirstParameter();
	    ParamStart=Org2SurL1 + ParamStart2;
	    if(ParamStart < Domain1.FirstParameter()) {
	      ParamStart=Domain1.FirstParameter();
	      ParamStart2=ParamStart - Org2SurL1;
	    }
	  }
	  break;
	default:  //~~~ Segment Infini a gauche
	  break;
	}
	
	switch(ResHasLastPoint) {
	case 1: 
	  ParamEnd=Domain1.LastParameter(); 
	  ParamEnd2=(Opposite)? (Org2SurL1-ParamEnd) 
	                         :(ParamEnd-Org2SurL1); 
	  break;
	case 2:
	  if(Opposite) {
	    ParamEnd2=Domain2.FirstParameter();
	    ParamEnd=Org2SurL1 - ParamEnd2; 
	  }
	  else {
	    ParamEnd2=Domain2.LastParameter();
	    ParamEnd=Org2SurL1 + ParamEnd2;
	  }
	  break;
	case 3:
	  if(Opposite) {
	    ParamEnd2=Domain2.FirstParameter();
	    ParamEnd=Org2SurL1 - ParamEnd2; 
	    if(ParamEnd > Domain1.LastParameter()) {
	      ParamEnd=Domain1.LastParameter();
	      ParamEnd2=Org2SurL1 -  ParamEnd;
	    }
	  }
	  else {
	    ParamEnd2=Domain2.LastParameter();
	    ParamEnd=Org2SurL1 + ParamEnd2;
	    if(ParamEnd > Domain1.LastParameter()) {
	      ParamEnd=Domain1.LastParameter();
	      ParamEnd2=ParamEnd - Org2SurL1;
	    }
	  }
	default:  //~~~ Segment Infini a droite
	  break;
	}
	
	IntRes2d_Transition Tinf,Tsup;

	if(ResHasFirstPoint) {
	  if(ResHasLastPoint) {
	    //~~~ Creation de la borne superieure
	    //~~~ L1 :     |------------->       ou          |-------------->
	    //~~~ L2 : <------------|            ou  <----|
	    if(ParamEnd >= (ParamStart-Tol)) { 
	      //~~~ Creation d un segment
	      IntRes2d_Position Pos1,Pos2;
	      Pos1=FindPositionLL(ParamStart,Domain1);
	      Pos2=FindPositionLL(ParamStart2,Domain2);
	      Tinf.SetValue(Standard_True,Pos1,IntRes2d_Unknown,Opposite);
	      Tsup.SetValue(Standard_True,Pos2,IntRes2d_Unknown,Opposite);
	      IntRes2d_IntersectionPoint P1(ElCLib::Value(ParamStart,L1)
					    ,ParamStart,ParamStart2
					    ,Tinf,Tsup,Standard_False);
	      if(ParamEnd > (ParamStart+Tol)) {
		//~~~ Le segment est assez long
		Pos1=FindPositionLL(ParamEnd,Domain1);
		Pos2=FindPositionLL(ParamEnd2,Domain2);
		Tinf.SetValue(Standard_True,Pos1,IntRes2d_Unknown,Opposite);
		Tsup.SetValue(Standard_True,Pos2,IntRes2d_Unknown,Opposite);

		IntRes2d_IntersectionPoint P2(ElCLib::Value(ParamEnd,L1)
					      ,ParamEnd,ParamEnd2
					      ,Tinf,Tsup,Standard_False);
		IntRes2d_IntersectionSegment Seg(P1,P2,Opposite,Standard_False);
		Append(Seg);
	      }
	      else {   //~~~~ le segment est de longueur inferieure a Tol
		Append(P1);
	      }
	    } //-- if( ParamEnd >= ...)
	  }   //-- if(ResHasLastPoint)
	  else { 
	    //~~~ Creation de la demi droite   |----------->
	    IntRes2d_Position Pos1=FindPositionLL(ParamStart,Domain1);
	    IntRes2d_Position Pos2=FindPositionLL(ParamStart2,Domain2);
	    Tinf.SetValue(Standard_True,Pos1,IntRes2d_Unknown,Opposite);
	    Tsup.SetValue(Standard_True,Pos2,IntRes2d_Unknown,Opposite);

	    IntRes2d_IntersectionPoint P(ElCLib::Value(ParamStart,L1)
					  ,ParamStart,ParamStart2
					  ,Tinf,Tsup,Standard_False);
	    IntRes2d_IntersectionSegment Seg(P,Standard_True,Opposite,Standard_False);
	    Append(Seg);
	  }
	}
	else {
	  IntRes2d_Position Pos1=FindPositionLL(ParamEnd,Domain1);
	  IntRes2d_Position Pos2=FindPositionLL(ParamEnd2,Domain2);
	  Tinf.SetValue(Standard_True,Pos1,IntRes2d_Unknown,Opposite);
	  Tsup.SetValue(Standard_True,Pos2,IntRes2d_Unknown,Opposite);

	  IntRes2d_IntersectionPoint P2(ElCLib::Value(ParamEnd,L1)
					,ParamEnd,ParamEnd2
					,Tinf,Tsup,Standard_False);
	  IntRes2d_IntersectionSegment Seg(P2,Standard_False,Opposite,Standard_False);
	  Append(Seg);
	  //~~~ Creation de la demi droite   <-----------|
	}
      }
    }
  }
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void IntCurve_IntConicConic::Perform(const gp_Lin2d& Line
				     ,const IntRes2d_Domain& LIG_Domain
				     ,const gp_Circ2d& Circle
				     ,const IntRes2d_Domain& CIRC_Domain
				     ,const Standard_Real TolConf,const Standard_Real Tol) {

//--  if(! CIRC_Domain.IsClosed()) {
//--    Standard_ConstructionError::Raise("Domaine incorrect");
//--  }

  Standard_Boolean TheReversedParameters=ReversedParameters();
  this->ResetFields();
  this->SetReversedParameters(TheReversedParameters);

  Standard_Integer nbsol=0;
  PeriodicInterval CInt1,CInt2;  
  
  LineCircleGeometricIntersection(Line,Circle,TolConf,Tol
				  ,CInt1,CInt2
				  ,nbsol);

  done=Standard_True;

  if(nbsol==0) { //-- Pas de solutions 
    return;
  }
  
//  Modified by Sergey KHROMOV - Mon Dec 18 11:13:18 2000 Begin
  if (nbsol == 2 && CInt2.Bsup == CInt1.Binf + PIpPI) {
    Standard_Real FirstBound = CIRC_Domain.FirstParameter();
    Standard_Real LastBound = CIRC_Domain.LastParameter();
    Standard_Real FirstTol = CIRC_Domain.FirstTolerance();
    Standard_Real LastTol = CIRC_Domain.LastTolerance();
    if (CInt1.Binf == 0 && FirstBound - FirstTol > CInt1.Bsup) {
      nbsol = 1;
      CInt1.SetValues(CInt2.Binf, CInt2.Bsup);
    } else if (CInt2.Bsup == PIpPI && LastBound + LastTol < CInt2.Binf)
      nbsol = 1;
  }
//  Modified by Sergey KHROMOV - Mon Dec 18 11:13:20 2000 End

  PeriodicInterval CDomain(CIRC_Domain);
  Standard_Real deltat = CDomain.Bsup-CDomain.Binf;
  while(CDomain.Binf >= PIpPI) CDomain.Binf-=PIpPI;
  while(CDomain.Binf <  0.0)   CDomain.Binf+=PIpPI;
  CDomain.Bsup=CDomain.Binf+deltat;

  //------------------------------------------------------------
  //-- Ajout : Jeudi 28 mars 96 
  //-- On agrandit artificiellement les domaines
  Standard_Real BinfModif = CDomain.Binf;
  Standard_Real BsupModif = CDomain.Bsup;
  BinfModif-=CIRC_Domain.FirstTolerance() / Circle.Radius();
  BsupModif+=CIRC_Domain.LastTolerance() / Circle.Radius();
  deltat = BsupModif-BinfModif;
  if(deltat<=PIpPI) { 
    CDomain.Binf = BinfModif;
    CDomain.Bsup = BsupModif;
  }
  else { 
    Standard_Real t=PIpPI-deltat;
    t*=0.5;
    CDomain.Binf = BinfModif+t;
    CDomain.Bsup = BsupModif-t; 
  }
  deltat = CDomain.Bsup-CDomain.Binf;
  while(CDomain.Binf >= PIpPI) CDomain.Binf-=PIpPI;
  while(CDomain.Binf <  0.0)   CDomain.Binf+=PIpPI;
  CDomain.Bsup=CDomain.Binf+deltat;
  //-- ------------------------------------------------------------

  Interval LDomain(LIG_Domain);
  
  Standard_Integer NbSolTotal=0;
  
  PeriodicInterval SolutionCircle[4];
  Interval SolutionLine[4];
  
  //----------------------------------------------------------------------
  //----------- Traitement du premier intervalle Geometrique  CInt1   ----
  //----------------------------------------------------------------------
  //-- NbSolTotal est incremente a chaque Intervalle solution.
  //-- On stocke les intervalles dans les tableaux : SolutionCircle[4] 
  //--                                            et SolutionLine[4]
  //-- des Exemples faciles donnent 3 Intersections
  //-- des Problemes numeriques peuvent peut etre en donner 4 ??????
  //--
  PeriodicInterval CDomainAndRes=CDomain.FirstIntersection(CInt1);
  
  ProjectOnLAndIntersectWithLDomain(Circle,Line
				    ,CDomainAndRes
				    ,LDomain
				    ,SolutionCircle
				    ,SolutionLine
				    ,NbSolTotal
				    ,LIG_Domain
				    ,CIRC_Domain);
  
  CDomainAndRes=CDomain.SecondIntersection(CInt1);
  
  ProjectOnLAndIntersectWithLDomain(Circle,Line
				    ,CDomainAndRes
				    ,LDomain
				    ,SolutionCircle
				    ,SolutionLine
				    ,NbSolTotal
				    ,LIG_Domain
				    ,CIRC_Domain);
  
  //----------------------------------------------------------------------
  //----------- Traitement du second intervalle Geometrique   C1_Int2 ----
  //----------------------------------------------------------------------
  if(nbsol==2) {
    CDomainAndRes=CDomain.FirstIntersection(CInt2);
    
    ProjectOnLAndIntersectWithLDomain(Circle,Line
				      ,CDomainAndRes
				      ,LDomain
				      ,SolutionCircle
				      ,SolutionLine
				      ,NbSolTotal
				      ,LIG_Domain
				      ,CIRC_Domain);
    
    //--------------------------------------------------------------------
    CDomainAndRes=CDomain.SecondIntersection(CInt2);
    
    
    ProjectOnLAndIntersectWithLDomain(Circle,Line
				      ,CDomainAndRes
				      ,LDomain
				      ,SolutionCircle
				      ,SolutionLine
				      ,NbSolTotal
				      ,LIG_Domain
				      ,CIRC_Domain);
  }









  //----------------------------------------------------------------------
  //-- Calcul de toutes les transitions et Positions.
  //--
  //-- On determine si des intervalles sont reduit a des points 
  //--      ( Rayon * Intervalle.Length()    <    TolConf   )   ### Modif 19 Nov Tol-->TolConf
  //--
  Standard_Real R=Circle.Radius();
  Standard_Integer i ;
  Standard_Real MaxTol = TolConf;
  if(MaxTol<Tol) MaxTol = Tol;
  if(MaxTol<1.0e-10) MaxTol = 1.0e-10; 

  for( i=0; i<NbSolTotal ; i++) { 
    if((R * SolutionCircle[i].Length())<MaxTol 
       && (SolutionLine[i].Length())<MaxTol) {
      
      Standard_Real t=(SolutionCircle[i].Binf+SolutionCircle[i].Bsup)*0.5;
      SolutionCircle[i].Binf=SolutionCircle[i].Bsup=t;
      
      t=(SolutionLine[i].Binf+SolutionLine[i].Bsup)*0.5;
      SolutionLine[i].Binf=SolutionLine[i].Bsup=t;
    }
  }
#if 0 
  if(NbSolTotal == 2) { 
    if(SolutionLine[0].Binf==SolutionLine[0].BSup) { 
      if(SolutionLine[1].Binf==SolutionLine[1].BSup) {
	if(Abs(SolutionLine[0].Binf-SolutionLine[1].Binf)<TolConf) { 
	  SolutionLine[0].Binf=0.5*(SolutionLine[0].BSup+SolutionLine[1].BSup);
	  SolutionLine[0].BSup=SolutionLine[0].Binf;
	  NbSolTotal = 1;
	}
      }
    }
  }
#endif
  //----------------------------------------------------------------------
  //-- Traitement des intervalles (ou des points obtenus)
  //-- 
  if(NbSolTotal) { 
    gp_Ax22d CircleAxis=Circle.Axis();
    gp_Ax2d LineAxis=Line.Position();
    gp_Pnt2d P1a,P2a,P1b,P2b;
    gp_Vec2d Tan1,Tan2,Norm1;
    gp_Vec2d Norm2(0.0,0.0);
    IntRes2d_Transition T1a,T2a,T1b,T2b;
    IntRes2d_Position Pos1a,Pos1b,Pos2a,Pos2b;
    
    ElCLib::CircleD1(SolutionCircle[0].Binf,CircleAxis,R,P1a,Tan1);
    ElCLib::LineD1(SolutionLine[0].Binf,LineAxis,P2a,Tan2);
    
    Standard_Boolean Opposite=((Tan1.Dot(Tan2))<0.0)? Standard_True : Standard_False;
    
    
    for(i=0; i<NbSolTotal; i++ ) {


      //-- 7 aout 97 
      //-- On recentre Bin et Bsup de facon a avoir une portion commune avec CIRC_Domain
      Standard_Real p1=SolutionCircle[i].Binf;
      Standard_Real p2=SolutionCircle[i].Bsup;
      Standard_Real q1=CIRC_Domain.FirstParameter();
      Standard_Real q2=CIRC_Domain.LastParameter();
      //--          |------ CircDomain ------|   [-- Sol --]
      if(p1>q2) { 	
	do { 
	  p1-=PIpPI; 
	  p2-=PIpPI;
	}
	while( (p1>q2) );
      }
      else if(p2<q1) { 
	do { 
	  p1+=PIpPI; 
	  p2+=PIpPI;
	}
	while( (p2<q1) );	
      }
      if(p1<q1 && p2>q1) { 
	p1=q1;
      }
      if(p1<q2 && p2>q2) { 
	p2=q2;
      }
      
#if 0
      if(SolutionCircle[i].Binf!=p1 || SolutionCircle[i].Bsup!=p2) { 
	printf("\n IntCurve_IntConicConic_1.cxx : (%g , %g) --> (%g , %g)\n",
	       SolutionCircle[i].Binf,SolutionCircle[i].Bsup,p1,p2); 
      } 
#endif
      SolutionCircle[i].Binf=p1;
      SolutionCircle[i].Bsup=p2;
      
//-- Fin 7 aout 97

      
      Standard_Real Linf=(Opposite)? SolutionLine[i].Bsup : SolutionLine[i].Binf;
      Standard_Real Lsup=(Opposite)? SolutionLine[i].Binf : SolutionLine[i].Bsup;
      
      //---------------------------------------------------------------
      //-- Si les parametres sur le cercle sont en premier 
      //-- On doit retourner ces parametres dans l ordre croissant
      //---------------------------------------------------------------
      if(Linf > Lsup) {
	Standard_Real T=SolutionCircle[i].Binf;
	SolutionCircle[i].Binf=SolutionCircle[i].Bsup;
	SolutionCircle[i].Bsup=T;
	
	T=Linf; Linf=Lsup; Lsup=T;
      }
      
      
      ElCLib::CircleD2(SolutionCircle[i].Binf,CircleAxis,R,P1a,Tan1,Norm1); 
      ElCLib::LineD1(Linf,LineAxis,P2a,Tan2);
      
      IntImpParGen::DeterminePosition(Pos1a,CIRC_Domain,P1a,SolutionCircle[i].Binf);
      IntImpParGen::DeterminePosition(Pos2a,LIG_Domain,P2a,Linf); 
      Determine_Transition_LC(Pos1a,Tan1,Norm1,T1a , Pos2a,Tan2,Norm2,T2a, Tol);
      Standard_Real Cinf;
      if(Pos1a==IntRes2d_End) {
	Cinf = CIRC_Domain.LastParameter();
	P1a  = CIRC_Domain.LastPoint();
	Linf = ElCLib::Parameter(Line,P1a);
	
	ElCLib::CircleD2(Cinf,CircleAxis,R,P1a,Tan1,Norm1); 
	ElCLib::LineD1(Linf,LineAxis,P2a,Tan2);	
	IntImpParGen::DeterminePosition(Pos1a,CIRC_Domain,P1a,Cinf);
	IntImpParGen::DeterminePosition(Pos2a,LIG_Domain,P2a,Linf); 
	Determine_Transition_LC(Pos1a,Tan1,Norm1,T1a , Pos2a,Tan2,Norm2,T2a, Tol);
      }
      else if(Pos1a==IntRes2d_Head) { 
	Cinf = CIRC_Domain.FirstParameter();
	P1a  = CIRC_Domain.FirstPoint();
	Linf = ElCLib::Parameter(Line,P1a);
	
	ElCLib::CircleD2(Cinf,CircleAxis,R,P1a,Tan1,Norm1); 
	ElCLib::LineD1(Linf,LineAxis,P2a,Tan2);	
	IntImpParGen::DeterminePosition(Pos1a,CIRC_Domain,P1a,Cinf);
	IntImpParGen::DeterminePosition(Pos2a,LIG_Domain,P2a,Linf); 
	Determine_Transition_LC(Pos1a,Tan1,Norm1,T1a , Pos2a,Tan2,Norm2,T2a, Tol);
      }
      else { 
	Cinf=NormalizeOnCircleDomain(SolutionCircle[i].Binf,CIRC_Domain);
      }

      IntRes2d_IntersectionPoint NewPoint1(P1a,Linf,Cinf,T2a,T1a,ReversedParameters());
      
      if((SolutionLine[i].Length()+SolutionCircle[i].Length()) >0.0) {
	
	ElCLib::CircleD2(SolutionCircle[i].Bsup,CircleAxis,R,P1b,Tan1,Norm1); 
        ElCLib::LineD1(Lsup,LineAxis,P2b,Tan2);
	  
	IntImpParGen::DeterminePosition(Pos1b,CIRC_Domain,P1b,SolutionCircle[i].Bsup);
	IntImpParGen::DeterminePosition(Pos2b,LIG_Domain,P2b,Lsup);
	Determine_Transition_LC(Pos1b,Tan1,Norm1,T1b , Pos2b,Tan2,Norm2,T2b, Tol);
	Standard_Real Csup;
	if(Pos1b==IntRes2d_End) {
	  Csup = CIRC_Domain.LastParameter();
	  P1b  = CIRC_Domain.LastPoint();
	  Lsup = ElCLib::Parameter(Line,P1b);
	  ElCLib::CircleD2(Csup,CircleAxis,R,P1b,Tan1,Norm1); 
	  ElCLib::LineD1(Lsup,LineAxis,P2b,Tan2);
	  
	  IntImpParGen::DeterminePosition(Pos1b,CIRC_Domain,P1b,Csup);
	  IntImpParGen::DeterminePosition(Pos2b,LIG_Domain,P2b,Lsup);
	  Determine_Transition_LC(Pos1b,Tan1,Norm1,T1b , Pos2b,Tan2,Norm2,T2b, Tol);	  
	}
	else if(Pos1b==IntRes2d_Head) { 
	  Csup = CIRC_Domain.FirstParameter();
	  P1b  = CIRC_Domain.FirstPoint();
	  Lsup = ElCLib::Parameter(Line,P1b);
	  ElCLib::CircleD2(Csup,CircleAxis,R,P1b,Tan1,Norm1); 
	  ElCLib::LineD1(Lsup,LineAxis,P2b,Tan2);
	  
	  IntImpParGen::DeterminePosition(Pos1b,CIRC_Domain,P1b,Csup);
	  IntImpParGen::DeterminePosition(Pos2b,LIG_Domain,P2b,Lsup);
	  Determine_Transition_LC(Pos1b,Tan1,Norm1,T1b , Pos2b,Tan2,Norm2,T2b, Tol);	
	}
	else { 
	  Csup=NormalizeOnCircleDomain(SolutionCircle[i].Bsup,CIRC_Domain);
	}

	IntRes2d_IntersectionPoint NewPoint2(P1b,Lsup,Csup,T2b,T1b,ReversedParameters());
	
	if(((Abs(Csup-Cinf)*R >  MaxTol) && (Abs(Lsup-Linf) > MaxTol))
	   || (T1a.TransitionType() != T2a.TransitionType())) {  
	  //-- Verifier egalement les transitions 
	  
	  IntRes2d_IntersectionSegment NewSeg(NewPoint1,NewPoint2
					      ,Opposite,ReversedParameters());
	  Append(NewSeg);
	}
	else { 
	  if(Pos1a!=IntRes2d_Middle ||  Pos2a!=IntRes2d_Middle) { 
	    Insert(NewPoint1);
	  }
	  if(Pos1b!=IntRes2d_Middle ||  Pos2b!=IntRes2d_Middle) { 
	    Insert(NewPoint2);
	  }

	}
      }
      else {
        //--Standard_Real Cmid=NormalizeOnCircleDomain(0.5*(SolutionCircle[i].Bsup+SolutionCircle[i].Binf)
	//--					   ,CIRC_Domain);        
	//--IntRes2d_IntersectionPoint NewPoint(P2a,0.5*(Linf+Lsup)
	//--				    ,Cmid
	//--				    ,T2a,T1a,ReversedParameters());
	Insert(NewPoint1);
      }
    }
  }
}




const IntRes2d_IntersectionPoint SegmentToPoint( const IntRes2d_IntersectionPoint& Pa
						,const IntRes2d_Transition& T1a
						,const IntRes2d_Transition& T2a
						,const IntRes2d_IntersectionPoint& Pb
						,const IntRes2d_Transition& T1b
						,const IntRes2d_Transition& T2b) {  
  
  if((T1b.PositionOnCurve() == IntRes2d_Middle) 
     && (T2b.PositionOnCurve() == IntRes2d_Middle)) { 
    return(Pa);
  }
  if((T1a.PositionOnCurve() == IntRes2d_Middle) 
     && (T2a.PositionOnCurve() == IntRes2d_Middle)) { 
    return(Pb);
  }
  
  IntRes2d_Transition t1 = T1a;
  IntRes2d_Transition t2 = T2a;
  Standard_Real u1 = Pa.ParamOnFirst();
  Standard_Real u2 = Pa.ParamOnSecond();
  
  
  if(t1.PositionOnCurve() == IntRes2d_Middle) { 
    t1.SetPosition(T1b.PositionOnCurve());
    u1 = Pb.ParamOnFirst();
  }
  if(t2.PositionOnCurve() == IntRes2d_Middle) {
    t2.SetPosition(T2b.PositionOnCurve());
    u2 = Pb.ParamOnSecond();
  } 
  return(IntRes2d_IntersectionPoint(Pa.Value(),u1,u2,t1,t2,Standard_False));
}