示例#1
0
def test_shade_duplicate():
    """Test the duplication of shade objects."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0))
    shd_1 = Shade('Test Shade', Face3D(pts))
    shd_2 = shd_1.duplicate()

    assert shd_1 is not shd_2
    for i, pt in enumerate(shd_1.vertices):
        assert pt == shd_2.vertices[i]
    assert shd_1.name == shd_2.name

    shd_2.move(Vector3D(0, 1, 0))
    for i, pt in enumerate(shd_1.vertices):
        assert pt != shd_2.vertices[i]
示例#2
0
def test_move():
    """Test the Room move method."""
    room = Room.from_box('ShoeBoxZone', 2, 2, 2)

    vec_1 = Vector3D(2, 2, 2)
    new_room = room.duplicate()
    new_room.move(vec_1)
    assert new_room.geometry.vertices[0] == Point3D(2, 2, 2)
    assert new_room.geometry.vertices[1] == Point3D(2, 4, 2)
    assert new_room.geometry.vertices[2] == Point3D(4, 4, 2)
    assert new_room.geometry.vertices[3] == Point3D(4, 2, 2)

    assert room.floor_area == new_room.floor_area
    assert room.volume == new_room.volume
示例#3
0
def test_rotate():
    """Test the Ray3D rotate method."""
    pt = Point3D(2, 2, 2)
    vec = Vector3D(0, 2, 0)
    ray = Ray3D(pt, vec)
    origin_1 = Point3D(0, 0, 0)
    axis_1 = Vector3D(1, 0, 0)

    test_1 = ray.rotate(axis_1, math.pi, origin_1)
    assert test_1.p.x == pytest.approx(2, rel=1e-3)
    assert test_1.p.y == pytest.approx(-2, rel=1e-3)
    assert test_1.p.z == pytest.approx(-2, rel=1e-3)
    assert test_1.v.x == pytest.approx(0, rel=1e-3)
    assert test_1.v.y == pytest.approx(-2, rel=1e-3)
    assert test_1.v.z == pytest.approx(0, rel=1e-3)

    test_2 = ray.rotate(axis_1, math.pi / 2, origin_1)
    assert test_2.p.x == pytest.approx(2, rel=1e-3)
    assert test_2.p.y == pytest.approx(-2, rel=1e-3)
    assert test_2.p.z == pytest.approx(2, rel=1e-3)
    assert test_2.v.x == pytest.approx(0, rel=1e-3)
    assert test_2.v.y == pytest.approx(0, rel=1e-3)
    assert test_2.v.z == pytest.approx(2, rel=1e-3)
示例#4
0
def test_equality():
    """Test the equality of Plane objects."""
    pt = Point3D(2, 0, 2)
    vec = Vector3D(0, 2, 0)
    plane = Plane(vec, pt)
    plane_dup = plane.duplicate()
    plane_alt = Plane(vec, Point3D(2, 0.1, 2))

    assert plane is plane
    assert plane is not plane_dup
    assert plane == plane_dup
    assert hash(plane) == hash(plane_dup)
    assert plane != plane_alt
    assert hash(plane) != hash(plane_alt)
示例#5
0
def test_countour_by_distance_between():
    """Test the countour_by_distance_between method."""
    pts_1 = [
        Point3D(0, 0, 0),
        Point3D(0, 0, 2),
        Point3D(2, 0, 2),
        Point3D(2, 0, 0)
    ]
    pts_2 = [
        Point3D(0, 0, 0),
        Point3D(0, 0, 2),
        Point3D(2, 0, 2),
        Point3D(4, 0, 0)
    ]
    plane = Plane(Vector3D(0, 1, 0))
    face_1 = Face3D(pts_1, plane)
    face_2 = Face3D(pts_2, plane)

    contours = face_1.countour_by_distance_between(0.5)
    assert len(contours) == 4
    assert contours[0].p2.z == pytest.approx(2, rel=1e-3)
    assert contours[-1].p2.z == pytest.approx(0.5, rel=1e-3)

    contours = face_1.countour_by_distance_between(0.5, Vector3D(1))
    assert len(contours) == 4
    assert contours[0].p2.x == pytest.approx(2, rel=1e-3)
    assert contours[-1].p2.x == pytest.approx(0.5, rel=1e-3)

    contours = face_1.countour_by_distance_between(0.5, Vector3D(1), True)
    assert len(contours) == 4
    assert contours[-1].p2.x == pytest.approx(1.5, rel=1e-3)
    assert round(contours[0].p2.x) == 0

    contours = face_2.countour_by_distance_between(0.5)
    assert len(contours) == 4
    contours = face_2.countour_by_distance_between(0.5, Vector3D(1))
    assert len(contours) == 8
示例#6
0
def test_rotate():
    """Test the Plane rotate method."""
    pt = Point3D(2, 2, 2)
    vec = Vector3D(0, 2, 0)
    plane = Plane(vec, pt)
    origin_1 = Point3D(0, 0, 0)
    axis_1 = Vector3D(1, 0, 0)

    test_1 = plane.rotate(axis_1, math.pi, origin_1)
    assert test_1.o.x == pytest.approx(2, rel=1e-3)
    assert test_1.o.y == pytest.approx(-2, rel=1e-3)
    assert test_1.o.z == pytest.approx(-2, rel=1e-3)
    assert test_1.n.x == pytest.approx(0, rel=1e-3)
    assert test_1.n.y == pytest.approx(-1, rel=1e-3)
    assert test_1.n.z == pytest.approx(0, rel=1e-3)
    assert test_1.x.x == pytest.approx(1, rel=1e-3)
    assert test_1.x.y == pytest.approx(0, rel=1e-3)
    assert test_1.x.z == pytest.approx(0, rel=1e-3)
    assert test_1.y.x == pytest.approx(0, rel=1e-3)
    assert test_1.y.y == pytest.approx(0, rel=1e-3)
    assert test_1.y.z == pytest.approx(1, rel=1e-3)
    assert test_1.k == pytest.approx(2, rel=1e-3)

    test_2 = plane.rotate(axis_1, math.pi/2, origin_1)
    assert test_2.o.x == pytest.approx(2, rel=1e-3)
    assert test_2.o.y == pytest.approx(-2, rel=1e-3)
    assert test_2.o.z == pytest.approx(2, rel=1e-3)
    assert test_2.n.x == pytest.approx(0, rel=1e-3)
    assert test_2.n.y == pytest.approx(0, rel=1e-3)
    assert test_2.n.z == pytest.approx(1, rel=1e-3)
    assert test_2.x.x == pytest.approx(1, rel=1e-3)
    assert test_2.x.y == pytest.approx(0, rel=1e-3)
    assert test_2.x.z == pytest.approx(0, rel=1e-3)
    assert test_2.y.x == pytest.approx(0, rel=1e-3)
    assert test_2.y.y == pytest.approx(1, rel=1e-3)
    assert test_2.y.z == pytest.approx(0, rel=1e-3)
    assert test_2.k == pytest.approx(2, rel=1e-3)
示例#7
0
def test_to_from_dict_methods():
    """Test the to/from dict methods."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)
    model = Model('Tiny House', [room])
    model.north_angle = 15

    model_dict = model.to_dict()
    new_model = Model.from_dict(model_dict)
    assert model_dict == new_model.to_dict()

    assert new_model.name == 'TinyHouse'
    assert new_model.display_name == 'Tiny House'
    assert new_model.north_angle == 15
    assert len(new_model.rooms) == 1
    assert isinstance(new_model.rooms[0], Room)
    assert len(new_model.faces) == 6
    assert isinstance(new_model.faces[0], Face)
    assert len(new_model.shades) == 2
    assert isinstance(new_model.shades[0], Shade)
    assert len(new_model.apertures) == 2
    assert isinstance(new_model.apertures[0], Aperture)
    assert len(new_model.doors) == 1
    assert isinstance(new_model.doors[0], Door)
    assert len(new_model.orphaned_faces) == 0
    assert len(new_model.orphaned_shades) == 0
    assert len(new_model.orphaned_apertures) == 0
    assert len(new_model.orphaned_doors) == 0
