Skip to content

Commit cd6d264

Browse files
chriswmackeyChris Mackey
authored and
Chris Mackey
committed
fix(polyface): Ensuring that from_box preserves base_plane orientation
Small fix to ensure that mesh grids that are generated from a box floor are correctly oriented to the box plane.
1 parent 59ab357 commit cd6d264

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: ladybug_geometry/geometry3d/polyface.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ def from_box(cls, width, depth, height, base_plane=None):
202202
polyface = cls(_verts, _face_indices, {'edge_indices': _edge_indices,
203203
'edge_types': [1] * 12})
204204
verts = tuple(tuple(_verts[i] for i in face[0]) for face in _face_indices)
205-
polyface._faces = tuple(Face3D(v, enforce_right_hand=False) for v in verts)
205+
top_plane = base_plane.move(_h_vec)
206+
bottom = (Face3D(verts[0], plane=base_plane, enforce_right_hand=False),)
207+
middle = tuple(Face3D(v, enforce_right_hand=False) for v in verts[1:5])
208+
top = (Face3D(verts[5], plane=top_plane, enforce_right_hand=False),)
209+
polyface._faces = bottom + middle + top
206210
polyface._volume = width * depth * height
207211
return polyface
208212

Diff for: tests/polyface3d_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,20 @@ def test_min_max_center():
478478
assert polyface_2.volume == pytest.approx(4, rel=1e-3)
479479

480480

481+
def test_floor_mesh_grid():
482+
"""Test the generation of a mesh grid from the floor of a box."""
483+
polyface = Polyface3D.from_box(5, 10, 3)
484+
floor_grid = polyface.faces[0].get_mesh_grid(1, 1, 1, True)
485+
assert len(floor_grid.faces) == 50
486+
487+
angle = -1 * math.radians(45)
488+
x_axis = Vector3D(1, 0, 0).rotate_xy(angle)
489+
base_plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 0), x_axis)
490+
polyface = Polyface3D.from_box(5, 10, 3, base_plane)
491+
floor_grid = polyface.faces[0].get_mesh_grid(1, 1, 1, True)
492+
assert len(floor_grid.faces) == 50
493+
494+
481495
def test_duplicate():
482496
"""Test the duplicate method of Face3D."""
483497
polyface = Polyface3D.from_box(2, 4, 2)

0 commit comments

Comments
 (0)