0023939: Incorrect circle parameter in IntAna
[occt.git] / src / IntAna2d / IntAna2d_AnaIntersection_2.cxx
index a0b97aa..74694c9 100755 (executable)
@@ -66,7 +66,7 @@ void IntAna2d_AnaIntersection::Perform (const gp_Circ2d& C1,
     if (ang1<0) {ang1=2*M_PI+ang1;}                // On revient entre 0 et 2PI
     lpnt[0].SetValue(XS,YS,ang1,ang2);
   }
-  else if (((sum-d)>Epsilon(d)) && ((d-dif)>Epsilon(d))) {
+  else if (((sum-d)>Epsilon(sum)) && ((d-dif)>Epsilon(sum))) {
     empt=Standard_False;
     para=Standard_False;
     iden=Standard_False;
@@ -78,6 +78,11 @@ void IntAna2d_AnaIntersection::Perform (const gp_Circ2d& C1,
     Standard_Real ref2=Ox2.Angle(ax);                       // Resultat entre -PI et +PI
 
     Standard_Real l1=(d*d + R1*R1 -R2*R2)/(2.0*d);
+    Standard_Real aDet = R1*R1-l1*l1;
+    if(aDet < 0.) {
+      aDet = 0.;
+      l1 = (l1 > 0 ? R1 : - R1);
+    }
     Standard_Real h= Sqrt(R1*R1-l1*l1);
 
     Standard_Real XS1= C1.Location().X() + l1*ax.X()/d - h*ax.Y()/d;
@@ -143,12 +148,15 @@ void IntAna2d_AnaIntersection::Perform (const gp_Circ2d& C1,
     lpnt[0].SetValue(XS1,YS1,ang11,ang21);
     lpnt[1].SetValue(XS2,YS2,ang12,ang22);
   }
-  else if (Abs(d-dif)<=Epsilon(d)) {    // Cercles tangents interieurs
+  else if (Abs(d-dif)<=Epsilon(sum)) {    // Cercles tangents interieurs
     empt=Standard_False;
     para=Standard_False;
     iden=Standard_False;
     nbp=1;
     gp_Vec2d ax(C1.Location(),C2.Location());
+    if(C1.Radius() < C2.Radius())
+      ax.Reverse();
+
     gp_Vec2d Ox1(C1.XAxis().Direction());
     gp_Vec2d Ox2(C2.XAxis().Direction());
     Standard_Real ang1=Ox1.Angle(ax);                       // Resultat entre -PI et +PI