示例#8
0
def test_face_duplicate():
    """Test the duplication of Face objects."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(5, 0,
                                                       3), Point3D(5, 0, 0))
    face_1 = Aperture('Test Face', Face3D(pts))
    face_2 = face_1.duplicate()

    assert face_1 is not face_2
    for i, pt in enumerate(face_1.vertices):
        assert pt == face_2.vertices[i]
    assert face_1.name == face_2.name

    face_2.move(Vector3D(0, 1, 0))
    for i, pt in enumerate(face_1.vertices):
        assert pt != face_2.vertices[i]
示例#9
0
def test_scale():
    """Test the Door scale method."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    door = Door('RectangleDoor', Face3D(pts, plane))

    new_dr = door.duplicate()
    new_dr.scale(2)
    assert new_dr.geometry[0] == Point3D(2, 2, 4)
    assert new_dr.geometry[1] == Point3D(4, 2, 4)
    assert new_dr.geometry[2] == Point3D(4, 4, 4)
    assert new_dr.geometry[3] == Point3D(2, 4, 4)
    assert new_dr.area == door.area * 2 ** 2
    assert new_dr.perimeter == door.perimeter * 2
    assert new_dr.normal == door.normal
示例#10
0
def test_scale():
    """Test the shade scale method."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    shade = Shade('Rectangle Shade', Face3D(pts, plane))

    new_shd = shade.duplicate()
    new_shd.scale(2)
    assert new_shd.geometry[0] == Point3D(2, 2, 4)
    assert new_shd.geometry[1] == Point3D(4, 2, 4)
    assert new_shd.geometry[2] == Point3D(4, 4, 4)
    assert new_shd.geometry[3] == Point3D(2, 4, 4)
    assert new_shd.area == shade.area * 2 ** 2
    assert new_shd.perimeter == shade.perimeter * 2
    assert new_shd.normal == shade.normal
示例#11
0
def test_shade_from_vertices():
    """Test the initialization of shade objects from vertices."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0))
    shade = Shade.from_vertices('Test Shade', pts)

    assert shade.name == 'TestShade'
    assert shade.display_name == 'Test Shade'
    assert isinstance(shade.geometry, Face3D)
    assert len(shade.vertices) == 4
    assert shade.upper_left_vertices[0] == Point3D(1, 0, 3)
    assert shade.normal == Vector3D(0, 1, 0)
    assert shade.center == Point3D(0.5, 0, 1.5)
    assert shade.area == 3
    assert shade.perimeter == 8
    assert not shade.has_parent
