diff --git a/ladybug_geometry/triangulation.py b/ladybug_geometry/triangulation.py index a17698a7..cbdb69d5 100644 --- a/ladybug_geometry/triangulation.py +++ b/ladybug_geometry/triangulation.py @@ -399,7 +399,10 @@ def _find_hole_bridge(hole, outerNode): if hx >= p.x and p.x >= mx and \ _point_in_triangle(hx_or_qx, hy, mx, my, qx_or_hx, hy, p.x, p.y): - tan = abs(hy - p.y) / (hx - p.x) # tangential + try: + tan = abs(hy - p.y) / (hx - p.x) # tangential + except ZeroDivisionError: + break if (tan < tanMin or (tan == tanMin and p.x > m.x)) and \ _locally_inside(p, hole): diff --git a/tests/face3d_test.py b/tests/face3d_test.py index 36ad7472..e0bed1ca 100644 --- a/tests/face3d_test.py +++ b/tests/face3d_test.py @@ -682,6 +682,15 @@ def test_triangulated_mesh_with_many_holes(): pytest.approx(face_geo.area, rel=1e-3) +def test_triangulated_mesh_edge_case(): + """Test triangulation properties of a Face3D triggering a zero division.""" + geo_file = './tests/json/edge_case_face.json' + with open(geo_file, 'r') as fp: + geo_dict = json.load(fp) + face_geo = Face3D.from_dict(geo_dict) + assert face_geo.triangulated_mesh3d.area != 0 + + def test_check_planar(): """Test the check_planar method of Face3D.""" pts_1 = (Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(2, 2, 2), Point3D(0, 2, 2)) diff --git a/tests/json/edge_case_face.json b/tests/json/edge_case_face.json new file mode 100644 index 00000000..35501298 --- /dev/null +++ b/tests/json/edge_case_face.json @@ -0,0 +1,221 @@ +{ + "type": "Face3D", + "plane": { + "o": [ + 179.65605217097971, + 200.10259867296926, + 665.5 + ], + "n": [ + 0.0, + 1.0, + 0.0 + ], + "type": "Plane", + "x": [ + 1.0, + -0.0, + 0.0 + ] + }, + "boundary": [ + [ + 179.65605217097971, + 200.10259867296926, + 665.5 + ], + [ + 179.65605217097971, + 200.10259867296926, + 661.5 + ], + [ + 168.42990273305756, + 200.10259867296926, + 661.5 + ], + [ + 168.42990273305756, + 200.10259867296926, + 665.5 + ] + ], + "holes": [ + [ + [ + 178.17605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 178.17605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 176.7860521709797, + 200.10259867296926, + 662.09999999999991 + ], + [ + 176.78605217097967, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 175.92605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 175.92605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 174.5360521709797, + 200.10259867296926, + 662.09999999999991 + ], + [ + 174.53605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 173.67605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 173.67605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 172.28605217097967, + 200.10259867296926, + 662.09999999999991 + ], + [ + 172.28605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 171.42605217097966, + 200.10259867296926, + 664.09999999999991 + ], + [ + 171.42605217097966, + 200.10259867296926, + 662.09999999999991 + ], + [ + 170.03605217097967, + 200.10259867296926, + 662.09999999999991 + ], + [ + 170.03605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 171.42605217097966, + 200.10259867296926, + 664.09999999999991 + ], + [ + 171.42605217097966, + 200.10259867296926, + 662.09999999999991 + ], + [ + 170.03605217097967, + 200.10259867296926, + 662.09999999999991 + ], + [ + 170.03605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 173.67605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 173.67605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 172.28605217097967, + 200.10259867296926, + 662.09999999999991 + ], + [ + 172.28605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 175.92605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 175.92605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 174.5360521709797, + 200.10259867296926, + 662.09999999999991 + ], + [ + 174.53605217097964, + 200.10259867296926, + 664.09999999999991 + ] + ], + [ + [ + 178.17605217097969, + 200.10259867296926, + 664.09999999999991 + ], + [ + 178.17605217097969, + 200.10259867296926, + 662.09999999999991 + ], + [ + 176.7860521709797, + 200.10259867296926, + 662.09999999999991 + ], + [ + 176.78605217097967, + 200.10259867296926, + 664.09999999999991 + ] + ] + ] +}