From 5c59b8e0509b0c5d94ce758f80c0f017e5c4969a Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Oct 2021 20:31:39 +0200 Subject: [PATCH] Mesh: [skip ci] add unit tests for coplanar and intersecting triangles --- src/Mod/Mesh/App/Core/Elements.cpp | 7 ++++--- src/Mod/Mesh/App/MeshTestsApp.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Mod/Mesh/App/Core/Elements.cpp b/src/Mod/Mesh/App/Core/Elements.cpp index b3d41952bc..9366fa1415 100644 --- a/src/Mod/Mesh/App/Core/Elements.cpp +++ b/src/Mod/Mesh/App/Core/Elements.cpp @@ -326,8 +326,7 @@ bool MeshGeomEdge::IntersectWithEdge (const MeshGeomEdge &edge, Base::Vector3f & }; if (is_in_range(t) && is_in_range(u)) { - res = p + t * r; - res = q + u * s; + res = p + t * r; // equal to q + u * s return true; } @@ -1088,7 +1087,9 @@ int MeshGeomFacet::IntersectWithFacet (const MeshGeomFacet& rclFacet, } } - if (intersections.size() == 2) { + // If triangles overlap there can be more than two intersection points + // In that case use any two of them. + if (intersections.size() >= 2) { rclPt0 = intersections[0]; rclPt1 = intersections[1]; } diff --git a/src/Mod/Mesh/App/MeshTestsApp.py b/src/Mod/Mesh/App/MeshTestsApp.py index c7304fcabf..01712ef519 100644 --- a/src/Mod/Mesh/App/MeshTestsApp.py +++ b/src/Mod/Mesh/App/MeshTestsApp.py @@ -226,6 +226,31 @@ class MeshGeoTestCases(unittest.TestCase): res=f1.intersect(f2) self.assertTrue(len(res) == 0) + def testIntersectionCoplanar(self): + self.planarMesh.append( [0.,10.,10.] ) + self.planarMesh.append( [10.,0.,10.] ) + self.planarMesh.append( [10.,10.,10.] ) + self.planarMesh.append( [6.,8.,10.] ) + self.planarMesh.append( [16.,8.,10.] ) + self.planarMesh.append( [6.,18.,10.] ) + planarMeshObject = Mesh.Mesh(self.planarMesh) + f1 = planarMeshObject.Facets[0] + f2 = planarMeshObject.Facets[1] + res = f1.intersect(f2) + self.assertTrue(len(res) == 2) + + def testIntersectionOverlap(self): + self.planarMesh.append( [0.,0.,0.] ) + self.planarMesh.append( [5.,0.,0.] ) + self.planarMesh.append( [8.,5.,0.] ) + self.planarMesh.append( [4.,0.,0.] ) + self.planarMesh.append( [10.,0.,0.] ) + self.planarMesh.append( [9.,5.,0.] ) + planarMeshObject = Mesh.Mesh(self.planarMesh) + f1 = planarMeshObject.Facets[0] + f2 = planarMeshObject.Facets[1] + res = f1.intersect(f2) + self.assertTrue(len(res) == 2) def testSelfIntersection(self): s = b"""solid Simple