def test_arc3_split_with_plane(): """Test the Arc3D split_with_plane method.""" pt = Point3D(2, 0, 2) arc = Arc3D(Plane(o=pt), 1, 0, math.pi) circle = Arc3D(Plane(o=pt), 1) plane_1 = Plane(Vector3D(0, 1, 0), Point3D(0, 0, 0)) int1 = circle.split_with_plane(plane_1) assert len(int1) == 2 assert int1[0].p1 == Point3D(3, 0, 2) assert int1[0].p2.x == pytest.approx(1, rel=1e-2) assert int1[0].p2.y == pytest.approx(0, rel=1e-2) assert int1[1].p2 == Point3D(3, 0, 2) assert int1[1].p1.x == pytest.approx(1, rel=1e-2) assert int1[1].p1.y == pytest.approx(0, rel=1e-2) plane_2 = Plane(Vector3D(0, 1, 0), Point3D(0, 0.5, 0)) int2 = arc.split_with_plane(plane_2) assert len(int2) == 3
def test_check_self_intersecting(): """Test the check_self_intersecting 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, 0), Point3D(2, 2)) aperture_1 = Aperture('Window1', Face3D(pts_1, plane_1)) aperture_2 = Aperture('Window2', Face3D(pts_2, plane_1)) aperture_3 = Aperture('Window3', Face3D(pts_1, plane_2)) aperture_4 = Aperture('Window4', Face3D(pts_2, plane_2)) assert aperture_1.check_self_intersecting(False) is True assert aperture_2.check_self_intersecting(False) is False with pytest.raises(Exception): assert aperture_2.check_self_intersecting(True) assert aperture_3.check_self_intersecting(False) is True assert aperture_4.check_self_intersecting(False) is False with pytest.raises(Exception): assert aperture_4.check_self_intersecting(True)
def test_closest_point(): """Test the Plane closest_point method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) plane = Plane(vec, pt) test_pt = Point3D(0, 4, 0) assert plane.closest_point(test_pt) == Point3D(0, 2, 0) test_pt = Point3D(4, 4, 4) assert plane.closest_point(test_pt) == Point3D(4, 2, 4)
def test_scale_world_origin(): """Test the Ray3D scale method with None origin.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) ray = Ray3D(pt, vec) new_ray = ray.scale(2) assert new_ray.p == Point3D(4, 4, 4) assert new_ray.v == Point3D(0, 4) assert new_ray.v.magnitude == 4
def test_cone_scale(): """Test the Cone scale method.""" c = Cone(Point3D(4, 0.5, 2), Vector3D(1, 0, 2.5), 0.7) test = c.scale(2, Point3D(0, 0, 0)) assert test.vertex.x == pytest.approx(8, rel=1e-3) assert test.vertex.y == pytest.approx(1, rel=1e-3) assert test.vertex.z == pytest.approx(4, rel=1e-3) assert test.axis.x == pytest.approx(2, rel=1e-3) assert test.axis.y == pytest.approx(0, rel=1e-3) assert test.axis.z == pytest.approx(5, rel=1e-3)
def test_scale_world_origin(): """Test the LineSegment3D scale method with None origin.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) seg = LineSegment3D(pt, vec) new_seg = seg.scale(2) assert new_seg.p == Point3D(4, 4, 4) assert new_seg.v == Point3D(0, 4) assert new_seg.length == 4
def test_check_self_intersecting(): """Test the check_self_intersecting 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, 0), Point3D(2, 2)) shade_1 = Shade('shade1', Face3D(pts_1, plane_1)) shade_2 = Shade('shade2', Face3D(pts_2, plane_1)) shade_3 = Shade('shade3', Face3D(pts_1, plane_2)) shade_4 = Shade('shade4', Face3D(pts_2, plane_2)) assert shade_1.check_self_intersecting(False) == '' assert shade_2.check_self_intersecting(False) != '' with pytest.raises(Exception): assert shade_2.check_self_intersecting(True) assert shade_3.check_self_intersecting(False) == '' assert shade_4.check_self_intersecting(False) != '' with pytest.raises(Exception): assert shade_4.check_self_intersecting(True)
def test_check_self_intersecting(): """Test the check_self_intersecting 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, 0), Point3D(2, 2)) door_1 = Door('Door1', Face3D(pts_1, plane_1)) door_2 = Door('Door2', Face3D(pts_2, plane_1)) door_3 = Door('Door3', Face3D(pts_1, plane_2)) door_4 = Door('Door4', Face3D(pts_2, plane_2)) assert door_1.check_self_intersecting(False) == '' assert door_2.check_self_intersecting(False) != '' with pytest.raises(Exception): assert door_2.check_self_intersecting(True) assert door_3.check_self_intersecting(False) == '' assert door_4.check_self_intersecting(False) != '' with pytest.raises(Exception): assert door_4.check_self_intersecting(True)
def test_linerayment2_mutability(): """Test the immutability of Ray3D objects.""" pt = Point3D(2, 0, 0) vec = Vector3D(0, 2, 0) ray = Ray3D(pt, vec) assert isinstance(ray, Ray3D) with pytest.raises(AttributeError): ray.p.x = 3 with pytest.raises(AttributeError): ray.v.x = 3 with pytest.raises(AttributeError): ray.p = Point3D(0, 0, 0) with pytest.raises(AttributeError): ray.v = Vector3D(2, 2, 0) ray_copy = ray.duplicate() assert ray.p == ray_copy.p assert ray.v == ray_copy.v
def test_linesegment3d_immutability(): """Test the immutability of LineSegment3D objects.""" pt = Point3D(2, 0, 0) vec = Vector3D(0, 2, 0) seg = LineSegment3D(pt, vec) assert isinstance(seg, LineSegment3D) with pytest.raises(AttributeError): seg.p.x = 3 with pytest.raises(AttributeError): seg.v.x = 3 with pytest.raises(AttributeError): seg.p = Point3D(0, 0, 0) with pytest.raises(AttributeError): seg.v = Vector3D(2, 2, 0) seg_copy = seg.duplicate() assert seg.p == seg_copy.p assert seg.v == seg_copy.v
def from_box(cls, name, 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: name: Room name. Must be < 100 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(name, dir), face, get_type_from_normal(face.normal), get_bc_from_position(face.boundary))) room = cls(name, faces) room._geometry = polyface return room
def test_linesegment3d_init(): """Test the initalization of LineSegment3D objects and basic properties.""" pt = Point3D(2, 0, 2) vec = Vector3D(0, 2, 0) seg = LineSegment3D(pt, vec) str(seg) # test the string representation of the line segment assert seg.p == Point3D(2, 0, 2) assert seg.v == Vector3D(0, 2, 0) assert seg.p1 == Point3D(2, 0, 2) assert seg.p2 == Point3D(2, 2, 2) assert seg.midpoint == Point3D(2, 1, 2) assert seg.point_at(0.25) == Point3D(2, 0.5, 2) assert seg.point_at_length(1) == Point3D(2, 1, 2) assert seg.length == 2 flip_seg = seg.flip() assert flip_seg.p == Point3D(2, 2, 2) assert flip_seg.v == Vector3D(0, -2, 0)
def test_check_self_intersecting(): """Test the check_self_intersecting 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, 0), Point3D(2, 2)) face_1 = Face('Wall1', Face3D(pts_1, plane_1)) face_2 = Face('Wall2', Face3D(pts_2, plane_1)) face_3 = Face('Wall3', Face3D(pts_1, plane_2)) face_4 = Face('Wall4', Face3D(pts_2, plane_2)) assert face_1.check_self_intersecting(False) is True assert face_2.check_self_intersecting(False) is False with pytest.raises(Exception): assert face_2.check_self_intersecting(True) assert face_3.check_self_intersecting(False) is True assert face_4.check_self_intersecting(False) is False with pytest.raises(Exception): assert face_4.check_self_intersecting(True)
def draw_psych_chart(psy_chart): """Draw a given psychrometric chart object into Rhino geometry. This will NOT translate any colored meshes or data points. """ # output all of the lines/polylines for the various axes title_i = [from_polyline2d(psy_chart.chart_border, z)] temp_lines_i = [ from_linesegment2d(tl, z) for tl in psy_chart.temperature_lines ] rh_lines_i = [from_polyline2d(rhl, z) for rhl in psy_chart.rh_lines] hr_lines_i = [from_linesegment2d(hrl, z) for hrl in psy_chart.hr_lines] # add the text to the various lines title_i.append( text_objects(psy_chart.x_axis_text, plane_from_point(psy_chart.x_axis_location), psy_chart.legend_parameters.text_height * 1.5, psy_chart.legend_parameters.font, 0, 0)) title_i.append( text_objects( psy_chart.y_axis_text, plane_from_point(psy_chart.y_axis_location, Vector3D(0, 1)), psy_chart.legend_parameters.text_height * 1.5, psy_chart.legend_parameters.font, 2, 0)) temp_lines_i = temp_lines_i + small_labels( psy_chart, psy_chart.temperature_labels, psy_chart.temperature_label_points, 1, 0) rh_lines_i = rh_lines_i + small_labels(psy_chart, psy_chart.rh_labels[:-1], psy_chart.rh_label_points[:-1], 2, 3, 0.8) hr_lines_i = hr_lines_i + small_labels(psy_chart, psy_chart.hr_labels, psy_chart.hr_label_points, 0, 3) # add enthalpy or wet bulb lines if plot_wet_bulb_: enth_wb_lines_i = [ from_linesegment2d(el, z) for el in psy_chart.wb_lines ] enth_wb_lines_i = enth_wb_lines_i + small_labels( psy_chart, psy_chart.wb_labels, psy_chart.wb_label_points, 2, 3) else: enth_wb_lines_i = [ from_linesegment2d(el, z) for el in psy_chart.enthalpy_lines ] enth_wb_lines_i = enth_wb_lines_i + small_labels( psy_chart, psy_chart.enthalpy_labels, psy_chart.enthalpy_label_points, 2, 3) # add all of the objects to the bse list title.append(title_i) temp_lines.append(temp_lines_i) rh_lines.append(rh_lines_i) hr_lines.append(hr_lines_i) enth_wb_lines.append(enth_wb_lines_i)
def human_height_points(position, height, pt_count): """Get a list of points and a line representing the human geometry. Args: position: Rhino point for the position of the human. height: Number for the height of the human. pt_count: Integer for the number of points representing the human. Returns: A tuple with human points as first element and human line as second. Both geomtries are Rhino geometries. """ lb_feet_pt = to_point3d(position).move(Vector3D(0, 0, height / 100)) lb_hum_line = LineSegment3D(lb_feet_pt, Vector3D(0, 0, height)) lb_pts = [lb_hum_line.midpoint] if pt_count == 1 else \ lb_hum_line.subdivide_evenly(pt_count - 1) if len(lb_pts) == pt_count - 1: # sometimes tolerance kills the last point lb_pts.append(lb_feet_pt.move(Vector3D(0, 0, height))) h_points = [from_point3d(pt) for pt in lb_pts] return h_points, from_linesegment3d(lb_hum_line)
def test_cylinder_duplicate(): """Test the Cylinder duplicate method.""" c = Cylinder(Point3D(0, 0.5, 2), Vector3D(1, 0.5, 2.5), 0.75) test = c.duplicate() assert test.radius == 0.75 assert c.center.x == pytest.approx(0, rel=1e-3) assert c.center.y == pytest.approx(0.5, rel=1e-3) assert c.center.z == pytest.approx(2, rel=1e-3) assert c.axis.x == pytest.approx(1, rel=1e-3) assert c.axis.y == pytest.approx(0.5, rel=1e-3) assert c.axis.z == pytest.approx(2.5, rel=1e-3)
def test_cylinder_to_from_dict(): """Test the Cylinder to_dict and from_dict methods.""" c = Cylinder(Point3D(4, 0.5, 2), Vector3D(1, 0, 2.5), 0.7) d = c.to_dict() c = Cylinder.from_dict(d) assert c.center.x == pytest.approx(4, rel=1e-3) assert c.center.y == pytest.approx(0.5, rel=1e-3) assert c.center.z == pytest.approx(2, rel=1e-3) assert c.axis.x == pytest.approx(1, rel=1e-3) assert c.axis.y == pytest.approx(0, rel=1e-3) assert c.axis.z == pytest.approx(2.5, rel=1e-3)
def test_cylinder_scale(): """Test the Cylinder scale method.""" c = Cylinder(Point3D(4, 0.5, 2), Vector3D(1, 0, 2.5), 0.7) test = c.scale(2, Point3D(0, 0, 0)) assert test.center.x == pytest.approx(8, rel=1e-3) assert test.center.y == pytest.approx(1, rel=1e-3) assert test.center.z == pytest.approx(4, rel=1e-3) assert test.axis.x == pytest.approx(2, rel=1e-3) assert test.axis.y == pytest.approx(0, rel=1e-3) assert test.axis.z == pytest.approx(5, rel=1e-3) assert test.radius == pytest.approx(1.4, rel=1e-3)
def test_remove_colinear_vertices(): """Test the remove_colinear_vertices method of Face3D.""" pts_1 = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2), Point3D(0, 2)) pts_2 = (Point3D(0, 0), Point3D(1, 0), Point3D(2, 0), Point3D(2, 2), Point3D(0, 2)) plane_1 = Plane(Vector3D(0, 0, 1)) face_1 = Face3D(pts_1, plane_1) face_2 = Face3D(pts_2, plane_1) assert len(face_1.remove_colinear_vertices(0.0001).vertices) == 4 assert len(face_2.remove_colinear_vertices(0.0001).vertices) == 4
def test_init_from_endpoints(): """Test the initalization of LineSegment3D from end points.""" pt_1 = Point3D(2, 0, 2) pt_2 = Point3D(2, 2, 2) seg = LineSegment3D.from_end_points(pt_1, pt_2) assert seg.p == Point3D(2, 0, 2) assert seg.v == Vector3D(0, 2, 0) assert seg.p1 == Point3D(2, 0, 2) assert seg.p2 == Point3D(2, 2, 2) assert seg.length == 2
def test_cone_duplicate(): """Test the Cone duplicate method.""" c = Cone(Point3D(0, 0.5, 2), Vector3D(1, 0.5, 2.5), 0.75) test = c.duplicate() assert test.angle == 0.75 assert c.vertex.x == pytest.approx(0, rel=1e-3) assert c.vertex.y == pytest.approx(0.5, rel=1e-3) assert c.vertex.z == pytest.approx(2, rel=1e-3) assert c.axis.x == pytest.approx(1, rel=1e-3) assert c.axis.y == pytest.approx(0.5, rel=1e-3) assert c.axis.z == pytest.approx(2.5, rel=1e-3)
def test_cone_to_from_dict(): """Test the Cone to_dict and from_dict methods.""" c = Cone(Point3D(4, 0.5, 2), Vector3D(1, 0, 2.5), 0.7) d = c.to_dict() c = Cone.from_dict(d) assert c.vertex.x == pytest.approx(4, rel=1e-3) assert c.vertex.y == pytest.approx(0.5, rel=1e-3) assert c.vertex.z == pytest.approx(2, rel=1e-3) assert c.axis.x == pytest.approx(1, rel=1e-3) assert c.axis.y == pytest.approx(0, rel=1e-3) assert c.axis.z == pytest.approx(2.5, rel=1e-3)
def test_color_face(): """Test ColorFace.""" pts_1 = [Point3D(0, 0, 0), Point3D(0, 10, 0), Point3D(10, 10, 0), Point3D(10, 0, 0)] pts_2 = [Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(0, 10, 3), Point3D(0, 10, 0)] pts_3 = [Point3D(0, 0, 0), Point3D(10, 0, 0), Point3D(10, 0, 3), Point3D(0, 0, 3)] pts_4 = [Point3D(10, 10, 0), Point3D(0, 10, 0), Point3D(0, 10, 3), Point3D(10, 10, 3)] pts_5 = [Point3D(10, 10, 0), Point3D(10, 0, 0), Point3D(10, 0, 3), Point3D(10, 10, 3)] pts_6 = [Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3), Point3D(0, 0, 3)] face_1 = Face('Face1', Face3D(pts_1)) face_2 = Face('Face2', Face3D(pts_2)) face_3 = Face('Face3', Face3D(pts_3)) face_4 = Face('Face4', Face3D(pts_4)) face_5 = Face('Face5', Face3D(pts_5)) face_6 = Face('Face6', Face3D(pts_6)) face_2.apertures_by_ratio(0.4, 0.01) face_2.apertures[0].overhang(0.5, indoor=False) face_2.apertures[0].overhang(0.5, indoor=True) face_2.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, 5, 1), Point3D(2.5, 5, 1), Point3D(2.5, 5, 2.5), Point3D(4.5, 5, 2.5)] door = Door('FrontDoor', Face3D(door_verts)) aperture = Aperture('Partition', Face3D(aperture_verts)) table_geo = Face3D.from_rectangle(2, 2, Plane(o=Point3D(1.5, 4, 1))) table = Shade('Table', table_geo) tree_canopy_geo = Face3D.from_regular_polygon(6, 2, Plane(o=Point3D(5, -3, 4))) tree_canopy = Shade('TreeCanopy', tree_canopy_geo) all_geo = [face_1, face_2, face_3, face_4, face_5, face_6, table, tree_canopy, aperture, door] color_face1 = ColorFace(all_geo, 'display_name') color_face2 = ColorFace(all_geo, 'boundary_condition') assert len(color_face1.faces) == len(color_face2.faces) == len(all_geo) assert len(color_face1.flat_faces) == len(color_face2.flat_faces) == len(all_geo) + 3 assert color_face1.flat_geometry[1].has_holes # ensure punched geometry is used assert color_face1.attr_name == color_face1.attr_name_end == 'display_name' assert color_face2.attr_name == color_face2.attr_name_end == 'boundary_condition' assert color_face1.attributes == \ ('Face1', 'Face2', 'Face2_Glz0', 'Face2_Glz0_OutOverhang0', 'Face2_Glz0_InOverhang0', 'Face3', 'Face4', 'Face5', 'Face6', 'Table', 'TreeCanopy', 'Partition', 'FrontDoor') assert color_face2.attributes == \ ('Ground', 'Outdoors', 'Outdoors', 'N/A', 'N/A', 'Outdoors', 'Outdoors', 'Outdoors', 'Outdoors', 'N/A', 'N/A', 'Outdoors', 'Outdoors') assert isinstance(color_face1.graphic_container, GraphicContainer) assert len(color_face1.attributes_unique) == \ len(color_face1.graphic_container.legend.segment_colors) == \ len(color_face1.attributes) assert len(color_face2.attributes_unique) == \ len(color_face2.graphic_container.legend.segment_colors) == 3 assert isinstance(color_face1.min_point, Point3D) assert isinstance(color_face1.max_point, Point3D)
def test_xy_to_xyz(): """Test the xy_to_xyz method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 0, 2) plane = Plane(vec, pt) test_pt = Point2D(2, 2) assert plane.xy_to_xyz(test_pt) == Point3D(4, 4, 2) test_pt = Point2D(-1, -1) assert plane.xy_to_xyz(test_pt) == Point3D(1, 1, 2) assert isinstance(plane.xy_to_xyz(test_pt), Point3D)
def test_vector3_mutability(): """Test the immutability of Vector3D objects.""" vec = Vector3D(0, 2, 0) assert isinstance(vec, Vector3D) vec_copy = vec.duplicate() assert vec == vec_copy with pytest.raises(AttributeError): vec.x = 2 norm_vec = vec.normalize() # ensure operations tha yield new vectors are ok assert norm_vec.magnitude == pytest.approx(1., rel=1e-3)
def test_xyz_to_xy(): """Test the xyz_to_xy method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 0, 2) plane = Plane(vec, pt) test_pt = Point3D(4, 4, 2) assert plane.xyz_to_xy(test_pt) == Point2D(2, 2) test_pt = Point3D(0, 0, 2) assert plane.xyz_to_xy(test_pt) == Point2D(-2, -2) assert isinstance(plane.xyz_to_xy(test_pt), Point2D)
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('RectangleWindow', 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 daylight_mesh_grid(info): for i in range(len(info.approved_rooms)): ext_wall = info.approved_rooms[i].geo_ene_ext_wall ext_wall_normal = -ext_wall.normal.normalize() #angle = np.arccos(ext_wall_normal.dot(Vector3D(0,1,0))) angle = -ext_wall_normal.angle(Vector3D(0, 1, 0)) if ext_wall_normal.x < 0: angle = -angle origin_floor = Face3D([Point3D(0,0,0), Point3D(0,0,0) + \ Point3D(1,0,0)*info.room_dim_width, Point3D(0,0,0) + \ Point3D(1,0,0)*info.room_dim_width + \ Point3D(0,1,0)*info.room_dim_depth, Point3D(0,0,0) + \ Point3D(0,1,0)*info.room_dim_depth]) origin_mesh = origin_floor.mesh_grid(x_dim=info.day_grid_x_dim, y_dim=info.day_grid_y_dim, offset=info.rad_grid_offset, flip=False, generate_centroids=True) offset_vec = Vector3D(0, 0, 1) * info.day_sensorpoint_height origin = ext_wall.upper_left_counter_clockwise_vertices[1] moving_vec = offset_vec + origin moved_mesh = origin_mesh.move(moving_vec) mesh = moved_mesh.rotate_xy(angle, origin) info.approved_rooms[i].mesh_grid = mesh save_day_mesh_to_files(info, i, mesh)
def test_distance_to_point(): """Test the Plane distance_to_point method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) plane = Plane(vec, pt) test_pt = Point3D(0, 4, 0) assert plane.distance_to_point(test_pt) == 2 test_pt = Point3D(4, 4, 4) assert plane.distance_to_point(test_pt) == 2 test_pt = Point3D(4, 2, 4) assert plane.distance_to_point(test_pt) == 0
def test_scale_world_origin(): """Test the Plane scale method with None origin.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) plane = Plane(vec, pt) new_plane = plane.scale(2) assert new_plane.o == Point3D(4, 4, 4) assert new_plane.n == Point3D(0, 1, 0) assert new_plane.x == plane.x assert new_plane.y == plane.y assert new_plane.k == 4