Skip to content

Commit

Permalink
fix(writer): catch the case when holes touch the edge of the face
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Feb 12, 2024
1 parent 3207ccb commit e97c7b6
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions honeybee_ies/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def _find_index(vertex: Point3D, vertices: List[Point3D], tolerance=0.01):
else:
raise ValueError(f'Failed to find {vertex} in the vertices.')

# remove new lines from the name
room.display_name = ' '.join(room.display_name.split())

unique_vertices = room.geometry.vertices
vertices = _vertices_to_ies(unique_vertices)
face_count = len(room.faces)
Expand All @@ -348,14 +351,26 @@ def _find_index(vertex: Point3D, vertices: List[Point3D], tolerance=0.01):
if isinstance(face.type, (RoofCeiling, Floor)) and face.geometry.has_holes:
# IES doesn't like rooms with holes in them. We need to break the face
# into smaller faces
fgs = face.geometry.split_through_holes()
face_count += len(fgs) - 1
indexes = [
[
_find_index(v, unique_vertices)
for v in fg.lower_left_counter_clockwise_vertices
] for fg in fgs
]
try:
fgs = face.geometry.split_through_holes()
except AssertionError as e:
if 'There must be at least 3 vertices for a Polygon2D' not in str(e):
raise AssertionError(e)
# ignore the hole
print(
f'Failed to resolve the holes for {room.display_name}. Check the '
'input model to ensure the holes are not outside the parent face.'
)
fgs = [face.geometry]
indexes = [[str(v + 1) for v in face_i[0]]]
else:
face_count += len(fgs) - 1
indexes = [
[
_find_index(v, unique_vertices)
for v in fg.lower_left_counter_clockwise_vertices
] for fg in fgs
]
else:
fgs = [face.geometry]
indexes = [[str(v + 1) for v in face_i[0]]]
Expand Down Expand Up @@ -383,10 +398,8 @@ def _find_index(vertex: Point3D, vertices: List[Point3D], tolerance=0.01):
open_str = '\n' + '\n'.join(openings) if len(openings) != 0 else ''
faces.append('%s%d%s' % (face_str, open_count, open_str))

# remove new lines from the name
room_name = ' '.join(room.display_name.split())
space = GEM_TYPES.Space.to_gem(
name=room_name, identifier=room.identifier,
name=room.display_name, identifier=room.identifier,
vertices_count=len(unique_vertices),
face_count=face_count - air_boundary_count,
vertices=vertices, faces='\n'.join(faces)
Expand Down

0 comments on commit e97c7b6

Please sign in to comment.