0027162: Draw command "(2d)extrema" incorrectly represent underlying algorithm results
authoraml <aml@opencascade.com>
Tue, 16 Feb 2016 12:47:38 +0000 (15:47 +0300)
committerabv <abv@opencascade.com>
Sat, 20 Feb 2016 07:10:03 +0000 (10:10 +0300)
Correct handling of infinity solutions added for Curve / Curve case.
Unused code deleted.
Test cases updated to the new behavior.

src/Extrema/Extrema_ExtCC2d.cxx
src/GeometryTest/GeometryTest_API2dCommands.cxx
src/GeometryTest/GeometryTest_APICommands.cxx
src/GeomliteTest/GeomliteTest_API2dCommands.cxx
tests/bugs/modalg_6/bug26075

index 957a044..1bbe5d8 100644 (file)
@@ -521,33 +521,30 @@ void Extrema_ExtCC2d::Results(const Extrema_ECC2d& AlgExt,
   if (myDone)
   {
     myIsPar = AlgExt.IsParallel();
-    if (!myIsPar)
+    NbExt = AlgExt.NbExt();
+    for (i = 1; i <= NbExt; i++)
     {
-      NbExt = AlgExt.NbExt();
-      for (i = 1; i <= NbExt; i++)
+      // Verification de la validite des parametres pour le cas trimme:
+      AlgExt.Points(i, P1, P2);
+      U = P1.Parameter();
+      if (Period1 != 0.0) 
+        U = ElCLib::InPeriod(U,Ut11,Ut11+Period1);
+      U2 = P2.Parameter();
+      if (Period2 != 0.0) 
+        U2 = ElCLib::InPeriod(U2,Ut21,Ut21+Period2);
+
+      if ((U  >= Ut11 - Precision::PConfusion())  && 
+        (U  <= Ut12 + Precision::PConfusion())  &&
+        (U2 >= Ut21 - Precision::PConfusion())  &&
+        (U2 <= Ut22 + Precision::PConfusion()))
       {
-        // Verification de la validite des parametres pour le cas trimme:
-        AlgExt.Points(i, P1, P2);
-        U = P1.Parameter();
-        if (Period1 != 0.0) 
-          U = ElCLib::InPeriod(U,Ut11,Ut11+Period1);
-        U2 = P2.Parameter();
-        if (Period2 != 0.0) 
-          U2 = ElCLib::InPeriod(U2,Ut21,Ut21+Period2);
-
-        if ((U  >= Ut11 - Precision::PConfusion())  && 
-            (U  <= Ut12 + Precision::PConfusion())  &&
-            (U2 >= Ut21 - Precision::PConfusion())  &&
-            (U2 <= Ut22 + Precision::PConfusion()))
-        {
-            mynbext++;
-            Val = AlgExt.SquareDistance(i);
-            P1.SetValues(U, P1.Value());
-            P2.SetValues(U2, P2.Value());
-            mySqDist.Append(Val);
-            mypoints.Append(P1);
-            mypoints.Append(P2);
-        }
+        mynbext++;
+        Val = AlgExt.SquareDistance(i);
+        P1.SetValues(U, P1.Value());
+        P2.SetValues(U2, P2.Value());
+        mySqDist.Append(Val);
+        mypoints.Append(P1);
+        mypoints.Append(P2);
       }
     }
 
index 5210f6f..45fd7d7 100644 (file)
@@ -205,50 +205,6 @@ static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const ch
 
 }
 
-//=======================================================================
-//function : extrema
-//purpose  : 
-//=======================================================================
-
-static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
-{
-  if ( n<3) return 1;
-
-  Handle(Geom2d_Curve)   GC1, GC2;
-
-  Standard_Real U1f,U1l,U2f,U2l;
-
-  GC1 = DrawTrSurf::GetCurve2d(a[1]);
-  if ( GC1.IsNull())
-    return 1;
-  U1f = GC1->FirstParameter();
-  U1l = GC1->LastParameter();
-
-  GC2 = DrawTrSurf::GetCurve2d(a[2]);
-  if ( GC2.IsNull())
-    return 1;
-  U2f = GC2->FirstParameter();
-  U2l = GC2->LastParameter();
-
-  char name[100];
-
-  Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
-  for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
-    gp_Pnt2d P1,P2;
-    Ex.Points(i,P1,P2);
-    Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2));
-    Handle(Geom2d_TrimmedCurve) CT = 
-      new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2));
-    Sprintf(name,"%s%d","ext_",i);
-    char* temp = name; // portage WNT
-    DrawTrSurf::Set(temp, CT);
-    di << name << " ";
-  }
-
-  return 0;
-}
-
-
 //=======================================================================
 //function : intersect
 //purpose  : 
@@ -324,9 +280,6 @@ void GeometryTest::API2dCommands(Draw_Interpretor& theCommands)
 
   g = "GEOMETRY curves and surfaces analysis";
 
