From c22383ec75d674f9fa7489c1aea2073b3f36ae47 Mon Sep 17 00:00:00 2001 From: Chris Mackey Date: Wed, 19 Jun 2024 13:09:46 -0700 Subject: [PATCH] style(room): Add extra step to remove degenerate geo during intersect --- honeybee/model.py | 2 +- honeybee/room.py | 7 ++++++- tests/model_test.py | 11 ++++++----- tests/room_test.py | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/honeybee/model.py b/honeybee/model.py index 154c7783..bfa8175c 100644 --- a/honeybee/model.py +++ b/honeybee/model.py @@ -1341,7 +1341,7 @@ def reset_ids(self, repair_surface_bcs=True): new_id = clean_and_number_string( dr.display_name, dr_dict, 'Door identifier') dr_map[dr.identifier] = new_id - dr.identifier =new_id + dr.identifier = new_id for shade in self.shades: shade.identifier = clean_and_number_string( shade.display_name, shd_dict, 'Shade identifier') diff --git a/honeybee/room.py b/honeybee/room.py index 3331a45a..4c222c86 100644 --- a/honeybee/room.py +++ b/honeybee/room.py @@ -1644,7 +1644,12 @@ def coplanar_split(self, geometry, tolerance=0.01, angle_tolerance=1): for f_geo in geo_dict[face_1.identifier]: f_split, _ = Face3D.coplanar_split( f_geo, face_2, tolerance, ang_tol) - new_geo.extend(f_split) + for sp_g in f_split: + try: + sp_g = sp_g.remove_colinear_vertices(tolerance) + new_geo.append(sp_g) + except AssertionError: # degenerate geometry to ignore + pass geo_dict[face_1.identifier] = new_geo # use the intersected geometry to remake this room's faces diff --git a/tests/model_test.py b/tests/model_test.py index b6465bff..1cd57de3 100644 --- a/tests/model_test.py +++ b/tests/model_test.py @@ -373,7 +373,7 @@ def test_reset_room_ids(): """Test the reset_room_ids method.""" model_json = './tests/json/model_with_adiabatic.hbjson' parsed_model = Model.from_hbjson(model_json) - + new_model = parsed_model.duplicate() new_model.reset_room_ids() @@ -381,7 +381,7 @@ def test_reset_room_ids(): def test_reset_ids(): - """Test the reset_room_ids method.""" + """Test the reset_ids method.""" model_json = './tests/json/model_with_adiabatic.hbjson' parsed_model = Model.from_hbjson(model_json) @@ -404,7 +404,7 @@ def test_offset_aperture_edges(): new_area = test_face.aperture_area assert new_area < orig_area assert len(test_face.apertures) == 3 - + test_face.offset_aperture_edges(0.6, 0.01) new_area = test_face.aperture_area assert new_area > orig_area @@ -619,7 +619,8 @@ def test_rotate(): assert room.center.x == pytest.approx(r_cent.x, rel=1e-3) assert room.center.y == pytest.approx(r_cent.y, rel=1e-3) assert room.center.z == pytest.approx(r_cent.z, rel=1e-3) - shd_cent = model.rooms[0][3].apertures[0].outdoor_shades[0].center.rotate(axis, math.radians(-90), origin) + shd_cent = model.rooms[0][3].apertures[0].outdoor_shades[0].center.rotate( + axis, math.radians(-90), origin) assert south_face.apertures[0].outdoor_shades[0].center.x == pytest.approx(shd_cent.x, rel=1e-3) assert south_face.apertures[0].outdoor_shades[0].center.y == pytest.approx(shd_cent.y, rel=1e-3) assert south_face.apertures[0].outdoor_shades[0].center.z == pytest.approx(shd_cent.z, rel=1e-3) @@ -832,7 +833,7 @@ def test_check_duplicate_shade_mesh_identifiers(): assert model.check_duplicate_shade_mesh_identifiers(False) == '' pts2 = (Point3D(0, 0, 2), Point3D(0, 2, 2), Point3D(2, 2, 2)) mesh2 = Mesh3D(pts2, [(0, 1, 2)]) - model.add_shade_mesh( ShadeMesh('Awning_1', mesh2)) + model.add_shade_mesh(ShadeMesh('Awning_1', mesh2)) assert model.check_duplicate_shade_mesh_identifiers(False) != '' with pytest.raises(ValueError): model.check_duplicate_shade_mesh_identifiers(True) diff --git a/tests/room_test.py b/tests/room_test.py index db6726de..738a4fc9 100644 --- a/tests/room_test.py +++ b/tests/room_test.py @@ -13,7 +13,6 @@ from honeybee.facetype import face_types - def test_init(): """Test the initialization of a room and basic properties.""" pts_1 = [Point3D(0, 0, 0), Point3D(0, 10, 0), Point3D(10, 10, 0), Point3D(10, 0, 0)] @@ -575,7 +574,7 @@ def test_find_adjacency(): assert len(adj_faces) == 1 assert len(adj_faces[0]) == 2 - adj_info = Room.solve_adjacency([room_south, room_north], 0.01) + Room.solve_adjacency([room_south, room_north], 0.01) # make sure it all still works after the Surface BC is already set adj_faces = Room.find_adjacency([room_south, room_north], 0.01) @@ -684,7 +683,7 @@ def test_group_by_orientation(): room_5 = Room.from_polyface3d('Zone5', pf_5) rooms = [room_1, room_2, room_3, room_4, room_5] - adj_info = Room.solve_adjacency(rooms, 0.01) + Room.solve_adjacency(rooms, 0.01) grouped_rooms, core_rooms, orientations = Room.group_by_orientation(rooms) assert len(grouped_rooms) == 4 @@ -706,6 +705,7 @@ def test_horizontal_boundary(): assert isinstance(hb, Face3D) assert hb.area > 99 + def test_grouped_horizontal_boundary(): """Test the grouped_horizontal_boundary method.""" geo_file = './tests/json/polygons_for_gap_boundary.json'