0025488: Wrong result of two trimmed cylinders intersection
authornbv <nbv@opencascade.com>
Fri, 21 Nov 2014 11:44:01 +0000 (14:44 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 21 Nov 2014 11:47:57 +0000 (14:47 +0300)
1. Function IsSame(...) for IntSurf_PntOn2S was added (see IntSurf_PntOn2S.cdl for detail information).
2. Inserting additional points is forbidden if existing WLine contains only two points coincided.

Test-case for issue #25488

src/IntPatch/IntPatch_ImpImpIntersection_4.gxx
src/IntSurf/IntSurf_PntOn2S.cdl
src/IntSurf/IntSurf_PntOn2S.cxx
tests/bugs/modalg_5/bug25488 [new file with mode: 0644]

index 11f3040..c73f08d 100644 (file)
@@ -2053,7 +2053,7 @@ Standard_Boolean IntCyCyTrim( const IntSurf_Quadric& theQuad1,
               aWL1FindStatus = 2; //start a new line
           }
         }
-      
+        
         if( ((aUSurf2f-aU22) <= theTol2D) &&
             ((aU22-aUSurf2l) <= theTol2D) && 
             ((aVSurf1f - aV12) <= theTol2D) &&
@@ -2237,15 +2237,29 @@ Standard_Boolean IntCyCyTrim( const IntSurf_Quadric& theQuad1,
       }
       else if(aWLine1->NbPnts() > 1)
       {
-        isTheEmpty = Standard_False;
-        isAddedIntoWL1 = Standard_True;
+        Standard_Boolean isGood = Standard_True;
+
+        if(aWLine1->NbPnts() == 2)
+        {
+          const IntSurf_PntOn2S& aPf = aWLine1->Point(1);
+          const IntSurf_PntOn2S& aPl = aWLine1->Point(2);
+
+          if(aPf.IsSame(aPl, Precision::Confusion()))
+            isGood = Standard_False;
+        }
+
+        if(isGood)
+        {
+          isTheEmpty = Standard_False;
+          isAddedIntoWL1 = Standard_True;
 
-        SeekAdditionalPoints(theQuad1, theQuad2, aWLine1->Curve(), 
-                              anEquationCoeffs, aNbPoints, aUSurf2f, aUSurf2l,
-                              theTol2D, aPeriod, 1.0, isTheReverse);
+          SeekAdditionalPoints( theQuad1, theQuad2, aWLine1->Curve(), 
+                                anEquationCoeffs, aNbPoints, aUSurf2f, aUSurf2l,
+                                theTol2D, aPeriod, 1.0, isTheReverse);
 
-        aWLine1->ComputeVertexParameters(theTol3D);
-        theSlin.Append(aWLine1);
+          aWLine1->ComputeVertexParameters(theTol3D);
+          theSlin.Append(aWLine1);
+        }
       }
       else
       {
@@ -2267,15 +2281,28 @@ Standard_Boolean IntCyCyTrim( const IntSurf_Quadric& theQuad1,
       }
       else if(aWLine2->NbPnts() > 1)
       {
-        isTheEmpty = Standard_False;
-        isAddedIntoWL2 = Standard_True;
+        Standard_Boolean isGood = Standard_True;
+        if(aWLine2->NbPnts() == 2)
+        {
+          const IntSurf_PntOn2S& aPf = aWLine2->Point(1);
+          const IntSurf_PntOn2S& aPl = aWLine2->Point(2);
+
+          if(aPf.IsSame(aPl, Precision::Confusion()))
+            isGood = Standard_False;
+        }
+
+        if(isGood)
+        {
+          isTheEmpty = Standard_False;
+          isAddedIntoWL2 = Standard_True;
 
-        SeekAdditionalPoints(theQuad1, theQuad2, aWLine2->Curve(),
-                              anEquationCoeffs, aNbPoints, aUSurf2f, aUSurf2l,
-                              theTol2D, aPeriod, -1.0, isTheReverse);
+          SeekAdditionalPoints(theQuad1, theQuad2, aWLine2->Curve(),
+                                anEquationCoeffs, aNbPoints, aUSurf2f, aUSurf2l,
+                                theTol2D, aPeriod, -1.0, isTheReverse);
 
-        aWLine2->ComputeVertexParameters(theTol3D);
-        theSlin.Append(aWLine2);
+          aWLine2->ComputeVertexParameters(theTol3D);
+          theSlin.Append(aWLine2);
+        }
       }
       else
       {
index ca9ed14..f3943d3 100644 (file)
@@ -119,6 +119,15 @@ is
 
        is static;
 
+    IsSame(me; theOterPoint : PntOn2S from IntSurf;
+            theTol3D, theTol2D: Real from Standard = 0.0)
+            
+  ---Purpose: Returns TRUE if 2D- and 3D-coordinates of theOterPoint are equal to
+   --         corresponding coordinates of me (with given tolerance).
+   --         If theTol2D == 0.0 we will compare 3D-points only.
+   
+        returns Boolean from Standard;
+  
 
 fields
 
index ff0d19f..4c203fb 100644 (file)
@@ -49,4 +49,31 @@ void IntSurf_PntOn2S::SetValue (const Standard_Boolean OnFirst,
 }
 
 
+Standard_Boolean IntSurf_PntOn2S::IsSame( const IntSurf_PntOn2S& theOterPoint,
+                                          const Standard_Real theTol3D,
+                                          const Standard_Real theTol2D) const
+{
+  if(pt.SquareDistance(theOterPoint.Value()) > theTol3D*theTol3D)
+    return Standard_False;
 
+  if(IsEqual(theTol2D, 0.0))
+  {//We need not compare 2D-coordinates of the points
+    return Standard_True;
+  }
+
+  Standard_Real aU1 = 0.0, aV1 = 0.0, aU2 = 0.0, aV2 = 0.0;
+  theOterPoint.Parameters(aU1, aV1, aU2, aV2);
+
+  gp_Pnt2d aP1(u1, v1), aP2(aU1, aV1);
+
+  if(!aP1.IsEqual(aP2, theTol2D))
+    return Standard_False;
+
+  aP1.SetCoord(u2, v2);
+  aP2.SetCoord(aU2, aV2);
+
+  if(!aP1.IsEqual(aP2, theTol2D))
+    return Standard_False;
+
+  return Standard_True;
+}
diff --git a/tests/bugs/modalg_5/bug25488 b/tests/bugs/modalg_5/bug25488
new file mode 100644 (file)
index 0000000..668b109
--- /dev/null
@@ -0,0 +1,33 @@
+puts "========"
+puts "OCC25488"
+puts "========"
+puts ""
+######################################################
+# Wrong result of two trimmed cylinders intersection
+######################################################
+
+set Tolerance 3.0e-7
+set D_good 0.
+
+restore [locate_data_file OCC25488_sb1_1t.draw] sb1
+restore [locate_data_file OCC25488_sb2_1t.draw] sb2
+
+set bug_info [intersect res sb1 sb2]
+
+set i 0
+while {$i != [llength $bug_info]} {
+  set res_i [lindex $bug_info $i]
+  dlog reset
+  dlog on
+  xdistcs ${res_i} sb1 0 1 10
+  set BugLog [dlog get]
+  set BugList [split ${BugLog} {TD= \t\n}]
+  checkList ${BugList} ${Tolerance} ${D_good}
+  dlog reset
+  dlog on
+  xdistcs ${res_i} sb2 0 1 10
+  set BugLog [dlog get]
+  set BugList [split ${BugLog} {TD= \t\n}]
+  checkList ${BugList} ${Tolerance} ${D_good}
+  set i [expr {$i + 1}]
+}