0027890: BndLib_Add2dCurve::Add(..) works incorrect on some curves
authorisn <isn@opencascade.com>
Thu, 22 Sep 2016 11:42:30 +0000 (14:42 +0300)
committerkgv <kgv@opencascade.com>
Fri, 30 Sep 2016 08:17:21 +0000 (11:17 +0300)
Draw Harness command 'gbounding' has been extended
to pass curve2d as args and to work in two modes ('normal' and optimal).

src/BRepTest/BRepTest_BasicCommands.cxx
src/BndLib/BndLib_Add2dCurve.cxx
tests/bugs/moddata_3/bug27890 [new file with mode: 0755]

index 87424fc..fff1366 100644 (file)
@@ -38,6 +38,7 @@
 #include <BRep_Builder.hxx>
 #include <BRepBndLib.hxx>
 #include <Bnd_Box.hxx>
+#include <Bnd_Box2d.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <BRepTools_WireExplorer.hxx>
@@ -486,46 +487,98 @@ static Standard_Integer optbounding(Draw_Interpretor& di,Standard_Integer n,cons
 #include <GeomAdaptor_Surface.hxx>
 #include <BndLib_AddSurface.hxx>
 #include <BndLib_Add3dCurve.hxx>
+#include <BndLib_Add2dCurve.hxx>
+#include <Draw_Segment2D.hxx>
 static Standard_Integer gbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
 {
-  if (n < 2) 
+  if (n != 2 && n != 3) 
   {
-    di << "Usage: gbounding surf/curve \n";
+    di << "Usage: gbounding surf/curve/curve2d [-o] \n";
+    di << "[-o] turn on Optimal mode ('off' by default) \n";
     return 1;
   }
-  Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
-  Bnd_Box B; Handle(Draw_Box) DB;
-  
-  if (n == 2) { 
+  else
+  {
+    Standard_Boolean IsOptimal = Standard_False;
+    if (n == 3 && !strcmp(a[2], "-o"))
+      IsOptimal = Standard_True;
+    
+    Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
+    Bnd_Box B;
+    Bnd_Box2d B2d;
+    Handle(Draw_Box) DB;
+    Standard_Boolean Is3d = Standard_True;
     Handle(Geom_Curve) C;
     Handle(Geom_Surface) S;
+    Handle_Geom2d_Curve C2d;
     S = DrawTrSurf::GetSurface(a[1]);
-    if (S.IsNull())
+    if (!S.IsNull())
     {
-      C = DrawTrSurf::GetCurve(a[1]);
+      //add surf
+      GeomAdaptor_Surface aGAS(S);
+      if (IsOptimal)
+        BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B);
+      else
+        BndLib_AddSurface::Add(aGAS, Precision::Confusion(), B);
     }
-    if(!S.IsNull())
+    else
     {
-      GeomAdaptor_Surface aGAS(S);
-      BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B);
+      C = DrawTrSurf::GetCurve(a[1]);
+      if (!C.IsNull())
+      {
+        // add cur
+        GeomAdaptor_Curve aGAC(C);
+        if (IsOptimal)
+          BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B);
+        else
+          BndLib_Add3dCurve::Add(aGAC, Precision::Confusion(), B);
+      }
+      else
+      {
+        C2d = DrawTrSurf::GetCurve2d(a[1]);
+        if (!C2d.IsNull())
+        {
+          //add cur2d
+          Is3d = Standard_False;
+          if (IsOptimal)
+            BndLib_Add2dCurve::AddOptimal(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d); 
+          else
+            BndLib_Add2dCurve::Add(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d); 
+        }
+        else
+        {
+          di << "Wrong argument \n";
+          return 1;
+        }
+      }
     }
-    else if(!C.IsNull())
+
+    if (Is3d)
     {
-      GeomAdaptor_Curve aGAC(C);
-      BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B);
+      B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
+      DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
+      dout<<DB;
+      di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
     }
     else
     {
-      di << "Wrong argument \n";
-      return 1;
+      B2d.Get(axmin,aymin,axmax,aymax);
+      gp_Pnt2d p1(axmin, aymin);
+      gp_Pnt2d p2(axmax, aymin);
+      gp_Pnt2d p3(axmax, aymax);
+      gp_Pnt2d p4(axmin, aymax);
+      Draw_Segment2D* S1 = new Draw_Segment2D(p1, p2, Draw_vert);
+      Draw_Segment2D* S2 = new Draw_Segment2D(p2, p3, Draw_vert);
+      Draw_Segment2D* S3 = new Draw_Segment2D(p3, p4, Draw_vert);
+      Draw_Segment2D* S4 = new Draw_Segment2D(p4, p1, Draw_vert);
+      dout << S1 << S2 << S3 << S4;
+      di << axmin<<" "<< aymin<<" "<< axmax<<" "<< aymax;
     }
-    B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
-    DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
-    dout<<DB;
-    di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
   }
   return 0;
-}//=======================================================================
+}
+
+//=======================================================================
 //function : findplane
 //purpose  : 
 //=======================================================================
@@ -1045,7 +1098,7 @@ void  BRepTest::BasicCommands(Draw_Interpretor& theCommands)
                  optbounding,g);
  //
   theCommands.Add("gbounding",
-                 "gbounding curve/surf ",
+                 "gbounding surf/curve/curve2d [-o] ",
                  __FILE__,
                  gbounding,g);
 
index 13ee2b2..8bf7619 100644 (file)
@@ -524,9 +524,8 @@ void BndLib_Box2dCurve::PerformOther()
   aNb=33;
   dT=(myT2-myT1)/(aNb-1);
   //
-  aT=myT1;
   for (j=0; j<aNb; ++j) {
-    aT=j*dT;
+    aT=myT1+j*dT;
     myCurve->D0(aT, aP2D);
     myBox.Add(aP2D);
   }
diff --git a/tests/bugs/moddata_3/bug27890 b/tests/bugs/moddata_3/bug27890
new file mode 100755 (executable)
index 0000000..99c5583
--- /dev/null
@@ -0,0 +1,34 @@
+puts "============"
+puts "CR27890"
+puts "==========="
+puts ""
+###############################################################################
+# BndLib_Add2dCurve::Add(..) works incorrect on some curves
+###############################################################################
+
+restore [locate_data_file bug27890_t1.draw] 
+
+set rr [gbounding bug27890_t1]
+
+regexp { *([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+) +([-0-9.+eE]+)} $rr full v1_x v1_y v2_x v2_y
+
+set tol_abs 1.0e-4
+set tol_rel 0.0001
+
+set expected_v1_x -34.660696189548446
+checkreal "v1_x" ${v1_x} ${expected_v1_x} ${tol_abs} ${tol_rel}
+
+set expected_v1_y -69.996521506152177
+checkreal "v1_y" ${v1_y} ${expected_v1_y} ${tol_abs} ${tol_rel}
+
+set expected_v2_x -15.536166915190313
+checkreal "v2_x" ${v2_x} ${expected_v2_x} ${tol_abs} ${tol_rel}
+
+set expected_v2_y -21.097502159535235
+checkreal "v2_y" ${v2_y} ${expected_v2_y} ${tol_abs} ${tol_rel}
+
+#v2d2
+view 1 -2D-  728 20 400 400
+
+2dfit
+checkview -screenshot -2d -path ${imagedir}/${test_image}.png