def test_init_from_three_points(): """Test the initialization of Plane from end points.""" plane = Plane.from_three_points(Point3D(0, 0, 2), Point3D(0, 2, 2), Point3D(2, 2, 2)) assert plane.o == Point3D(0, 0, 2) assert plane.n == Vector3D(0, 0, -1) assert plane.x == Vector3D(1, 0, 0) assert plane.y == Vector3D(0, -1, 0) assert plane.k == -2 assert round(plane.altitude, 3) == round(-math.pi / 2, 3) assert round(plane.azimuth, 3) == 0 plane = Plane.from_three_points(Point3D(2, 2, 2), Point3D(0, 2, 2), Point3D(0, 0, 2)) assert plane.o == Point3D(2, 2, 2) assert plane.n == Vector3D(0, 0, 1) assert plane.x == Vector3D(1, 0, 0) assert plane.y == Vector3D(0, 1, 0) assert plane.k == 2 assert round(plane.altitude, 3) == round(math.pi / 2, 3) assert round(plane.azimuth, 3) == 0
def test_scale(): """Test the Arc3D scale method.""" pt = Point3D(2, 0, 2) arc = Arc3D(Plane(o=pt), 1, 0, math.pi) origin_1 = Point3D(2, 0, 2) new_arc = arc.scale(2, origin_1) assert new_arc.c == Point3D(2, 0, 2) assert new_arc.radius == 2 assert new_arc.length == 2 * arc.length assert new_arc.a1 == arc.a1 assert new_arc.a2 == arc.a2
def test_check_non_zero(): """Test the check_non_zero method.""" plane_1 = Plane(Vector3D(0, 0, 1)) pts_1 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2)) pts_2 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 0)) aperture_1 = Aperture('Window1', Face3D(pts_1, plane_1)) aperture_2 = Aperture('Window2', Face3D(pts_2, plane_1)) assert aperture_1.check_non_zero(0.0001, False) is True assert aperture_2.check_non_zero(0.0001, False) is False with pytest.raises(Exception): assert aperture_2.check_self_intersecting(0.0001, True)
def test_check_non_zero(): """Test the check_non_zero method.""" plane_1 = Plane(Vector3D(0, 0, 1)) pts_1 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2)) pts_2 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 0)) face_1 = Face('Wall1', Face3D(pts_1, plane_1)) face_2 = Face('Wall2', Face3D(pts_2, plane_1)) assert face_1.check_non_zero(0.0001, False) == '' assert face_2.check_non_zero(0.0001, False) != '' with pytest.raises(Exception): assert face_2.check_non_zero(0.0001, True)
def test_scale(): """Test the Plane scale method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) plane = Plane(vec, pt) origin_1 = Point3D(0, 2, 2) origin_2 = Point3D(1, 1, 2) new_plane = plane.scale(2, origin_1) assert new_plane.o == Point3D(4, 2, 2) assert new_plane.n == Point3D(0, 1, 0) assert new_plane.x == plane.x assert new_plane.y == plane.y assert new_plane.k == 2 new_plane = plane.scale(2, origin_2) assert new_plane.o == Point3D(3, 3, 2) assert new_plane.n == Point3D(0, 1, 0) assert new_plane.x == plane.x assert new_plane.y == plane.y assert new_plane.k == 3
def test_add_remove_apertures(): """Test the adding and removing of multiple apertures to a Face.""" face_face3d = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, 0, 3))) ap_face3d_1 = Face3D.from_rectangle(2, 2, Plane(o=Point3D(2, 2, 3))) ap_face3d_2 = Face3D.from_rectangle(2, 2, Plane(o=Point3D(7, 7, 3))) face = Face('Test_Roof', face_face3d) aperture_1 = Aperture('Test_Skylight_1', ap_face3d_1) aperture_2 = Aperture('Test_Skylight_2', ap_face3d_2) face.add_apertures([aperture_1, aperture_2]) assert len(face.apertures) == 2 assert face.apertures[0].parent is face assert face.apertures[1].parent is face assert len(face.punched_vertices) == 16 assert face.punched_geometry.area == 92 assert face.check_apertures_valid(0.01, 1) == '' face.remove_apertures() assert len(face.apertures) == 0 assert len(face.punched_vertices) == 4 assert face.punched_geometry.area == 100
def test_add_remove_doors(): """Test the adding and removing of multiple doors to a Face.""" face_face3d = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, 0, 3))) ap_face3d_1 = Face3D.from_rectangle(2, 2, Plane(o=Point3D(2, 2, 3))) ap_face3d_2 = Face3D.from_rectangle(2, 2, Plane(o=Point3D(7, 7, 3))) face = Face('Test_Roof', face_face3d) door_1 = Door('Test_Trap_Door_1', ap_face3d_1) door_2 = Door('Test_Trap_Door_2', ap_face3d_2) face.add_doors([door_1, door_2]) assert len(face.doors) == 2 assert face.doors[0].parent is face assert face.doors[1].parent is face assert len(face.punched_vertices) == 16 assert face.punched_geometry.area == 92 assert face.check_doors_valid(0.01, 1) == '' face.remove_doors() assert len(face.doors) == 0 assert len(face.punched_vertices) == 4 assert face.punched_geometry.area == 100
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].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].mesh_grid(1, 1, 1, True) assert len(floor_grid.faces) == 50
def test_check_duplicate_identifiers(): """Test check_duplicate_building_identifiers.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 20, 3), Point3D(0, 30, 3), Point3D(10, 30, 3), Point3D(10, 20, 3)) pts_4 = (Point3D(10, 20, 3), Point3D(10, 30, 3), Point3D(20, 30, 3), Point3D(20, 20, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story_1 = Story('OfficeFloor1', [room2d_1, room2d_2]) story_2 = Story('OfficeFloor2', [room2d_3, room2d_4]) story_1.solve_room_2d_adjacency(0.01) story_1.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story_1.multiplier = 4 story_2.solve_room_2d_adjacency(0.01) story_2.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story_2.multiplier = 2 building_1 = Building('OfficeBuilding', [story_1]) building_2 = Building('OfficeBuilding', [story_2]) tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon(6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy_1 = ContextShade('TreeCanopy', [tree_canopy_geo1]) tree_canopy_2 = ContextShade('TreeCanopy', [tree_canopy_geo2]) model_1 = Model('NewDevelopment1', [building_1], [tree_canopy_1]) model_2 = Model('NewDevelopment2', [building_2], [tree_canopy_2]) assert model_1.check_duplicate_building_identifiers(False) == '' assert model_1.check_duplicate_context_shade_identifiers(False) == '' model_1.add_model(model_2) assert model_1.check_duplicate_building_identifiers(False) != '' with pytest.raises(ValueError): model_1.check_duplicate_building_identifiers(True) assert model_1.check_duplicate_context_shade_identifiers(False) != '' with pytest.raises(ValueError): model_1.check_duplicate_context_shade_identifiers(True)
def test_reflect(): """Test the Plane reflect method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) plane = Plane(vec, pt) origin_1 = Point3D(0, 1, 2) origin_2 = Point3D(1, 1, 2) normal_1 = Vector3D(0, 1, 0) normal_2 = Vector3D(-1, 1, 0).normalize() assert plane.reflect(normal_1, origin_1).o == Point3D(2, 0, 2) assert plane.reflect(normal_1, origin_1).n == Vector3D(0, -1, 0) assert plane.reflect(normal_1, origin_2).o == Point3D(2, 0, 2) assert plane.reflect(normal_1, origin_2).n == Vector3D(0, -1, 0) test_1 = plane.reflect(normal_2, origin_2) assert test_1.o == Point3D(2, 2, 2) assert test_1.n.x == pytest.approx(1, rel=1e-3) assert test_1.n.y == pytest.approx(0, rel=1e-3) assert test_1.n.z == pytest.approx(0, rel=1e-3) test_2 = plane.reflect(normal_2, origin_1) assert test_2.o.x == pytest.approx(1, rel=1e-3) assert test_2.o.y == pytest.approx(3, rel=1e-3) assert test_2.o.z == pytest.approx(2, rel=1e-3) assert test_2.n.x == pytest.approx(1, rel=1e-3) assert test_2.n.y == pytest.approx(0, rel=1e-3) assert test_2.n.z == pytest.approx(0, rel=1e-3)
def test_reflect(): """Test the Room2D reflect 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)) room = Room2D('SquareShoebox', Face3D(pts, plane), 3) origin_1 = Point3D(1, 0, 2) origin_2 = Point3D(0, 0, 2) normal_1 = Vector3D(1, 0, 0) normal_2 = Vector3D(-1, -1, 0).normalize() plane_1 = Plane(normal_1, origin_1) plane_2 = Plane(normal_2, origin_2) plane_3 = Plane(normal_2, origin_1) test_1 = room.duplicate() test_1.reflect(plane_1) assert test_1.floor_geometry[-1].x == pytest.approx(1, rel=1e-3) assert test_1.floor_geometry[-1].y == pytest.approx(1, rel=1e-3) assert test_1.floor_geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.floor_geometry[1].x == pytest.approx(0, rel=1e-3) assert test_1.floor_geometry[1].y == pytest.approx(2, rel=1e-3) assert test_1.floor_geometry[1].z == pytest.approx(2, rel=1e-3) test_1 = room.duplicate() test_1.reflect(plane_2) assert test_1.floor_geometry[-1].x == pytest.approx(-1, rel=1e-3) assert test_1.floor_geometry[-1].y == pytest.approx(-1, rel=1e-3) assert test_1.floor_geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.floor_geometry[1].x == pytest.approx(-2, rel=1e-3) assert test_1.floor_geometry[1].y == pytest.approx(-2, rel=1e-3) assert test_1.floor_geometry[1].z == pytest.approx(2, rel=1e-3) test_2 = room.duplicate() test_2.reflect(plane_3) assert test_2.floor_geometry[-1].x == pytest.approx(0, rel=1e-3) assert test_2.floor_geometry[-1].y == pytest.approx(0, rel=1e-3) assert test_2.floor_geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_2.floor_geometry[1].x == pytest.approx(-1, rel=1e-3) assert test_2.floor_geometry[1].y == pytest.approx(-1, rel=1e-3) assert test_2.floor_geometry[1].z == pytest.approx(2, rel=1e-3)
def test_reflect(): """Test the Aperture reflect 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)) origin_1 = Point3D(1, 0, 2) origin_2 = Point3D(0, 0, 2) normal_1 = Vector3D(1, 0, 0) normal_2 = Vector3D(-1, -1, 0).normalize() plane_1 = Plane(normal_1, origin_1) plane_2 = Plane(normal_2, origin_2) plane_3 = Plane(normal_2, origin_1) test_1 = aperture.duplicate() test_1.reflect(plane_1) assert test_1.geometry[-1].x == pytest.approx(1, rel=1e-3) assert test_1.geometry[-1].y == pytest.approx(1, rel=1e-3) assert test_1.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].x == pytest.approx(0, rel=1e-3) assert test_1.geometry[1].y == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].z == pytest.approx(2, rel=1e-3) test_1 = aperture.duplicate() test_1.reflect(plane_2) assert test_1.geometry[-1].x == pytest.approx(-1, rel=1e-3) assert test_1.geometry[-1].y == pytest.approx(-1, rel=1e-3) assert test_1.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].x == pytest.approx(-2, rel=1e-3) assert test_1.geometry[1].y == pytest.approx(-2, rel=1e-3) assert test_1.geometry[1].z == pytest.approx(2, rel=1e-3) test_2 = aperture.duplicate() test_2.reflect(plane_3) assert test_2.geometry[-1].x == pytest.approx(0, rel=1e-3) assert test_2.geometry[-1].y == pytest.approx(0, rel=1e-3) assert test_2.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_2.geometry[1].x == pytest.approx(-1, rel=1e-3) assert test_2.geometry[1].y == pytest.approx(-1, rel=1e-3) assert test_2.geometry[1].z == pytest.approx(2, rel=1e-3)
def test_reflect(): """Test the Model reflect 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]) origin = Point3D(0, 0, 0) normal = Vector3D(1, 0, 0) model.reflect(Plane(normal, origin)) r_cent = model.rooms[0].center.reflect(normal, origin) 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.reflect( normal, 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) a_cent = model.rooms[0][3].apertures[0].center.reflect(normal, origin) assert room[3].apertures[0].center.x == pytest.approx(a_cent.x, rel=1e-3) assert room[3].apertures[0].center.y == pytest.approx(a_cent.y, rel=1e-3) assert room[3].apertures[0].center.z == pytest.approx(a_cent.z, rel=1e-3) d_cent = model.rooms[0][1].doors[0].center.reflect(normal, origin) assert room[1].doors[0].center.x == pytest.approx(d_cent.x, rel=1e-3) assert room[1].doors[0].center.y == pytest.approx(d_cent.y, rel=1e-3) assert room[1].doors[0].center.z == pytest.approx(d_cent.z, rel=1e-3)
def test_sphere_intersection_with_plane(): """Test the Sphere intersect_plane method.""" ppt = Point3D(-1.5, 0, 1.46) vec = Vector3D(0.1, 0, 1) pl = Plane(vec, ppt) spt = Point3D(0, 0, 0) sp = Sphere(spt, 1.5) int1 = sp.intersect_plane(pl) assert isinstance(int1, Arc3D) ppt = Point3D(0, 0, 0) vec = Vector3D(0, 0, 1) pl = Plane(vec, ppt) int2 = sp.intersect_plane(pl) assert int2.c == ppt assert int2.radius == 1.5 ppt = Point3D(0, 0, 1.5) vec = Vector3D(0, 0, 1) pl = Plane(vec, ppt) int3 = sp.intersect_plane(pl) assert int3 is None
def test_move(): """Test the Arc3D move method.""" pt = Point3D(2, 0, 0) arc = Arc3D(Plane(o=pt), 1, 0, math.pi) vec_1 = Vector3D(2, 2, 2) new_arc = arc.move(vec_1) assert new_arc.c == Point3D(4, 2, 2) assert new_arc.radius == arc.radius assert new_arc.p1 == Point3D(5, 2, 2) assert new_arc.p2 == Point3D(3, 2, 2) assert new_arc.a1 == arc.a1 assert new_arc.a2 == arc.a2
def test_scale(): """Test the ContextShade scale method.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) plane_1 = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 0)) awning_canopy = ContextShade('Awning_Canopy', [Face3D(pts, plane_1)]) new_a = awning_canopy.duplicate() new_a.scale(2) assert new_a[0][0] == Point3D(2, 2, 4) assert new_a[0][1] == Point3D(4, 2, 4) assert new_a[0][2] == Point3D(4, 4, 4) assert new_a[0][3] == Point3D(2, 4, 4) assert new_a.area == awning_canopy.area * 2 ** 2
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_reflect(): v = View('test_view', (1, 0, 2), (2, 0, 0), (0, 0, 3)) v.reflect(Plane(pv.Vector3D(1, 0, 0), pv.Point3D(0, 0, 0))) assert round(v.position[0]) == -1 assert round(v.position[1]) == 0 assert round(v.position[2]) == 2 assert round(v.up_vector[0]) == 0 assert round(v.up_vector[1]) == 0 assert round(v.up_vector[2]) == 3 assert round(v.direction[0]) == -2 assert round(v.direction[1]) == 0 assert round(v.direction[2]) == 0
def test_flip(): """Test the flip method of Face3D.""" pts_1 = (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_1 = Face3D(pts_1, plane_1) face_2 = face_1.flip() assert face_1.normal == face_2.normal.reverse() assert face_1.is_clockwise is False assert face_2.is_clockwise is False for i, pt in enumerate(reversed(face_1.vertices)): assert pt == face_2[i]
def test_bounding_box_angle(): """Test the bounding_box 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_box([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 min_pt.z == pytest.approx(-4, 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) assert max_pt.z == pytest.approx(6, rel=1e-2) x_dom, y_dom, z_dom = bounding_box_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) assert z_dom == pytest.approx(10, rel=1e-2)
def from_dict(cls, data): """Create a color range from a dictionary. Args: data: { "min": -3, "max": 3, "segment_count": 7} """ optional_keys = ('min', 'max', 'segment_count', 'colors', 'continuous_colors', 'continuous_legend', 'title', 'ordinal_dictionary', 'decimal_count', 'include_larger_smaller', 'vertical', 'base_plane', 'segment_height', 'segment_width', 'text_height', 'font') default_keys = ('is_segment_count_default', 'is_title_default', 'is_base_plane_default', 'is_segment_height_default', 'is_segment_width_default', 'is_text_height_default') for key in optional_keys: if key not in data: data[key] = None for key in default_keys: if key not in data: data[key] = False colors = None if data['colors'] is not None: colors = [Color.from_dict(col) for col in data['colors']] base_plane = None if data['base_plane'] is not None: base_plane = Plane.from_dict(data['base_plane']) leg_par = cls(data['min'], data['max'], data['segment_count'], colors, data['title'], base_plane) leg_par.continuous_colors = data['continuous_colors'] leg_par.continuous_legend = data['continuous_legend'] leg_par.ordinal_dictionary = data['ordinal_dictionary'] leg_par.decimal_count = data['decimal_count'] leg_par.include_larger_smaller = data['include_larger_smaller'] leg_par.vertical = data['vertical'] leg_par.segment_height = data['segment_height'] leg_par.segment_width = data['segment_width'] leg_par.text_height = data['text_height'] leg_par.font = data['font'] leg_par._is_segment_count_default = data['is_segment_count_default'] leg_par._is_title_default = data['is_title_default'] leg_par._is_base_plane_default = data['is_base_plane_default'] leg_par._is_segment_height_default = data['is_segment_height_default'] leg_par._is_segment_width_default = data['is_segment_width_default'] leg_par._is_text_height_default = data['is_text_height_default'] return leg_par
def test_to_dict(): """Test the Model to_dict method.""" pts_1 = (Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(10, 10, 3), Point3D(10, 0, 3)) pts_2 = (Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(20, 10, 3), Point3D(20, 0, 3)) pts_3 = (Point3D(0, 10, 3), Point3D(0, 20, 3), Point3D(10, 20, 3), Point3D(10, 10, 3)) pts_4 = (Point3D(10, 10, 3), Point3D(10, 20, 3), Point3D(20, 20, 3), Point3D(20, 10, 3)) room2d_1 = Room2D('Office1', Face3D(pts_1), 3) room2d_2 = Room2D('Office2', Face3D(pts_2), 3) room2d_3 = Room2D('Office3', Face3D(pts_3), 3) room2d_4 = Room2D('Office4', Face3D(pts_4), 3) story = Story('OfficeFloor', [room2d_1, room2d_2, room2d_3, room2d_4]) story.solve_room_2d_adjacency(0.01) story.set_outdoor_window_parameters(SimpleWindowRatio(0.4)) story.multiplier = 4 building = Building('OfficeBuilding', [story]) tree_canopy_geo1 = Face3D.from_regular_polygon(6, 6, Plane(o=Point3D(5, -10, 6))) tree_canopy_geo2 = Face3D.from_regular_polygon(6, 2, Plane(o=Point3D(-5, -10, 3))) tree_canopy = ContextShade('TreeCanopy', [tree_canopy_geo1, tree_canopy_geo2]) model = Model('NewDevelopment', [building], [tree_canopy]) model.tolerance = 0.01 model.angle_tolerance = 1 model_dict = model.to_dict() assert model_dict['type'] == 'Model' assert model_dict['identifier'] == 'NewDevelopment' assert model_dict['display_name'] == 'NewDevelopment' assert 'buildings' in model_dict assert len(model_dict['buildings']) == 1 assert 'context_shades' in model_dict assert len(model_dict['context_shades']) == 1 assert 'tolerance' in model_dict assert model_dict['tolerance'] == 0.01 assert 'angle_tolerance' in model_dict assert model_dict['angle_tolerance'] == 1 assert 'properties' in model_dict assert model_dict['properties']['type'] == 'ModelProperties'
def test_face_add_prefix(): """Test the face add_prefix method.""" face_face3d = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, 0, 3))) ap_face3d = Face3D.from_rectangle(2, 2, Plane(o=Point3D(2, 2, 3))) face = Face('Test_Roof', face_face3d) aperture = Aperture('Test_Skylight', ap_face3d) face.add_aperture(aperture) prefix = 'New' face.add_prefix(prefix) assert face.identifier.startswith(prefix) for ap in face.apertures: assert ap.identifier.startswith(prefix) face_face3d = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, 0, 3))) ap_face3d = Face3D.from_rectangle(2, 2, Plane(o=Point3D(2, 2, 3))) face = Face('Test_Roof', face_face3d) door = Door('Test_Trap_Door', ap_face3d) face.add_door(door) face.add_prefix(prefix) for dr in face.doors: assert dr.identifier.startswith(prefix)
def test_add_remove_sub_faces(): """Test the adding and removing of an aperture and a door to a Face.""" face_face3d = Face3D.from_rectangle(10, 10, Plane(o=Point3D(0, 0, 3))) ap_face3d = Face3D.from_rectangle(2, 2, Plane(o=Point3D(2, 2, 3))) dr_face3d = Face3D.from_rectangle(2, 2, Plane(o=Point3D(7, 7, 3))) face = Face('Test_Roof', face_face3d) aperture = Aperture('Test_Skylight', ap_face3d) door = Door('Test_Trap_Door', dr_face3d) face.add_aperture(aperture) face.add_door(door) assert len(face.apertures) == 1 assert len(face.doors) == 1 assert face.apertures[0].parent is face assert face.doors[0].parent is face assert len(face.punched_vertices) == 16 assert face.punched_geometry.area == 92 assert face.check_sub_faces_valid(0.01, 1) face.remove_sub_faces() assert len(face.apertures) == 0 assert len(face.punched_vertices) == 4 assert face.punched_geometry.area == 100
def test_move(): """Test the ContextShade move method.""" pts_1 = (Point3D(0, 2, 3), Point3D(2, 2, 3), Point3D(2, 0, 3), Point3D(0, 0, 3)) plane_1 = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 0)) awning_canopy = ContextShade('Awning_Canopy', [Face3D(pts_1, plane_1)]) vec_1 = Vector3D(2, 2, 2) new_a = awning_canopy.duplicate() new_a.move(vec_1) assert new_a[0][0] == Point3D(2, 2, 5) assert new_a[0][1] == Point3D(4, 2, 5) assert new_a[0][2] == Point3D(4, 4, 5) assert new_a[0][3] == Point3D(2, 4, 5) assert awning_canopy.area == new_a.area
def test_extract_rectangle_complex(): """Test the Face3D extract_rectangle method with a more complex shape.""" pts_1 = (Point3D(-1, -1, 0), Point3D(-12, -1, 0), Point3D(-12, -1, 2), Point3D(-10, -1, 3), Point3D(-1, -1, 3)) plane = Plane(Vector3D(0, 1, 0)) face_1 = Face3D(pts_1, plane) f1_result = face_1.extract_rectangle(0.0001) assert f1_result[0] == LineSegment3D.from_end_points( Point3D(-1, -1, 0), Point3D(-10, -1, 0)) assert f1_result[1] == LineSegment3D.from_end_points( Point3D(-1, -1, 3), Point3D(-10, -1, 3)) assert len(f1_result[2]) == 1 assert len(f1_result[2][0].vertices) == 4
def test_is_centered_adjacent(): """Test the is_centered_adjacent method.""" plane_1 = Plane(Vector3D(0, 0, 1)) plane_2 = Plane(Vector3D(0, 0, -1)) pts_1 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2), Point3D(0, 2)) pts_2 = (Point3D(0, 0), Point3D(0, 2), Point3D(2, 2), Point3D(2, 0)) pts_3 = (Point3D(0, 0), Point3D(2, 0), Point3D(2.1, 2.1), Point3D(0, 2)) pts_4 = (Point3D(1, 0), Point3D(0, 1), Point3D(1, 2), Point3D(2, 1)) pts_5 = (Point3D(2, 0), Point3D(2, 2), Point3D(0, 2), Point3D(0, 0)) face_1 = Face3D(pts_1, plane_1) face_2 = Face3D(pts_2, plane_1) face_3 = Face3D(pts_1, plane_2) face_4 = Face3D(pts_2, plane_2) face_5 = Face3D(pts_3, plane_1) face_6 = Face3D(pts_4, plane_1) face_7 = Face3D(pts_5, plane_1) assert face_1.is_centered_adjacent(face_2, 0.0001) is True assert face_1.is_centered_adjacent(face_3, 0.0001) is True assert face_1.is_centered_adjacent(face_4, 0.0001) is True assert face_1.is_centered_adjacent(face_5, 0.0001) is False assert face_1.is_centered_adjacent(face_6, 0.0001) is False assert face_1.is_centered_adjacent(face_7, 0.0001) is True
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)
def test_intersect_plane(): """Test the Plane intersect_plane method.""" pt_1 = Point3D(2, 2, 2) vec_1 = Vector3D(0, 2, 0) plane_1 = Plane(vec_1, pt_1) pt_2 = Point3D(0, 0, 0) vec_2 = Vector3D(2, 0, 0) plane_2 = Plane(vec_2, pt_2) pt_3 = Point3D(0, 0, 0) vec_3 = Vector3D(0, 2, 0) plane_3 = Plane(vec_3, pt_3) assert plane_1.intersect_plane(plane_2) == Ray3D( Point3D(0, 2, 0), Vector3D(0, 0, -1)) assert plane_1.intersect_plane(plane_3) is None assert plane_2.intersect_plane(plane_3) == Ray3D( Point3D(0, 0, 0), Vector3D(0, 0, 1))
def test_reflect(): sensor = Sensor((1, 0, 2), (2, 0, 0)) sensors = [ Sensor((0, 0, 0), (0, 0, 1)), Sensor((0, 0, 10), (0, 0, 1)), sensor ] sg = SensorGrid('sg_1', sensors) sg.reflect(Plane(pv.Vector3D(1, 0, 0), pv.Point3D(0, 0, 0))) assert round(sensor.pos[0]) == -1 assert round(sensor.pos[1]) == 0 assert round(sensor.pos[2]) == 2 assert round(sensor.dir[0]) == -2 assert round(sensor.dir[1]) == 0 assert round(sensor.dir[2]) == 0