-  theCommands.Add("2dextrema", "extrema curve curve",__FILE__,
-                 extrema,g);
-
   g = "GEOMETRY intersections";
 
   theCommands.Add("2dintersect", "intersect curve curve",__FILE__,
index a4ffdcc..0bf179c 100644 (file)
@@ -332,6 +332,8 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
   Standard_Boolean C2 = Standard_False;
   Standard_Boolean S1 = Standard_False;
   Standard_Boolean S2 = Standard_False;
+  Standard_Boolean isInfinitySolutions = Standard_False;
+  Standard_Real aMinDist = RealLast();
 
   Standard_Real U1f, U1l, U2f, U2l, V1f = 0., V1l = 0., V2f = 0., V2l = 0.;
 
@@ -368,10 +370,9 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
   if (C1 && C2)
   {
     GeomAPI_ExtremaCurveCurve Ex(GC1, GC2, U1f, U1l, U2f, U2l);
-    if (!Ex.Extrema().IsParallel())
+
+    for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
     {
-      for (Standard_Integer aJ = 1; aJ <= Ex.NbExtrema(); ++aJ)
-      {
         gp_Pnt aP1, aP2;
         Ex.Points(aJ, aP1, aP2);
         aPnts1.Append(aP1);
@@ -381,12 +382,10 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
         Ex.Parameters(aJ, aU1, aU2);
         aPrms[0].Append(aU1);
         aPrms[2].Append(aU2);
-      }
-    }
-    else
-    {
-      di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
     }
+    // Since GeomAPI cannot provide access to flag directly.
+    isInfinitySolutions = Ex.Extrema().IsParallel();
+    aMinDist = Ex.LowerDistance();
   }
   else if (C1 && S2)
   {
@@ -447,9 +446,14 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
 
   // Output points.
   const Standard_Integer aPntCount = aPnts1.Size();
-  if (aPntCount == 0)
+  if (aPntCount == 0 || isInfinitySolutions)
   {
-    di << "No solutions!\n";
+    // Infinity solutions flag may be set with 0 number of 
+    // solutions in analytic extrema Curve/Curve.
+    if (isInfinitySolutions) 
+      di << "Infinite number of extremas, distance = " << aMinDist << "\n";
+    else
+      di << "No solutions!\n";
   }
   for (Standard_Integer aJ = 1; aJ <= aPntCount; aJ++)
   {
index 3effd51..5de5e67 100644 (file)
@@ -241,18 +241,26 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
   char name[100];
 
   Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
-
-// modified by APV (compilation error - LINUX)
-//  for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
-  Standard_Integer i;
+  Standard_Boolean isInfinitySolutions = Ex.Extrema().IsParallel();
   const Standard_Integer aNExtr = Ex.NbExtrema();
-  for ( i = 1; i <= aNExtr; i++) {
-// modified by APV (compilation error - LINUX)
 
+  if (aNExtr == 0 || isInfinitySolutions)
+  {
+    // Infinity solutions flag may be set with 0 number of 
+    // solutions in analytic extrema Curve/Curve.
+    if (isInfinitySolutions) 
+      di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
+    else
+      di << "No solutions!\n";
+  }
+
+  for (Standard_Integer i = 1; i <= aNExtr; i++)
+  {
     gp_Pnt2d P1,P2;
     Ex.Points(i,P1,P2);
     di << "dist " << i << ": " << Ex.Distance(i) << "  ";
-    if (Ex.Distance(i) <= Precision::PConfusion()) {
+    if (Ex.Distance(i) <= Precision::PConfusion())
+    {
       Handle(Draw_Marker2D) mark = new Draw_Marker2D( P1, Draw_X, Draw_vert); 
       dout << mark;
       dout.Flush();
@@ -261,7 +269,8 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
       DrawTrSurf::Set(temp, P1);
       di << name << "\n";
     }
-    else {
+    else
+    {
       Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2));
       Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2));
       Sprintf(name,"%s%d","ext_",i);
@@ -270,8 +279,6 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const
       di << name << "\n";
     }
   }
-  if (i==1)
-    di << "No solutions!\n";
 
   return 0;
 }
index 19109de..c7cff4d 100644 (file)
@@ -12,7 +12,7 @@ mkcurve c1 s1
 mkcurve c2 s2
 set bug_info [extrema c1 c2]
 
-set bug_info [string range $bug_info [expr {[string first "\n" $bug_info] + 1}] [expr {[string last "\n" $bug_info] - 1}]]
-if {$bug_info != "No solutions!"} {
+set bug_info [string range $bug_info [expr {[string first "Infinite" $bug_info]}] [expr {[string first "distance" $bug_info] - 3}]]
+if {$bug_info != "Infinite number of extremas"} {
   puts "ERROR: OCC26075 is reproduced. Flag IsParallel is not returned."
 }