]> OCCT Git - occt.git/commitdiff
0024905: Boolean cut produced invalid result
authornbv <nbv@opencascade.com>
Tue, 23 Oct 2018 11:07:11 +0000 (14:07 +0300)
committerapn <apn@opencascade.com>
Wed, 24 Oct 2018 15:55:07 +0000 (18:55 +0300)
The method BOPAlgo_PaveFiller::PutClosingPaveOnCurve(...) has been improved in order to take into account extended vertex tolerance.

src/BOPAlgo/BOPAlgo_PaveFiller_6.cxx
tests/bugs/modalg_7/bug24905 [new file with mode: 0644]

index d56ec9503b92b88b6f5866d4ba8a12f585697a7e..e7c92ad7a43b77188e7156c91f7dd64db4809bb2 100644 (file)
@@ -2740,42 +2740,63 @@ void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
   aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
 
   // Find the pave which has been put at one of the ends
+  BOPDS_Pave aPave;
+  // Index of the vertex put at one of the ends
   Standard_Integer nV = -1;
   // Keep the opposite parameter
   Standard_Real aTOp = 0.;
-
-  Standard_Boolean bFound = Standard_False;
+  // Keep the opposite bounding point
+  gp_Pnt aPOp;
 
   Handle(BOPDS_PaveBlock)& aPB = aNC.ChangePaveBlock1();
   BOPDS_ListOfPave& aLP = aPB->ChangeExtPaves();
   BOPDS_ListIteratorOfListOfPave aItLP(aLP);
-  for (; aItLP.More() && !bFound; aItLP.Next())
+  for (; aItLP.More() && (nV < 0); aItLP.Next())
   {
-    const BOPDS_Pave& aPC = aItLP.Value();
-    Standard_Real aTC = aPC.Parameter();
+    aPave = aItLP.Value();
+    Standard_Real aTC = aPave.Parameter();
     for (Standard_Integer j = 0; j < 2; ++j)
     {
       if (Abs(aTC - aT[j]) < Precision::PConfusion())
       {
-        nV = aPC.Index();
+        nV = aPave.Index();
         aTOp = (!j) ? aT[1] : aT[0];
-        bFound = Standard_True;
+        aPOp = (!j) ? aP[1] : aP[0];
         break;
       }
     }
   }
 
-  if (!bFound)
+  if (nV < 0)
+    // No paves on the bounds of the curve
     return;
 
   // Check if the curve is closed using the tolerance
   // of found vertex
   const TopoDS_Vertex& aV = TopoDS::Vertex(myDS->Shape(nV));
-  const Standard_Real aTolV = BRep_Tool::Tolerance(aV);
-
-  Standard_Real aDist = aP[0].Distance(aP[1]);
-  if (aDist > aTolV)
+  Standard_Real aTolV = BRep_Tool::Tolerance(aV);
+  gp_Pnt aPV = BRep_Tool::Pnt(aV);
+  // Tolerance for the point on the curve
+  Standard_Real aTolP = Max(aNC.Tolerance(), aNC.TangentialTolerance());
+  aTolP += Precision::Confusion();
+
+  const Standard_Real aDistVP = aPV.Distance(aPOp);
+  if (aDistVP > aTolV + aTolP)
+  {
+    // Curve is not closed
     return;
+  }
+
+  if (aDistVP > aTolV)
+  {
+    Standard_Integer nVn = UpdateVertex(nV, aDistVP);
+    if (nVn != nV)
+    {
+      aPave.SetIndex(nVn);
+      nV = nVn;
+    }
+    aTolV = BRep_Tool::Tolerance(TopoDS::Vertex(myDS->Shape(nV)));
+  }
 
   // Check if there will be valid range on the curve
   Standard_Real aFirst, aLast;
@@ -2784,15 +2805,17 @@ void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
                                aT[1], aP[1], aTolV,
                                aFirst, aLast))
   {
+    // No valid range
     return;
   }
 
   // Add closing pave to the curve
-  BOPDS_Pave aPave;
-  aPave.SetIndex(nV);
-  aPave.SetParameter(aTOp);
-  aLP.Append(aPave);
+  BOPDS_Pave aNewPave;
+  aNewPave.SetIndex(nV);
+  aNewPave.SetParameter(aTOp);
+  aLP.Append(aNewPave);
 }
+
 //=======================================================================
 //function : PreparePostTreatFF
 //purpose  : 
diff --git a/tests/bugs/modalg_7/bug24905 b/tests/bugs/modalg_7/bug24905
new file mode 100644 (file)
index 0000000..f8ce504
--- /dev/null
@@ -0,0 +1,67 @@
+puts "========"
+puts "0024905: Boolean cut produced invalid result"
+puts "========"
+puts ""
+
+circle c1 0 0 0 0 -1 0 75
+circle c2 0 0 0 0 -1 0 65
+mkedge c1 c1
+mkedge c2 c2
+wire c1 c1
+wire c2 c2
+orientation c2 R
+mkplane f1 c1 1
+add c2 f1
+prism p1 f1 0 1000 0
+trotate p1 0 0 0 0 0 1 180
+circle c3 50 500 -2000 0 0 1 50
+mkedge c3 c3
+wire c3 c3
+mkplane f2 c3 1
+prism p2 f2 0 0 4000
+trotate p2 0 500 0 1 0 0 -77
+trotate p2 0 0 0 0 0 1 180
+
+bclearobjects
+bcleartools
+baddobjects p1
+baddtools p2
+
+bfillds
+
+bbop r_0 0
+bbop r_1 1
+bbop r_2 2
+bbop r_3 3
+bbop r_4 4
+
+for {set i 0} {$i <= 4} {incr i} {
+  checkshape r_$i
+  if {[regexp "Faulties" [ bopargcheck r_$i ]]} {
+    puts "Error: bopargcheck has found some faulties in r_$i"
+  }
+}
+
+
+checknbshapes r_0 -solid 1 -shell 1 -face 5 -wire 6
+checkprops r_0 -s 196255 -v 857818
+
+checknbshapes r_1 -solid 1 -shell 1 -face 9 -wire 13
+checkprops r_1 -s 1.96453e+06 -v 3.49563e+07
+
+checknbshapes r_2 -solid 1 -shell 1 -face 7 -wire 11
+checkprops r_2 -s 742474 -v 3.54041e+06
+
+checknbshapes r_3 -solid 2 -shell 2 -face 7 -wire 8
+checkprops r_3 -s 1.41831e+06 -v 3.05581e+07
+
+checknbshapes r_4 -vertex 8 -edge 8
+checkprops r_4 -l 3965.07
+
+checksection r_4 -r 0
+
+# CUT
+copy r_2 result
+checkmaxtol result -min_tol 1.0e-4
+checkview -display result -2d -path ${imagedir}/${test_image}.png
+