示例#12
0
def test_rotate_xy():
    """Test the ContextShade rotate_xy method."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    awning_canopy = ContextShade('Awning_Canopy', [Face3D(pts, plane)])
    origin_1 = Point3D(1, 1, 0)

    test_1 = awning_canopy.duplicate()
    test_1.rotate_xy(180, origin_1)
    assert test_1[0][0].x == pytest.approx(1, rel=1e-3)
    assert test_1[0][0].y == pytest.approx(1, rel=1e-3)
    assert test_1[0][0].z == pytest.approx(2, rel=1e-3)
    assert test_1[0][2].x == pytest.approx(0, rel=1e-3)
    assert test_1[0][2].y == pytest.approx(0, rel=1e-3)
    assert test_1[0][2].z == pytest.approx(2, rel=1e-3)
示例#13
0
def test_door_duplicate():
    """Test the duplication of door objects."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0,
                                                       3), Point3D(1, 0, 0))
    dr_1 = Door('Test Door', Face3D(pts))
    dr_2 = dr_1.duplicate()

    assert dr_1 is not dr_2
    for i, pt in enumerate(dr_1.vertices):
        assert pt == dr_2.vertices[i]
    assert dr_1.name == dr_2.name

    dr_2.move(Vector3D(0, 1, 0))
    for i, pt in enumerate(dr_1.vertices):
        assert pt != dr_2.vertices[i]
