0024803: improve the result of v/v interference for two vertices case
authorpkv <pkv@opencascade.com>
Thu, 9 Apr 2015 13:26:40 +0000 (16:26 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 9 Apr 2015 13:28:55 +0000 (16:28 +0300)
Changes:
class BOPTools_AlgoTools
- method:
void BOPTools_AlgoTools::MakeVertex(BOPCol_ListOfShape& aLV,
                                    TopoDS_Vertex& aVnew)
has been changed.
The section for case of two vertices  has been added

Test case for issue CR24803

src/BOPTools/BOPTools_AlgoTools.cxx
tests/bugs/modalg_6/bug24803 [new file with mode: 0755]

index 5a61d53..6b5e4c5 100644 (file)
@@ -65,6 +65,7 @@
 #include <BOPCol_MapOfShape.hxx>
 //
 #include <IntTools_ShrunkRange.hxx>
+#include <Precision.hxx>
 //
 
 static
@@ -1496,13 +1497,67 @@ void BOPTools_AlgoTools::MakeVertex(BOPCol_ListOfShape& aLV,
                                     TopoDS_Vertex& aVnew)
 {
   Standard_Integer aNb;
-  Standard_Real aTi, aDi, aDmax;
-  gp_Pnt aPi, aP;
-  gp_XYZ aXYZ(0.,0.,0.), aXYZi;
-  BOPCol_ListIteratorOfListOfShape aIt;
   //
   aNb=aLV.Extent();
-  if (aNb) {
+  if (!aNb) {
+    return;
+  }
+  //
+  else if (aNb==1) {
+    aVnew=*((TopoDS_Vertex*)(&aLV.First()));
+    return;
+  }
+  //
+  else if (aNb==2) {
+    Standard_Integer m, n;
+    Standard_Real aR[2], dR, aD, aEps;
+    TopoDS_Vertex aV[2];
+    gp_Pnt aP[2];
+    BRep_Builder aBB;
+    //
+    aEps=RealEpsilon();
+    for (m=0; m<aNb; ++m) {
+      aV[m]=(!m)? 
+       *((TopoDS_Vertex*)(&aLV.First())):
+       *((TopoDS_Vertex*)(&aLV.Last()));
+      aP[m]=BRep_Tool::Pnt(aV[m]);
+      aR[m]=BRep_Tool::Tolerance(aV[m]);
+    }  
+    //
+    m=0; // max R
+    n=1; // min R
+    if (aR[0]<aR[1]) {
+      m=1;
+      n=0;
+    }
+    //
+    dR=aR[m]-aR[n]; // dR >= 0.
+    gp_Vec aVD(aP[m], aP[n]);
+    aD=aVD.Magnitude();
+    //
+    if (aD<=dR || aD<aEps) { 
+      aBB.MakeVertex (aVnew, aP[m], aR[m]);
+    }
+    else {
+      Standard_Real aRr;
+      gp_XYZ aXYZr;
+      gp_Pnt aPr;
+      //
+      aRr=0.5*(aR[m]+aR[n]+aD);
+      aXYZr=0.5*(aP[m].XYZ()+aP[n].XYZ()-aVD.XYZ()*(dR/aD));
+      aPr.SetXYZ(aXYZr);
+      //
+      aBB.MakeVertex (aVnew, aPr, aRr);
+    }
+    return;
+  }// else if (aNb==2) {
+  //
+  else { // if (aNb>2) 
+    Standard_Real aTi, aDi, aDmax;
+    gp_Pnt aPi, aP;
+    gp_XYZ aXYZ(0.,0.,0.), aXYZi;
+    BOPCol_ListIteratorOfListOfShape aIt;
+    //
     aIt.Initialize(aLV);
     for (; aIt.More(); aIt.Next()) {
       TopoDS_Vertex& aVi=*((TopoDS_Vertex*)(&aIt.Value()));
diff --git a/tests/bugs/modalg_6/bug24803 b/tests/bugs/modalg_6/bug24803
new file mode 100755 (executable)
index 0000000..210edcc
--- /dev/null
@@ -0,0 +1,67 @@
+puts "========"
+puts "OCC24803"
+puts "========"
+puts ""
+###########################################################
+# improve the result of v/v interference for two vertices case
+###########################################################
+
+set x1 0
+set y1 0
+set z1 0
+set tolerance1 1.0
+vertex v1 $x1 $y1 $z1
+settolerance v1 $tolerance1
+
+set x2 4
+set y2 0
+set z2 0
+vertex v2 $x2 $y2 $z2
+set tolerance2 3.5
+settolerance v2 $tolerance2
+
+bop v1 v2
+bopcommon res
+
+regexp {Tolerance +MAX=([-0-9.+eE]+)} [tolerance res] full MaxTolerance
+puts "MaxTolerance=$MaxTolerance"
+
+set expected_MaxTolerance 4.25
+set tol_abs_MaxTolerance 0.1
+set tol_rel_MaxTolerance 0.1
+checkreal "MaxTolerance" ${MaxTolerance} ${expected_MaxTolerance} ${tol_abs_MaxTolerance} ${tol_rel_MaxTolerance}
+
+set info [dump res]
+regexp "Tolerance : +(\[-0-9*\.+eE\]+)" $info full tolerance_res
+regexp "Point 3D : +(\[-0-9*\.+eE\]+), +(\[-0-9*\.+eE\]+), +(\[-0-9*\.+eE\]+)" $info full x_res y_res z_res
+puts "tolerance_res=$tolerance_res"
+puts "x_res=$x_res y_res=$y_res z_res=$z_res"
+
+set expected_tolerance 4.25
+set tol_abs_tolerance  0.1
+set tol_rel_tolerance 0.1
+checkreal "tolerance" ${tolerance_res} ${expected_tolerance} ${tol_abs_tolerance} ${tol_rel_tolerance}
+
+set expected_x_res 3.25
+set tol_abs_x_res  0.1
+set tol_rel_x_res 0.1
+checkreal "x_res" ${x_res} ${expected_x_res} ${tol_abs_x_res} ${tol_rel_x_res}
+
+set expected_y_res 0
+set tol_abs_y_res  0.1
+set tol_rel_y_res 0.1
+checkreal "y_res" ${y_res} ${expected_y_res} ${tol_abs_y_res} ${tol_rel_y_res}
+
+set expected_z_res 0
+set tol_abs_z_res  0.1
+set tol_rel_z_res 0.1
+checkreal "z_res" ${z_res} ${expected_z_res} ${tol_abs_z_res} ${tol_rel_z_res}
+
+circle c1 $x1 $y1 $z1 $tolerance1
+circle c2 $x2 $y2 $z2 $tolerance2
+circle c_res $x_res $y_res $z_res $tolerance_res
+
+view 1 +X+Y 465 20 400 400
+fit
+
+xwd $imagedir/${test_image}.png