Skip to content

Commit

Permalink
fix(polyface): Ensuring that from_box preserves base_plane orientation
Browse files Browse the repository at this point in the history
Small fix to ensure that mesh grids that are generated from a box floor are correctly oriented to the box plane.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Jul 23, 2019
1 parent 59ab357 commit cd6d264
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ladybug_geometry/geometry3d/polyface.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ def from_box(cls, width, depth, height, base_plane=None):
polyface = cls(_verts, _face_indices, {'edge_indices': _edge_indices,
'edge_types': [1] * 12})
verts = tuple(tuple(_verts[i] for i in face[0]) for face in _face_indices)
polyface._faces = tuple(Face3D(v, enforce_right_hand=False) for v in verts)
top_plane = base_plane.move(_h_vec)
bottom = (Face3D(verts[0], plane=base_plane, enforce_right_hand=False),)
middle = tuple(Face3D(v, enforce_right_hand=False) for v in verts[1:5])
top = (Face3D(verts[5], plane=top_plane, enforce_right_hand=False),)
polyface._faces = bottom + middle + top
polyface._volume = width * depth * height
return polyface

Expand Down
14 changes: 14 additions & 0 deletions tests/polyface3d_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,20 @@ def test_min_max_center():
assert polyface_2.volume == pytest.approx(4, rel=1e-3)


def test_floor_mesh_grid():
"""Test the generation of a mesh grid from the floor of a box."""
polyface = Polyface3D.from_box(5, 10, 3)
floor_grid = polyface.faces[0].get_mesh_grid(1, 1, 1, True)
assert len(floor_grid.faces) == 50

angle = -1 * math.radians(45)
x_axis = Vector3D(1, 0, 0).rotate_xy(angle)
base_plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 0), x_axis)
polyface = Polyface3D.from_box(5, 10, 3, base_plane)
floor_grid = polyface.faces[0].get_mesh_grid(1, 1, 1, True)
assert len(floor_grid.faces) == 50


def test_duplicate():
"""Test the duplicate method of Face3D."""
polyface = Polyface3D.from_box(2, 4, 2)
Expand Down

0 comments on commit cd6d264

Please sign in to comment.