0029695: Shape Healing - infinite loop in ShapeFix_IntersectionTool
authorgka <gka@opencascade.com>
Mon, 16 Apr 2018 08:58:43 +0000 (11:58 +0300)
committerabv <abv@opencascade.com>
Wed, 23 May 2018 02:43:36 +0000 (05:43 +0300)
Avoid splitting of wrong edge in ShapeFix_IntersectionTool.
Added protection for case when index of edge to be split is out of range.

Added test bugs heal bug29695

src/ShapeFix/ShapeFix_IntersectionTool.cxx
tests/bugs/heal/bug29695 [new file with mode: 0644]

index 9d17b1b..223143e 100644 (file)
@@ -253,6 +253,8 @@ Standard_Boolean ShapeFix_IntersectionTool::SplitEdge1(const Handle(ShapeExtend_
                                                        const Standard_Real preci,
                                                        ShapeFix_DataMapOfShapeBox2d& boxes) const
 {
+  Standard_ASSERT_RETURN (num > 0 && num <= sewd->NbEdges(), "Edge index out of range", Standard_False);
+
   TopoDS_Edge edge = sewd->Edge(num);
   TopoDS_Edge newE1, newE2;
   if(!SplitEdge(edge,param,vert,face,newE1,newE2,preci)) return Standard_False;
@@ -1801,24 +1803,22 @@ Standard_Boolean ShapeFix_IntersectionTool::FixIntersectingWires
                       }
                     }
                     if( akey1==0 && akey2==0 ) {
+                      int num1split2 = num1; // what edge to split by point 2
                       if(SplitEdge1(sewd1, face, num1, p11, NewV1, tolV1, boxes1)) {
                         NbModif++;
-                      }
-                      tmpE = sewd1->Edge(num1);
-                      Standard_Real a,b;
-                      Handle(Geom2d_Curve) c2d;
-                      sae.PCurve(tmpE,face,c2d,a,b,Standard_False);
-                      if( (a-p12)*(b-p12)>0 ) { // p12 - external for [a,b] => split next edge
-                        if(SplitEdge1(sewd1, face, num1+1, p12, NewV2, tolV2, boxes1) ) {
-                          NbModif++;
-                          numseg1=num1+1;
+                        tmpE = sewd1->Edge (num1);
+                        Standard_Real a, b;
+                        Handle (Geom2d_Curve) c2d;
+                        sae.PCurve (tmpE, face, c2d, a, b, Standard_False);
+                        if ((a - p12)*(b - p12) > 0)
+                        { // p12 - external for [a,b] => split next edge
+                          num1split2++;
                         }
                       }
-                      else {
-                        if(SplitEdge1(sewd1, face, num1, p12, NewV2, tolV2, boxes1) ) {
-                          NbModif++;
-                          numseg1=num1+1;
-                        }
+                      if (SplitEdge1 (sewd1, face, num1split2, p12, NewV2, tolV2, boxes1))
+                      {
+                        NbModif++;
+                        numseg1=num1+1;
                       }
                     }
                     SegE = sewd1->Edge(numseg1); // get edge from segment
@@ -1885,25 +1885,23 @@ Standard_Boolean ShapeFix_IntersectionTool::FixIntersectingWires
                       }
                     }
                     if( akey1==0 && akey2==0 ) {
+                      int num2split2 = num2;
                       if(SplitEdge1(sewd2, face, num2, p21, NewV1, tolV1, boxes2)) {
                         NbModif++;
                         numseg2=num2+1;
-                      }
-                      tmpE = sewd2->Edge(num2);
-                      Standard_Real a,b;
-                      Handle(Geom2d_Curve) c2d;
-                      sae.PCurve(tmpE,face,c2d,a,b,Standard_False);
-                      if( (a-p22)*(b-p22)>0 ) { // p22 - external for [a,b] => split next edge
-                        if(SplitEdge1(sewd2, face, num2+1, p22, NewV2, tolV2, boxes2) ) {
-                          NbModif++;
-                          numseg2=num2+1;
+                        tmpE = sewd2->Edge (num2);
+                        Standard_Real a, b;
+                        Handle (Geom2d_Curve) c2d;
+                        sae.PCurve (tmpE, face, c2d, a, b, Standard_False);
+                        if ((a - p22)*(b - p22) > 0)
+                        { // p22 - external for [a,b] => split next edge
+                          num2split2++;
                         }
                       }
-                      else {
-                        if(SplitEdge1(sewd2, face, num2, p22, NewV2, tolV2, boxes2) ) {
-                          NbModif++;
-                          numseg2=num2+1;
-                        }
+                      if (SplitEdge1 (sewd2, face, num2split2, p22, NewV2, tolV2, boxes2))
+                      {
+                        NbModif++;
+                        numseg2 = num2 + 1;
                       }
                     }
                     tmpE = sewd2->Edge(numseg2);
diff --git a/tests/bugs/heal/bug29695 b/tests/bugs/heal/bug29695
new file mode 100644 (file)
index 0000000..df1ac6b
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+restore [locate_data_file bug29695_badface.brep] a
+fixshape result a
+
+checkshape result
+