def test_aperture_duplicate():
    """Test the duplication of Aperture objects."""
    pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(5, 0,
                                                       3), Point3D(5, 0, 0))
    ap_1 = Aperture('Test Window', Face3D(pts))
    ap_2 = ap_1.duplicate()

    assert ap_1 is not ap_2
    for i, pt in enumerate(ap_1.vertices):
        assert pt == ap_2.vertices[i]
    assert ap_1.name == ap_2.name

    ap_2.move(Vector3D(0, 1, 0))
    for i, pt in enumerate(ap_1.vertices):
        assert pt != ap_2.vertices[i]
示例#15
0
def test_move():
    """Test the Model move method."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)

    new_room = room.duplicate()
    model = Model('Tiny House', [new_room])

    vec_1 = Vector3D(2, 2, 0)
    model.move(vec_1)

    assert room.center == \
        model.rooms[0].center.move(Vector3D(-2, -2, 0))
    assert south_face.apertures[0].indoor_shades[0].center == \
        model.rooms[0][3].apertures[0].indoor_shades[0].center.move(Vector3D(-2, -2, 0))
    assert south_face.apertures[0].outdoor_shades[0].center == \
        model.rooms[0][3].apertures[0].outdoor_shades[0].center.move(Vector3D(-2, -2, 0))
    assert room[3].apertures[0].center == \
        model.rooms[0][3].apertures[0].center.move(Vector3D(-2, -2, 0))
    assert room[1].doors[0].center == \
        model.rooms[0][1].doors[0].center.move(Vector3D(-2, -2, 0))

    assert room.floor_area == model.rooms[0].floor_area
    assert room.volume == model.rooms[0].volume
    assert south_face.apertures[0].indoor_shades[0].area == \
        model.rooms[0][3].apertures[0].indoor_shades[0].area
    assert south_face.apertures[0].outdoor_shades[0].area == \
        model.rooms[0][3].apertures[0].outdoor_shades[0].area
    assert room[3].apertures[0].area == model.rooms[0][3].apertures[0].area
    assert room[1].doors[0].area == model.rooms[0][1].doors[0].area
示例#16
0
def test_scale():
    """Test the Aperture scale method."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    aperture = Aperture('Rectangle Window', Face3D(pts, plane))

    new_ap = aperture.duplicate()
    new_ap.scale(2)
    assert new_ap.geometry[0] == Point3D(2, 2, 4)
    assert new_ap.geometry[1] == Point3D(4, 2, 4)
    assert new_ap.geometry[2] == Point3D(4, 4, 4)
    assert new_ap.geometry[3] == Point3D(2, 4, 4)
    assert new_ap.area == aperture.area * 2 ** 2
    assert new_ap.perimeter == aperture.perimeter * 2
    assert new_ap.normal == aperture.normal
示例#17
0
    def horizontal_radial_vectors(self, vector_count):
        """Get perfectly horizontal Vector3Ds radiating outward in a circle.

        Args:
            vector_count: An integer for the number of vectors to generate in the
                horizontal plane. This can align with any of the dome or sphere
                patches by setting this to 30 * division_count.

        Returns:
            A list of ladybug_geometry horizontal Vector3D radiating outward in
            a circle. All vectors are unit vectors.
        """
        base_vec = Vector3D(0, 1, 0)
        horiz_angle = -2 * math.pi / vector_count
        return tuple(base_vec.rotate_xy(horiz_angle * i) for i in range(vector_count))
