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_overlapping_bounding_boxes(): """Test the Polyface3D overlapping_bounding_boxes method.""" polyface_1 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 2))) polyface_2 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 1))) polyface_3 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(2, 1, 2))) polyface_4 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 2, 2))) polyface_5 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(0, 0, 0))) assert Polyface3D.overlapping_bounding_boxes(polyface_1, polyface_2, 0.01) assert Polyface3D.overlapping_bounding_boxes(polyface_1, polyface_3, 0.01) assert Polyface3D.overlapping_bounding_boxes(polyface_1, polyface_4, 0.01) assert not Polyface3D.overlapping_bounding_boxes(polyface_1, polyface_5, 0.01)
def test_min_max_center(): """Test the Face3D min, max and center.""" polyface_1 = Polyface3D.from_box(2, 4, 2) polyface_2 = Polyface3D.from_box(math.sqrt(2), math.sqrt(2), 2, Plane( Vector3D(0, 0, 1), Point3D(1, 0, 0), Vector3D(1, 1, 0))) assert polyface_1.min == Point3D(0, 0, 0) assert polyface_1.max == Point3D(2, 4, 2) assert polyface_1.center == Point3D(1, 2, 1) assert polyface_1.volume == pytest.approx(16, rel=1e-3) assert polyface_2.min == Point3D(0, 0, 0) assert polyface_2.max == Point3D(2, 2, 2) assert polyface_2.center == Point3D(1, 1, 1) assert polyface_2.volume == pytest.approx(4, rel=1e-3)
def test_reflect(): """Test the Polyface3D reflect method.""" polyface = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 2))) origin_1 = Point3D(1, 0, 2) normal_1 = Vector3D(1, 0, 0) normal_2 = Vector3D(-1, -1, 0).normalize() test_1 = polyface.reflect(normal_1, origin_1) assert test_1[0].x == pytest.approx(1, rel=1e-3) assert test_1[0].y == pytest.approx(1, rel=1e-3) assert test_1[0].z == pytest.approx(2, rel=1e-3) assert test_1[2].x == pytest.approx(0, rel=1e-3) assert test_1[2].y == pytest.approx(2, rel=1e-3) assert test_1[2].z == pytest.approx(2, rel=1e-3) test_1 = polyface.reflect(normal_2, Point3D(0, 0, 2)) assert test_1[0].x == pytest.approx(-1, rel=1e-3) assert test_1[0].y == pytest.approx(-1, rel=1e-3) assert test_1[0].z == pytest.approx(2, rel=1e-3) assert test_1[2].x == pytest.approx(-2, rel=1e-3) assert test_1[2].y == pytest.approx(-2, rel=1e-3) assert test_1[2].z == pytest.approx(2, rel=1e-3) test_2 = polyface.reflect(normal_2, origin_1) assert test_2[0].x == pytest.approx(0, rel=1e-3) assert test_2[0].y == pytest.approx(0, rel=1e-3) assert test_2[0].z == pytest.approx(2, rel=1e-3) assert test_2[2].x == pytest.approx(-1, rel=1e-3) assert test_2[2].y == pytest.approx(-1, rel=1e-3) assert test_2[2].z == pytest.approx(2, rel=1e-3)
def test_rotate(): """Test the Polyface3D rotate method.""" polyface = Polyface3D.from_box(2, 2, 2, Plane(o=Point3D(0, 0, 2))) origin = Point3D(0, 0, 0) axis = Vector3D(1, 0, 0) test_1 = polyface.rotate(axis, math.pi, origin) assert test_1[0].x == pytest.approx(0, rel=1e-3) assert test_1[0].y == pytest.approx(0, rel=1e-3) assert test_1[0].z == pytest.approx(-2, rel=1e-3) assert test_1[2].x == pytest.approx(2, rel=1e-3) assert test_1[2].y == pytest.approx(-2, rel=1e-3) assert test_1[2].z == pytest.approx(-2, rel=1e-3) assert polyface.area == test_1.area assert polyface.volume == test_1.volume assert len(polyface.vertices) == len(test_1.vertices) test_2 = polyface.rotate(axis, math.pi / 2, origin) assert test_2[0].x == pytest.approx(0, rel=1e-3) assert test_2[0].y == pytest.approx(-2, rel=1e-3) assert test_2[0].z == pytest.approx(0, rel=1e-3) assert test_2[2].x == pytest.approx(2, rel=1e-3) assert test_2[2].y == pytest.approx(-2, rel=1e-3) assert test_2[2].z == pytest.approx(2, rel=1e-3) assert polyface.area == test_2.area assert polyface.volume == test_1.volume assert len(polyface.vertices) == len(test_2.vertices)
def test_bounding_rectangle(): """Test the bounding_rectangle methods with arrays of 3D objects.""" plane1 = Plane(o=Point3D(-5, 0, 0)) plane2 = Plane(o=Point3D(0, -4, 4)) plane3 = Plane(o=Point3D(2, 2, -4)) polyface1 = Polyface3D.from_box(2, 4, 2, plane1) polyface2 = Polyface3D.from_box(2, 4, 2, plane2) polyface3 = Polyface3D.from_box(2, 4, 2, plane3) min_pt, max_pt = bounding_rectangle([polyface1, polyface2, polyface3]) assert min_pt == Point2D(-5, -4) assert max_pt == Point2D(4, 6) x_dom, y_dom = bounding_rectangle_extents( [polyface1, polyface2, polyface3]) assert x_dom == 9 assert y_dom == 10
def test_bounding_rectangle_angle(): """Test the bounding_rectangle methods with an axis_angle.""" plane1 = Plane(o=Point3D(-5, 0, 0)) plane2 = Plane(o=Point3D(0, -4, 4)) plane3 = Plane(o=Point3D(2, 2, -4)) polyface1 = Polyface3D.from_box(2, 4, 2, plane1) polyface2 = Polyface3D.from_box(2, 4, 2, plane2) polyface3 = Polyface3D.from_box(2, 4, 2, plane3) min_pt, max_pt = bounding_rectangle([polyface1, polyface2, polyface3], 45) assert min_pt.x == pytest.approx(1.45, rel=1e-2) assert min_pt.y == pytest.approx(-4.89, rel=1e-2) assert max_pt.x == pytest.approx(-1.62, rel=1e-2) assert max_pt.y == pytest.approx(9.47, rel=1e-2) x_dom, y_dom = bounding_rectangle_extents( [polyface1, polyface2, polyface3], 45) assert x_dom == pytest.approx(10.6103, rel=1e-2) assert y_dom == pytest.approx(10.1589, rel=1e-2)
def test_scale_world_origin(): """Test the Polyface3D scale method with None origin.""" polyface = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 2))) new_polyface = polyface.scale(2) assert new_polyface[0] == Point3D(2, 2, 4) assert new_polyface[1] == Point3D(2, 4, 4) assert new_polyface[2] == Point3D(4, 4, 4) assert new_polyface[3] == Point3D(4, 2, 4) assert new_polyface.area == polyface.area * 2**2 assert new_polyface.volume == polyface.volume * 2**3
def test_duplicate(): """Test the duplicate method of Face3D.""" polyface = Polyface3D.from_box(2, 4, 2) new_polyface = polyface.duplicate() for i, pt in enumerate(polyface): assert pt == new_polyface[i] for i, fi in enumerate(polyface.face_indices): assert fi == new_polyface.face_indices[i] assert polyface.area == new_polyface.area assert polyface.is_solid == new_polyface.is_solid
def test_scale(): """Test the Polyface3D scale method.""" polyface_1 = Polyface3D.from_box(2, 2, 2, Plane(o=Point3D(0, 0, 2))) polyface_2 = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 0))) origin_1 = Point3D(2, 0) origin_2 = Point3D(1, 1) new_polyface_1 = polyface_1.scale(2, origin_1) assert new_polyface_1[0] == Point3D(-2, 0, 4) assert new_polyface_1[1] == Point3D(-2, 4, 4) assert new_polyface_1[2] == Point3D(2, 4, 4) assert new_polyface_1[3] == Point3D(2, 0, 4) assert new_polyface_1.area == polyface_1.area * 2**2 assert new_polyface_1.volume == polyface_1.volume * 2**3 new_polyface_2 = polyface_2.scale(2, origin_2) assert new_polyface_2[0] == Point3D(1, 1) assert new_polyface_2[1] == Point3D(1, 3) assert new_polyface_2[2] == Point3D(3, 3) assert new_polyface_2[3] == Point3D(3, 1) assert new_polyface_2.area == polyface_2.area * 2**2 assert new_polyface_2.volume == polyface_2.volume * 2**3
def test_move(): """Test the Polyface3D move method.""" polyface = Polyface3D.from_box(2, 2, 2) vec_1 = Vector3D(2, 2, 2) new_polyface = polyface.move(vec_1) assert new_polyface[0] == Point3D(2, 2, 2) assert new_polyface[1] == Point3D(2, 4, 2) assert new_polyface[2] == Point3D(4, 4, 2) assert new_polyface[3] == Point3D(4, 2, 2) assert polyface.area == new_polyface.area assert polyface.volume == new_polyface.volume
def test_polyface3d_init_from_box(): """Test the initalization of Poyface3D from_box.""" polyface = Polyface3D.from_box(2, 4, 2) assert len(polyface.vertices) == 8 assert len(polyface.face_indices) == 6 assert len(polyface.faces) == 6 assert len(polyface.edge_indices) == 12 assert len(polyface.edges) == 12 assert len(polyface.naked_edges) == 0 assert len(polyface.non_manifold_edges) == 0 assert len(polyface.internal_edges) == 12 assert polyface.area == 40 assert polyface.volume == 16 assert polyface.is_solid
def from_box(cls, identifier, width=3.0, depth=6.0, height=3.2, orientation_angle=0, origin=Point3D(0, 0, 0)): """Initialize a Room from parameters describing a box. The resulting faces of the room will always be ordered as follows: (Bottom, Front, Right, Back, Left, Top) where the front is facing the cardinal direction of the orientation_angle. Args: identifier: Text string for a unique Room ID. Must be < 100 characters and not contain any spaces or special characters. width: Number for the width of the box (in the X direction). Default: 3.0. depth: Number for the depth of the box (in the Y direction). Default: 6.0. height: Number for the height of the box (in the Z direction). Default: 3.2. orientation_angle: A number between 0 and 360 for the clockwise orientation of the box in degrees. (0 = North, 90 = East, 180 = South, 270 = West) origin: A ladybug_geometry Point3D for the origin of the room. """ # create a box Polyface3D x_axis = Vector3D(1, 0, 0) if orientation_angle != 0: angle = -1 * math.radians( float_in_range(orientation_angle, 0, 360, 'orientation_angle')) x_axis = x_axis.rotate_xy(angle) base_plane = Plane(Vector3D(0, 0, 1), origin, x_axis) polyface = Polyface3D.from_box(width, depth, height, base_plane) # create the honeybee Faces directions = ('Bottom', 'Front', 'Right', 'Back', 'Left', 'Top') faces = [] for face, dir in zip(polyface.faces, directions): faces.append( Face('{}_{}'.format(identifier, dir), face, get_type_from_normal(face.normal), get_bc_from_position(face.boundary))) room = cls(identifier, faces) room._geometry = polyface return room
def test_rotate_xy(): """Test the Polyface3D rotate_xy method.""" polyface = Polyface3D.from_box(1, 1, 1, Plane(o=Point3D(1, 1, 2))) origin_1 = Point3D(1, 1, 0) test_1 = polyface.rotate_xy(math.pi, origin_1) assert test_1[0].x == pytest.approx(1, rel=1e-3) assert test_1[0].y == pytest.approx(1, rel=1e-3) assert test_1[0].z == pytest.approx(2, rel=1e-3) assert test_1[2].x == pytest.approx(0, rel=1e-3) assert test_1[2].y == pytest.approx(0, rel=1e-3) assert test_1[2].z == pytest.approx(2, rel=1e-3) test_2 = polyface.rotate_xy(math.pi / 2, origin_1) assert test_2[0].x == pytest.approx(1, rel=1e-3) assert test_2[0].y == pytest.approx(1, rel=1e-3) assert test_1[0].z == pytest.approx(2, rel=1e-3) assert test_2[2].x == pytest.approx(0, rel=1e-3) assert test_2[2].y == pytest.approx(2, rel=1e-3) assert test_1[2].z == pytest.approx(2, rel=1e-3)
def test_polyface3d_to_from_dict(): """Test the to/from dict of Polyface3D objects.""" polyface = Polyface3D.from_box(2, 4, 2) polyface_dict = polyface.to_dict() new_polyface = Polyface3D.from_dict(polyface_dict) assert isinstance(new_polyface, Polyface3D) assert new_polyface.to_dict() == polyface_dict assert len(new_polyface.vertices) == 8 assert len(new_polyface.face_indices) == 6 assert len(new_polyface.faces) == 6 assert len(new_polyface.edge_indices) == 12 assert len(new_polyface.edges) == 12 assert len(new_polyface.naked_edges) == 0 assert len(new_polyface.non_manifold_edges) == 0 assert len(new_polyface.internal_edges) == 12 assert new_polyface.area == 40 assert new_polyface.volume == 16 assert new_polyface.is_solid