Skip to content

Commit

Permalink
Merge 6ac75b0 into fb92956
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Sep 3, 2021
2 parents fb92956 + 6ac75b0 commit 840695f
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ladybug_geometry/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions tests/face3d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
221 changes: 221 additions & 0 deletions tests/json/edge_case_face.json
Original file line number Diff line number Diff line change
@@ -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
]
]
]
}

0 comments on commit 840695f

Please sign in to comment.