示例#18
0
def test_adjacent_zone_model():
    """Test the solve adjacency method with an interior aperture."""
    room_south = Room.from_box('South Zone', 5, 5, 3, origin=Point3D(0, 0, 0))
    room_north = Room.from_box('North Zone', 5, 5, 3, origin=Point3D(0, 5, 0))
    room_south[1].apertures_by_ratio(0.4, 0.01)
    room_north[3].apertures_by_ratio(0.4, 0.01)

    room_south[3].apertures_by_ratio(0.4, 0.01)
    room_south[3].apertures[0].overhang(0.5, indoor=False)
    room_south[3].apertures[0].overhang(0.5, indoor=True)
    room_south[3].apertures[0].move_shades(Vector3D(0, 0, -0.5))
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('Front Door', Face3D(door_verts))
    room_north[1].add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    room_north[1].add_aperture(aperture)
    Room.solve_adjacency([room_south, room_north], 0.01)

    model = Model('Two Room House', [room_south, room_north])

    assert len(model.rooms) == 2
    assert len(model.faces) == 12
    assert len(model.shades) == 2
    assert len(model.apertures) == 4
    assert len(model.doors) == 1

    model_dict = model.to_dict()
    new_model = Model.from_dict(model_dict)

    assert isinstance(new_model.rooms[0][1].apertures[0].boundary_condition,
                      Surface)
    assert isinstance(new_model.rooms[1][3].apertures[0].boundary_condition,
                      Surface)
    assert new_model.rooms[0][1].apertures[0].boundary_condition.boundary_condition_object == \
        new_model.rooms[1][3].apertures[0].name
    assert new_model.rooms[1][3].apertures[0].boundary_condition.boundary_condition_object == \
        new_model.rooms[0][1].apertures[0].name
