Skip to content

Commit

Permalink
fix(building): Ensure duplicate room vertices don't create exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Oct 4, 2024
1 parent cb883fe commit 60f4e12
Show file tree
Hide file tree
Showing 4 changed files with 30,265 additions and 7 deletions.
21 changes: 16 additions & 5 deletions dragonfly/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,21 @@ def add_roof_geometry(self, roof_geometry, tolerance=0.01, overlap_threshold=0):
incorrect roof assignment in cases where roofs extend slightly
past the room they are intended for. (Default: 0.05).
"""
# first check to be sure that roof_geometry has been supplied
# convert all roof geometries to clean 2D polygons
roof_polygons, clean_roofs = [], []
for r_geo in roof_geometry:
try:
clean_geo = r_geo.remove_colinear_vertices(tolerance)
except AssertionError: # degenerate roof geometry to ignore
continue
clean_poly = Polygon2D(tuple(Point2D(pt.x, pt.y) for pt in r_geo.boundary))
clean_roofs.append(clean_geo)
roof_polygons.append(clean_poly)
roof_geometry = clean_roofs
if len(roof_geometry) == 0:
return

# convert all rooms and roof geometries to 2D polygons to evaluate overlaps
roof_polygons = tuple(
Polygon2D(tuple(Point2D(pt.x, pt.y) for pt in geo.boundary))
for geo in roof_geometry)
# prepare the stories for checking the roofs
rev_stories = list(reversed(self.unique_stories))
story_polygons, story_heights, room_heights = [], [], []
for story in rev_stories:
Expand All @@ -1017,6 +1024,10 @@ def add_roof_geometry(self, roof_geometry, tolerance=0.01, overlap_threshold=0):
for rm_poly, rm_ht in zip(story_poly, rm_hts):
poly_rel = rf_poly.polygon_relationship(rm_poly, tolerance)
if poly_rel >= 0:
try:
rm_poly = rm_poly.remove_colinear_vertices(tolerance)
except AssertionError: # degenerate room to ignore
continue
overlap_polys = rf_poly.boolean_intersect(rm_poly, tolerance) \
if poly_rel == 0 else [rm_poly]
if sum(ply.area for ply in overlap_polys) < rm_poly.area * ot:
Expand Down
Loading

0 comments on commit 60f4e12

Please sign in to comment.