Mesh: [skip ci] add unit tests for coplanar and intersecting triangles

This commit is contained in:
wmayer
2021-10-19 20:31:39 +02:00
parent fe070903d3
commit 5c59b8e050
2 changed files with 29 additions and 3 deletions

View File

@@ -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];
}

View File

@@ -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