示例#19
0
def test_to_dict():
    """Test the Model to_dict method."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)
    model = Model('Tiny House', [room])
    model.north_angle = 15

    model_dict = model.to_dict()
    assert model_dict['type'] == 'Model'
    assert model_dict['name'] == 'TinyHouse'
    assert model_dict['display_name'] == 'Tiny House'
    assert 'rooms' in model_dict
    assert len(model_dict['rooms']) == 1
    assert 'faces' in model_dict['rooms'][0]
    assert len(model_dict['rooms'][0]['faces']) == 6
    assert 'apertures' in model_dict['rooms'][0]['faces'][3]
    assert len(model_dict['rooms'][0]['faces'][3]['apertures']) == 1
    assert 'doors' in model_dict['rooms'][0]['faces'][1]
    assert len(model_dict['rooms'][0]['faces'][1]['doors']) == 1
    assert 'outdoor_shades' in model_dict['rooms'][0]['faces'][3]['apertures'][
        0]
    assert len(model_dict['rooms'][0]['faces'][3]['apertures'][0]
               ['outdoor_shades']) == 1
    assert 'north_angle' in model_dict
    assert model_dict['north_angle'] == 15
    assert 'properties' in model_dict
    assert model_dict['properties']['type'] == 'ModelProperties'
示例#20
0
def test_scale():
    """Test the Face scale method."""
    pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2,
                                                       2), Point3D(1, 2, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    face = Face('Rectangle Face', Face3D(pts, plane))

    new_f = face.duplicate()
    new_f.scale(2)
    assert new_f.geometry[0] == Point3D(2, 2, 4)
    assert new_f.geometry[1] == Point3D(4, 2, 4)
    assert new_f.geometry[2] == Point3D(4, 4, 4)
    assert new_f.geometry[3] == Point3D(2, 4, 4)
    assert new_f.area == face.area * 2**2
    assert new_f.perimeter == face.perimeter * 2
    assert new_f.normal == face.normal
示例#21
0
def test_scale():
    """Test the LineSegment3D scale method."""
    pt = Point3D(2, 2, 2)
    vec = Vector3D(0, 2, 0)
    seg = LineSegment3D(pt, vec)

    origin_1 = Point3D(0, 2, 2)
    origin_2 = Point3D(1, 1, 2)
    new_seg = seg.scale(2, origin_1)
    assert new_seg.p == Point3D(4, 2, 2)
    assert new_seg.v == Point3D(0, 4, 0)
    assert new_seg.length == 4

    new_seg = seg.scale(2, origin_2)
    assert new_seg.p == Point3D(3, 3, 2)
    assert new_seg.v == Point3D(0, 4, 0)
示例#22
0
def test_rotate():
    """Test the Arc3D rotate method."""
    pt = Point3D(2, 2, 2)
    arc = Arc3D(Plane(o=pt), 1, 0, math.pi)
    axis_1 = Vector3D(0, 1, 0)
    origin_1 = Point3D(0, 2, 2)

    test_1 = arc.rotate(axis_1, math.pi, origin_1)
    assert test_1.c.x == pytest.approx(-2, rel=1e-3)
    assert test_1.c.z == pytest.approx(2, rel=1e-3)
    assert test_1.radius == arc.radius

    test_2 = arc.rotate(axis_1, math.pi / 2, origin_1)
    assert test_2.c.x == pytest.approx(0, rel=1e-3)
    assert test_2.c.z == pytest.approx(0, rel=1e-3)
    assert test_2.radius == arc.radius
示例#23
0
def test_room2d_segment_orientations():
    """Test the Room2D segment_orientations method."""
    pts = (Point3D(1, 1, 2), Point3D(1, 2, 2), Point3D(2, 2, 2), Point3D(2, 1, 2))
    plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    room2d = Room2D('ZoneCLOSET920980', Face3D(pts, plane), 3)

    assert room2d.segment_normals[0] == Vector2D(1, 0)
    assert room2d.segment_normals[1] == Vector2D(0, 1)
    assert room2d.segment_normals[2] == Vector2D(-1, 0)
    assert room2d.segment_normals[3] == Vector2D(0, -1)

    orientations = room2d.segment_orientations()
    assert orientations[0] == pytest.approx(90, rel=1e-3)
    assert orientations[1] == pytest.approx(0, rel=1e-3)
    assert orientations[2] == pytest.approx(270, rel=1e-3)
    assert orientations[3] == pytest.approx(180, rel=1e-3)
示例#24
0
def test_project_point():
    """Test the Face3D project_point method."""
    pts = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 1), Point3D(1, 1),
           Point3D(1, 2), Point3D(0, 2))
    plane = Plane(Vector3D(0, 0, 1))
    face = Face3D(pts, plane)

    pt_1 = Point3D(0.5, 0.5, 2)
    pt_2 = Point3D(0.5, 0.5, -2)
    pt_3 = Point3D(1.5, 1.5, 2)
    pt_4 = Point3D(-1, -1, 2)

    assert face.project_point(pt_1) == Point3D(0.5, 0.5, 0)
    assert face.project_point(pt_2) == Point3D(0.5, 0.5, 0)
    assert face.project_point(pt_3) is None
    assert face.project_point(pt_4) is None
示例#25
0
def test_scale():
    """Test the Ray3D scale method."""
    pt = Point3D(2, 2, 2)
    vec = Vector3D(0, 2, 0)
    ray = Ray3D(pt, vec)

    origin_1 = Point3D(0, 2, 2)
    origin_2 = Point3D(1, 1, 2)
    new_ray = ray.scale(2, origin_1)
    assert new_ray.p == Point3D(4, 2, 2)
    assert new_ray.v == Point3D(0, 4, 0)
    assert new_ray.v.magnitude == 4

    new_ray = ray.scale(2, origin_2)
    assert new_ray.p == Point3D(3, 3, 2)
    assert new_ray.v == Point3D(0, 4, 0)
示例#26
0
def test_is_point_on_face():
    """Test the is_point_on_face method."""
    bound_pts = [Point3D(0, 0), Point3D(4, 0), Point3D(4, 4), Point3D(0, 4)]
    sub_pt_1 = Point3D(1, 1)
    sub_pt_2 = Point3D(3, 2)
    sub_pt_3 = Point3D(6, 2)
    sub_pt_4 = Point3D(6, 6)
    sub_pt_5 = Point3D(2, 0, 2)
    plane_1 = Plane(Vector3D(0, 0, 1))
    face = Face3D(bound_pts, plane_1)

    assert face.is_point_on_face(sub_pt_1, 0.0001) is True
    assert face.is_point_on_face(sub_pt_2, 0.0001) is True
    assert face.is_point_on_face(sub_pt_3, 0.0001) is False
    assert face.is_point_on_face(sub_pt_4, 0.0001) is False
    assert face.is_point_on_face(sub_pt_5, 0.0001) is False
示例#27
0
def test_duplicate():
    """Test the duplicate method of Face3D."""
    pts = (Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(2, 2,
                                                       2), Point3D(0, 2, 2))
    plane_1 = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2))
    face = Face3D(pts, plane_1)
    new_face = face.duplicate()

    for i, pt in enumerate(new_face):
        assert pt == pts[i]

    assert face.area == new_face.area
    assert face.perimeter == new_face.perimeter
    assert face.is_clockwise == new_face.is_clockwise
    assert face.is_convex == new_face.is_convex
    assert face.is_self_intersecting == new_face.is_self_intersecting
示例#28
0
def overhang(model_json, depth, angle, vertical_offset, per_window, outdoor,
             output_file):
    """Add overhangs to all outdoor walls or windows in walls.

    \b
    Args:
        model_json: Full path to a Model JSON file.
        depth: A number for the overhang depth.
    """
    try:
        # serialize the Model to Python
        with open(model_json) as json_file:
            data = json.load(json_file)
        parsed_model = Model.from_dict(data)
        # check the Model tolerance
        assert parsed_model.tolerance != 0, \
            'Model must have a non-zero tolerance to use overhang.'
        tol = parsed_model.tolerance
        indoor = not outdoor

        # generate the overhangs for all walls of rooms
        overhangs = []
        for room in parsed_model.rooms:
            for face in room.faces:
                if isinstance(face.boundary_condition, Outdoors) and \
                        isinstance(face.type, Wall):
                    if per_window:
                        for ap in face.apertures:
                            overhangs.extend(
                                ap.overhang(depth, angle, indoor, tol))
                    else:
                        overhangs.extend(
                            face.overhang(depth, angle, indoor, tol))

        # move the overhangs if an offset has been specified
        if vertical_offset != 0:
            m_vec = Vector3D(0, 0, vertical_offset)
            for shd in overhangs:
                shd.move(m_vec)

        # write the new model out to the file or stdout
        output_file.write(json.dumps(parsed_model.to_dict()))
    except Exception as e:
        _logger.exception('Model overhang failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
示例#29
0
def test_model_init():
    """Test the initialization of the Model and basic properties."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)

    model = Model('Tiny House', [room])
    str(model)  # test the string representation of the object

    assert model.name == 'TinyHouse'
    assert model.display_name == 'Tiny House'
    assert model.north_angle == 0
    assert model.north_vector == Vector2D(0, 1)
    assert len(model.rooms) == 1
    assert isinstance(model.rooms[0], Room)
    assert len(model.faces) == 6
    assert isinstance(model.faces[0], Face)
    assert len(model.shades) == 2
    assert isinstance(model.shades[0], Shade)
    assert len(model.apertures) == 2
    assert isinstance(model.apertures[0], Aperture)
    assert len(model.doors) == 1
    assert isinstance(model.doors[0], Door)
    assert len(model.orphaned_faces) == 0
    assert len(model.orphaned_shades) == 0
    assert len(model.orphaned_apertures) == 0
    assert len(model.orphaned_doors) == 0
示例#30
0
def test_move():
    """Test the Mesh3D move method."""
    pts = (Point3D(0, 0, 2), Point3D(0, 2, 2), Point3D(2, 2, 2),
           Point3D(2, 0, 2), Point3D(4, 0, 2))
    mesh = Mesh3D(pts, [(0, 1, 2, 3), (2, 3, 4)])

    vec_1 = Vector3D(2, 2, -1)
    new_mesh = mesh.move(vec_1)
    assert new_mesh[0] == Point3D(2, 2, 1)
    assert new_mesh[1] == Point3D(2, 4, 1)
    assert new_mesh[2] == Point3D(4, 4, 1)
    assert new_mesh[3] == Point3D(4, 2, 1)
    assert new_mesh[4] == Point3D(6, 2, 1)

    assert mesh.area == new_mesh.area
    assert len(mesh.vertices) == len(new_mesh.vertices)
    assert len(mesh.faces) == len(new_mesh.faces)