0030704: Modeling Data, Bnd_OBB - Oriented bounding box gives a wrong result if a...
authorvro <vro@opencascade.com>
Thu, 5 Sep 2019 08:23:30 +0000 (11:23 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 6 Sep 2019 16:23:18 +0000 (19:23 +0300)
Added protection on a void box to methods Bnd_OBB::Add() to escape taking into account "heap trash" coordinates of a void box.

src/Bnd/Bnd_OBB.cxx
src/QABugs/QABugs_20.cxx
tests/bugs/moddata_3/bug30704 [new file with mode: 0644]

index 0120cfe..6fd3dc7 100644 (file)
@@ -973,11 +973,24 @@ Standard_Boolean Bnd_OBB::IsCompletelyInside(const Bnd_OBB& theOther) const
 // =======================================================================
 void Bnd_OBB::Add(const gp_Pnt& theP)
 {
-  gp_Pnt aList[9];
-  GetVertex(aList);
-  aList[8] = theP;
-
-  ReBuild(TColgp_Array1OfPnt(aList[0], 0, 8));
+  if (IsVoid())
+  {
+    myCenter = theP.XYZ();
+    myAxes[0] = gp::DX().XYZ();
+    myAxes[1] = gp::DY().XYZ();
+    myAxes[2] = gp::DZ().XYZ();
+    myHDims[0] = 0.0;
+    myHDims[1] = 0.0;
+    myHDims[2] = 0.0;
+    myIsAABox = Standard_True;
+  }
+  else
+  {
+    gp_Pnt aList[9];
+    GetVertex(aList);
+    aList[8] = theP;
+    ReBuild(TColgp_Array1OfPnt(aList[0], 0, 8));
+  }
 }
 
 // =======================================================================
@@ -986,9 +999,26 @@ void Bnd_OBB::Add(const gp_Pnt& theP)
 // =======================================================================
 void Bnd_OBB::Add(const Bnd_OBB& theOther)
 {
-  gp_Pnt aList[16];
-  GetVertex(&aList[0]);
-  theOther.GetVertex(&aList[8]);
-  ReBuild(TColgp_Array1OfPnt(aList[0], 0, 15));
+  if (!theOther.IsVoid())
+  {
+    if (IsVoid())
+    {
+      myCenter = theOther.myCenter;
+      myAxes[0] = theOther.myAxes[0];
+      myAxes[1] = theOther.myAxes[1];
+      myAxes[2] = theOther.myAxes[2];
+      myHDims[0] = theOther.myHDims[0];
+      myHDims[1] = theOther.myHDims[1];
+      myHDims[2] = theOther.myHDims[2];
+      myIsAABox = theOther.myIsAABox;
+    }
+    else
+    {
+      gp_Pnt aList[16];
+      GetVertex(&aList[0]);
+      theOther.GetVertex(&aList[8]);
+      ReBuild(TColgp_Array1OfPnt(aList[0], 0, 15));
+    }
+  }
 }
 
index 996c7b8..b9c898e 100644 (file)
@@ -3239,6 +3239,38 @@ static Standard_Integer OCC30869 (Draw_Interpretor& theDI, Standard_Integer theA
   return 0;
 }
 
+#include <BRepPrimAPI_MakeBox.hxx>
+static Standard_Integer OCC30704(Draw_Interpretor& di, Standard_Integer, const char**)
+{
+  // Make a shape somewhere far from (0, 0, 0).
+  BRepPrimAPI_MakeBox mkBox(gp_Pnt(100, 100, 100), 100, 100, 100);
+  const TopoDS_Shape& box = mkBox.Shape();
+
+  // Add a bounding box of a shape to a void bounding box.
+  Bnd_OBB aVoidBox, aBox;
+  BRepBndLib::AddOBB(box, aBox, Standard_False, Standard_False, Standard_False);
+  aVoidBox.Add(aBox);
+
+  // Print the center point of the bounding box.
+  const gp_XYZ& center = aVoidBox.Center();
+  di << center.X() << " " << center.Y() << " " << center.Z();
+  return 0;
+}
+static Standard_Integer OCC30704_1(Draw_Interpretor& di, Standard_Integer, const char**)
+{
+  // A point.
+  gp_Pnt aP(100, 200, 300);
+
+  // Add the point to a void bounding box.
+  Bnd_OBB aVoidBox;
+  aVoidBox.Add(aP);
+
+  // Print the center point of the bounding box.
+  const gp_XYZ& center = aVoidBox.Center();
+  di << center.X() << " " << center.Y() << " " << center.Z();
+  return 0;
+}
+
 void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
 
@@ -3296,5 +3328,8 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
                                "Usage: OCC30869 wire",
                    __FILE__, OCC30869, group);
 
+  theCommands.Add("OCC30704", "OCC30704", __FILE__, OCC30704, group);
+  theCommands.Add("OCC30704_1", "OCC30704_1", __FILE__, OCC30704_1, group);
+
   return;
 }
diff --git a/tests/bugs/moddata_3/bug30704 b/tests/bugs/moddata_3/bug30704
new file mode 100644 (file)
index 0000000..244018e
--- /dev/null
@@ -0,0 +1,15 @@
+puts "============"
+puts "0030704: Oriented bounding box (Bnd_OBB) gives a wrong result if a box is added to a void box"
+puts "============"
+
+pload QAcommands
+
+set ret1 [OCC30704]
+if { ${ret1} != "150 150 150" } {
+    puts "Error: add bounding box to void bounding box"
+}
+
+set ret2 [OCC30704_1]
+if { ${ret2} != "100 200 300" } {
+    puts "Error: add point to void bounding box"
+}