def test_arc2_intersect_line_ray(): """Test the Arc2D intersect_line_ray method.""" pt = Point2D(2, 0) arc = Arc2D(pt, 1, 0, math.pi) circle = Arc2D(pt, 1) seg1 = LineSegment2D(pt, Vector2D(2, 2)) seg2 = LineSegment2D(Point2D(0, -2), Vector2D(6, 6)) seg3 = LineSegment2D(pt, Vector2D(0.5, 0.5)) int1 = arc.intersect_line_ray(seg1) assert len(int1) == 1 assert int1[0].x == pytest.approx(2.71, rel=1e-2) assert int1[0].y == pytest.approx(0.71, rel=1e-2) int2 = circle.intersect_line_ray(seg1) assert len(int2) == 1 assert int2[0].x == pytest.approx(2.71, rel=1e-2) assert int2[0].y == pytest.approx(0.71, rel=1e-2) int3 = arc.intersect_line_ray(seg2) assert len(int3) == 1 assert int3[0].x == pytest.approx(2.71, rel=1e-2) assert int3[0].y == pytest.approx(0.71, rel=1e-2) int4 = circle.intersect_line_ray(seg2) assert len(int4) == 2 assert int4[0].x == pytest.approx(2.71, rel=1e-2) assert int4[0].y == pytest.approx(0.71, rel=1e-2) assert int4[1].x == pytest.approx(1.29, rel=1e-2) assert int4[1].y == pytest.approx(-0.71, rel=1e-2) assert arc.intersect_line_ray(seg3) is None
def test_reflect(): """Test the Polygon2D reflect method.""" pts = (Point2D(1, 1), Point2D(2, 1), Point2D(2, 2), Point2D(1, 2)) polygon = Polygon2D(pts) origin_1 = Point2D(1, 0) normal_1 = Vector2D(1, 0) normal_2 = Vector2D(-1, -1).normalize() test_1 = polygon.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[2].x == pytest.approx(0, rel=1e-3) assert test_1[2].y == pytest.approx(2, rel=1e-3) assert polygon.area == pytest.approx(test_1.area, rel=1e-3) assert polygon.perimeter == pytest.approx(test_1.perimeter, rel=1e-3) assert polygon.is_clockwise is not test_1.is_clockwise assert polygon.is_convex is test_1.is_convex assert polygon.is_self_intersecting is test_1.is_self_intersecting test_1 = polygon.reflect(normal_2, Point2D(0, 0)) 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[2].x == pytest.approx(-2, rel=1e-3) assert test_1[2].y == pytest.approx(-2, rel=1e-3) test_2 = polygon.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[2].x == pytest.approx(-1, rel=1e-3) assert test_2[2].y == pytest.approx(-1, rel=1e-3)
def test_countour_fins_by_distance_between(): """Test the countour_fins_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) fins = face_1.countour_fins_by_distance_between(0.5, 0.5, 0.5) assert len(fins) == 4 fins = face_1.countour_fins_by_distance_between(0.25, 0.5, 0.5, contour_vector=Vector2D(1)) assert len(fins) == 8 fins = face_2.countour_fins_by_distance_between(0.5, 0.5, 0.5, contour_vector=Vector2D(1)) assert len(fins) == 8
def test_vector2_angle(): """Test the methods that get the angle between Vector2D objects.""" vec_1 = Vector2D(0, 2) vec_2 = Vector2D(2, 0) vec_3 = Vector2D(0, -2) vec_4 = Vector2D(-2, 0) assert vec_1.angle(vec_2) == pytest.approx(math.pi / 2, rel=1e-3) assert vec_1.angle(vec_3) == pytest.approx(math.pi, rel=1e-3) assert vec_1.angle(vec_4) == pytest.approx(math.pi / 2, rel=1e-3) assert vec_1.angle(vec_1) == pytest.approx(0, rel=1e-3) assert vec_1.angle_counterclockwise(vec_2) == pytest.approx(3 * math.pi / 2, rel=1e-3) assert vec_1.angle_counterclockwise(vec_3) == pytest.approx(math.pi, rel=1e-3) assert vec_1.angle_counterclockwise(vec_4) == pytest.approx(math.pi / 2, rel=1e-3) assert vec_1.angle_counterclockwise(vec_1) == pytest.approx(0, rel=1e-3) assert vec_1.angle_clockwise(vec_2) == pytest.approx(math.pi / 2, rel=1e-3) assert vec_1.angle_clockwise(vec_3) == pytest.approx(math.pi, rel=1e-3) assert vec_1.angle_clockwise(vec_4) == pytest.approx(3 * math.pi / 2, rel=1e-3) assert vec_1.angle_clockwise(vec_1) == pytest.approx(0, rel=1e-3)
def test_reflect(): """Test the Mesh2D reflect method.""" pts = (Point2D(1, 1), Point2D(1, 2), Point2D(2, 2), Point2D(2, 1), Point2D(3, 1)) mesh = Mesh2D(pts, [(0, 1, 2, 3), (2, 3, 4)]) origin_1 = Point2D(1, 0) normal_1 = Vector2D(1, 0) normal_2 = Vector2D(-1, -1).normalize() test_1 = mesh.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[2].x == pytest.approx(0, rel=1e-3) assert test_1[2].y == pytest.approx(2, rel=1e-3) assert mesh.area == test_1.area assert len(mesh.vertices) == len(test_1.vertices) assert len(mesh.faces) == len(test_1.faces) test_1 = mesh.reflect(normal_2, Point2D(0, 0)) 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[2].x == pytest.approx(-2, rel=1e-3) assert test_1[2].y == pytest.approx(-2, rel=1e-3) assert mesh.area == test_1.area assert len(mesh.vertices) == len(test_1.vertices) assert len(mesh.faces) == len(test_1.faces) test_2 = mesh.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[2].x == pytest.approx(-1, rel=1e-3) assert test_2[2].y == pytest.approx(-1, rel=1e-3) assert mesh.area == test_2.area assert len(mesh.vertices) == len(test_2.vertices) assert len(mesh.faces) == len(test_2.faces)
def test_reflect(): """Test the Arc2D reflect method.""" pt = Point2D(2, 2) arc = Arc2D(pt, 2, 0, math.pi) origin_1 = Point2D(0, 1) origin_2 = Point2D(1, 1) normal_1 = Vector2D(0, 1) normal_2 = Vector2D(-1, 1).normalize() assert arc.reflect(normal_1, origin_1).c.x == pytest.approx(2, rel=1e-3) assert arc.reflect(normal_1, origin_1).c.y == pytest.approx(0, rel=1e-3) assert arc.reflect(normal_1, origin_1).midpoint.x == pytest.approx(2, rel=1e-3) assert arc.reflect(normal_1, origin_1).midpoint.y == pytest.approx(-2, rel=1e-3) assert arc.reflect(normal_1, origin_2).c == Point2D(2, 0) assert arc.reflect(normal_1, origin_2).midpoint.x == pytest.approx(2, rel=1e-3) assert arc.reflect(normal_1, origin_2).midpoint.y == pytest.approx(-2, rel=1e-3) test_1 = arc.reflect(normal_2, origin_2) assert test_1.c.x == pytest.approx(2, rel=1e-3) assert test_1.c.y == pytest.approx(2, rel=1e-3) assert test_1.midpoint.x == pytest.approx(4, rel=1e-3) assert test_1.midpoint.y == pytest.approx(2, rel=1e-3)
def test_reflect(): """Test the LineSegment2D reflect method.""" pt = Point2D(2, 2) vec = Vector2D(0, 2) seg = LineSegment2D(pt, vec) origin_1 = Point2D(0, 1) origin_2 = Point2D(1, 1) normal_1 = Vector2D(0, 1) normal_2 = Vector2D(-1, 1).normalize() assert seg.reflect(normal_1, origin_1).p == Point2D(2, 0) assert seg.reflect(normal_1, origin_1).v == Vector2D(0, -2) assert seg.reflect(normal_1, origin_2).p == Point2D(2, 0) assert seg.reflect(normal_1, origin_2).v == Vector2D(0, -2) test_1 = seg.reflect(normal_2, origin_2) assert test_1.p == Point2D(2, 2) assert test_1.v.x == pytest.approx(2, rel=1e-3) assert test_1.v.y == pytest.approx(0, rel=1e-3) test_2 = seg.reflect(normal_2, origin_1) assert test_2.p.x == pytest.approx(1, rel=1e-3) assert test_2.p.y == pytest.approx(3, rel=1e-3) assert test_1.v.x == pytest.approx(2, rel=1e-3) assert test_1.v.y == pytest.approx(0, rel=1e-3)
def test_countour_by_number(): """Test the countour_by_number 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_number(4) 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_number(4, Vector2D(1)) assert len(contours) == 4 assert contours[-1].p2.x == pytest.approx(1.5, rel=1e-3) contours = face_1.countour_by_number(4, Vector2D(1), True) assert len(contours) == 4 assert contours[-1].p2.x == pytest.approx(0.5, rel=1e-3) contours = face_2.countour_by_number(4) assert len(contours) == 4 contours = face_2.countour_by_number(8, Vector2D(1)) assert len(contours) == 8
def _default_dict_parameters(data): """Get defaulted parameters from a base dictionary.""" offset = data['offset'] if 'offset' in data else 0 angle = data['angle'] if 'angle' in data else 0 contr = Vector2D.from_array(data['contour_vector']) if 'contour_vector' in data \ else Vector2D(0, 1) flip = data['flip_start_side'] if 'flip_start_side' in data else False return offset, angle, contr, flip
def test_move(): """Test the Ray2D move method.""" pt = Point2D(2, 0) vec = Vector2D(0, 2) ray = Ray2D(pt, vec) vec_1 = Vector2D(2, 2) new_ray = ray.move(vec_1) assert new_ray.p == Point2D(4, 2) assert new_ray.v == vec
def horizontal_orientation(self, north_vector=Vector2D(0, 1)): """Get a number between 0 and 360 for the orientation of the face in degrees. 0 = North, 90 = East, 180 = South, 270 = West Args: north_vector: A ladybug_geometry Vector2D for the north direction. Default is the Y-axis (0, 1). """ return math.degrees( north_vector.angle_clockwise(Vector2D(self.normal.x, self.normal.y)))
def test_init_from_sdl(): """Test the initialization of LineSegment2D from start, direction, length.""" pt = Point2D(2, 0) vec = Vector2D(0, 1) seg = LineSegment2D.from_sdl(pt, vec, 2) assert seg.p == Point2D(2, 0) assert seg.v == Vector2D(0, 2) assert seg.p1 == Point2D(2, 0) assert seg.p2 == Point2D(2, 2) assert seg.length == 2
def test_circular_mean(): """Test the circular mean staticmethod.""" angles_1 = [math.radians(x) for x in [45, 315]] angles_2 = [math.radians(x) for x in [45, 135]] angles_3 = [math.radians(x) for x in [90, 270]] assert Vector2D.circular_mean(angles_1) == pytest.approx(0, rel=1e-3) assert Vector2D.circular_mean(angles_2) == \ pytest.approx(math.radians(90), rel=1e-3) assert Vector2D.circular_mean(angles_3) == \ pytest.approx(math.radians(180), rel=1e-3)
def test_move(): """Test the LineSegment2D move method.""" pt = Point2D(2, 0) vec = Vector2D(0, 2) seg = LineSegment2D(pt, vec) vec_1 = Vector2D(2, 2) new_seg = seg.move(vec_1) assert new_seg.p == Point2D(4, 2) assert new_seg.v == vec assert new_seg.p1 == Point2D(4, 2) assert new_seg.p2 == Point2D(4, 4)
def test_vector2_to_from_dict(): """Test the initalization of Vector2D objects and basic properties.""" vec = Vector2D(0, 2) vec_dict = vec.to_dict() new_vec = Vector2D.from_dict(vec_dict) assert isinstance(new_vec, Vector2D) assert new_vec.to_dict() == vec_dict pt = Point2D(0, 2) pt_dict = pt.to_dict() new_pt = Point2D.from_dict(pt_dict) assert isinstance(new_pt, Point2D) assert new_pt.to_dict() == pt_dict
def test_ray2d_init(): """Test the initalization of Ray2D objects and basic properties.""" pt = Point2D(2, 0) vec = Vector2D(0, 2) ray = Ray2D(pt, vec) str(ray) # test the string representation of the ray assert ray.p == Point2D(2, 0) assert ray.v == Vector2D(0, 2) flip_ray = ray.reverse() assert flip_ray.p == Point2D(2, 0) assert flip_ray.v == Vector2D(0, -2)
def test_to_from_array(): """Test to/from array method.""" test_ray = Ray2D(Point2D(2, 0), Vector2D(2, 2)) ray_array = ((2, 0), (2, 2)) assert test_ray == Ray2D.from_array(ray_array) ray_array = ((2, 0), (2, 2)) test_ray = Ray2D(Point2D(2, 0), Vector2D(2, 2)) assert test_ray.to_array() == ray_array test_ray_2 = Ray2D.from_array(test_ray.to_array()) assert test_ray == test_ray_2
def test_intersect_line_ray_colinear(): """Test the LineSegment2D intersect_line_ray method with colinear segments.""" pt_1 = Point2D(3.5362137509358353, -2.3574758339572237) vec_1 = Vector2D(2.6625609418810905, -1.7750406279207271) seg_1 = LineSegment2D(pt_1, vec_1) pt_2 = Point2D(-1.7889081328263625, 1.1926054218842419) vec_2 = Vector2D(1.7889081328263625, -1.1926054218842419) seg_2 = LineSegment2D(pt_2, vec_2) assert seg_1.intersect_line_ray(seg_2) is None seg_1 = seg_1.flip() assert seg_1.intersect_line_ray(seg_2) is None seg_2 = seg_2.flip() assert seg_1.intersect_line_ray(seg_2) is None pt_1 = Point2D(0, 0) vec_1 = Vector2D(1, 0) seg_1 = LineSegment2D(pt_1, vec_1) pt_2 = Point2D(0, 0) vec_2 = Vector2D(0, 1) seg_2 = LineSegment2D(pt_2, vec_2) assert seg_1.intersect_line_ray(seg_2) == Point2D(0, 0) pt_1 = Point2D(1, 0) vec_1 = Vector2D(-1, 0) seg_1 = LineSegment2D(pt_1, vec_1) assert seg_1.intersect_line_ray(seg_2) == Point2D(0, 0) pt_2 = Point2D(0, 1) vec_2 = Vector2D(0, -1) seg_2 = LineSegment2D(pt_2, vec_2) assert seg_1.intersect_line_ray(seg_2) == Point2D(0, 0) pt_1 = Point2D(0, -1) vec_1 = Vector2D(0, 1) seg_1 = LineSegment2D(pt_1, vec_1) assert seg_1.intersect_line_ray(seg_2) is None pt_2 = Point2D(0, 0) vec_2 = Vector2D(-1, 0) seg_2 = LineSegment2D(pt_2, vec_2) assert seg_1.intersect_line_ray(seg_2) == Point2D(0, 0) pt_2 = Point2D(-1, 0) vec_2 = Vector2D(1, 0) seg_2 = LineSegment2D(pt_2, vec_2) assert seg_1.intersect_line_ray(seg_2) == Point2D(0, 0)
def test_reflect(): """Test the Point2D reflect method.""" pt_1 = Point2D(2, 2) origin_1 = Point2D(0, 1) origin_2 = Point2D(1, 1) normal_1 = Vector2D(0, 1) normal_2 = Vector2D(-1, 1).normalize() assert pt_1.reflect(normal_1, origin_1) == Point2D(2, 0) assert pt_1.reflect(normal_1, origin_2) == Point2D(2, 0) assert pt_1.reflect(normal_2, origin_2) == Point2D(2, 2) test_1 = pt_1.reflect(normal_2, origin_1) assert test_1.x == pytest.approx(1, rel=1e-3) assert test_1.y == pytest.approx(3, rel=1e-3)
def test_reflect(): """Test the Polyline2D reflect method.""" pts = (Point2D(1, 1), Point2D(2, 1), Point2D(2, 2), Point2D(1, 2)) pline = Polyline2D(pts) origin_1 = Point2D(1, 0) normal_1 = Vector2D(1, 0) normal_2 = Vector2D(-1, -1).normalize() test_1 = pline.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[2].x == pytest.approx(0, rel=1e-3) assert test_1[2].y == pytest.approx(2, rel=1e-3) assert pline.length == pytest.approx(test_1.length, rel=1e-3)
def louvers_by_count(self, louver_count, depth, offset=0, angle=0, contour_vector=Vector2D(0, 1), flip_start_side=False, indoor=False, tolerance=0.01, base_name=None): """Add a series of louvered Shade objects covering this Aperture. Args: louver_count: A positive integer for the number of louvers to generate. depth: A number for the depth to extrude the louvers. offset: A number for the distance to louvers from this aperture. Default is 0 for no offset. angle: A number for the for an angle to rotate the louvers in degrees. Positive numbers indicate a downward rotation while negative numbers indicate an upward rotation. Default is 0 for no rotation. contour_vector: A Vector2D for the direction along which contours are generated. This 2D vector will be interpreted into a 3D vector within the plane of this Aperture. (0, 1) will usually generate horizontal contours in 3D space, (1, 0) will generate vertical contours, and (1, 1) will generate diagonal contours. Default: (0, 1). flip_start_side: Boolean to note whether the side the louvers start from should be flipped. Default is False to have louvers on top or right. Setting to True will start contours on the bottom or left. indoor: Boolean for whether louvers should be generated facing the opposite direction of the aperture normal (typically meaning indoor geometry). Default: False. tolerance: An optional value to remove any louvers with a length less than the tolerance. Default: 0.01, suitable for objects in meters. base_name: Optional base name for the shade objects. If None, the default is InShd or OutShd depending on whether indoor is True. Returns: A list of the new Shade objects that have been generated. """ assert louver_count > 0, 'louver_count must be greater than 0.' angle = math.radians(angle) louvers = [] ap_geo = self.geometry if indoor is False else self.geometry.flip() shade_faces = ap_geo.countour_fins_by_number(louver_count, depth, offset, angle, contour_vector, flip_start_side, tolerance) if base_name is None: shd_name_base = '{}_InShd{}' if indoor else '{}_OutShd{}' else: shd_name_base = '{}_' + str(base_name) + '{}' for i, shade_geo in enumerate(shade_faces): louvers.append( Shade(shd_name_base.format(self.identifier, i), shade_geo)) if indoor: self.add_indoor_shades(louvers) else: self.add_outdoor_shades(louvers) return louvers
def chart_border2d(self): """Get a Polyline2D for the border of the plot.""" base_pt = Point2D(self._base_point.x, self._base_point.y) width = self._container.max_point.x - self._container.min_point.x height = self._container.max_point.y - self._container.min_point.y pgon = Polygon2D.from_rectangle(base_pt, Vector2D(0, 1), width, height) return Polyline2D.from_polygon(pgon)
def left_fin(self, depth, angle=0, indoor=False, tolerance=0.01, base_name=None): """Add a single vertical fin on the left side of this Aperture. Args: depth: A number for the fin depth. angle: A number for the for an angle to rotate the fin in degrees. Default is 0 for no rotation. indoor: Boolean for whether the fin should be generated facing the opposite direction of the aperture normal (typically meaning indoor geometry). Default: False. tolerance: An optional value to return None if the fin has a length less than the tolerance. Default: 0.01, suitable for objects in meters. base_name: Optional base name for the shade objects. If None, the default is InLeftFin or OutLeftFin depending on whether indoor is True. Returns: A list of the new Shade objects that have been generated. """ if base_name is None: base_name = 'InLeftFin' if indoor else 'OutLeftFin' return self.louvers_by_count(1, depth, angle=angle, contour_vector=Vector2D(1, 0), flip_start_side=True, indoor=indoor, tolerance=tolerance, base_name=base_name)
def test_intersect_line_ray(): """Test the Ray2D distance_to_point method.""" pt_1 = Point2D(2, 2) vec_1 = Vector2D(0, 2) ray_1 = Ray2D(pt_1, vec_1) pt_2 = Point2D(0, 3) vec_2 = Vector2D(4, 0) ray_2 = Ray2D(pt_2, vec_2) pt_3 = Point2D(0, 0) vec_3 = Vector2D(1, 1) ray_3 = Ray2D(pt_3, vec_3) assert ray_1.intersect_line_ray(ray_2) == Point2D(2, 3) assert ray_1.intersect_line_ray(ray_3) == Point2D(2, 2)
def window_construction_by_orientation(self, construction, orientation=0, offset=45, north_vector=Vector2D(0, 1)): """Set the construction of exterior Apertures in Walls facing a given orientation. This is useful for testing orientation-specific energy conservation strategies or creating AHSRAE baseline buildings. Args: construction: A WindowConstruction that will be assigned to all of the room's Apertures in Walls that are facing a certain orientation. orientation: A number between 0 and 360 that represents the orientation in degrees to which the construction will be assigned. 0 = North, 90 = East, 180 = South, 270 = West. (Default: 0 for North). offset: A number between 0 and 180 that represents the offset from the orientation in degrees for which the construction will be assigned. For example, a value of 45 indicates that any Apertures falling in the 90 degree range around the orientation will get the input construction. (Default: 45). north_vector: A ladybug_geometry Vector3D for the north direction. Default is the Y-axis (0, 1). """ for room in self._host.rooms: room.properties.energy.window_construction_by_orientation( construction, orientation, offset, north_vector)
def test_zero_magnitude_vector(): """Test properties with a zero magnitude vecotr.""" vec = Vector2D(0, 0) assert vec.is_zero() assert vec.magnitude == 0 assert vec.normalize() == vec
def test_intersect_line_ray(): """Test the LineSegment2D intersect_line_ray method.""" pt_1 = Point2D(2, 2) vec_1 = Vector2D(0, 2) seg_1 = LineSegment2D(pt_1, vec_1) pt_2 = Point2D(0, 3) vec_2 = Vector2D(4, 0) seg_2 = LineSegment2D(pt_2, vec_2) pt_3 = Point2D(0, 0) vec_3 = Vector2D(1, 1) seg_3 = LineSegment2D(pt_3, vec_3) assert seg_1.intersect_line_ray(seg_2) == Point2D(2, 3) assert seg_1.intersect_line_ray(seg_3) is None
def test_subdivide(): """Test the LineSegment2D subdivide methods.""" pt = Point2D(2, 2) vec = Vector2D(0, 2) seg = LineSegment2D(pt, vec) divisions = seg.subdivide(0.5) assert len(divisions) == 5 assert divisions[0] == pt assert divisions[1] == Point2D(2, 2.5) assert divisions[2] == Point2D(2, 3) assert divisions[3] == Point2D(2, 3.5) assert divisions[4] == Point2D(2, 4) divisions = seg.subdivide([1, 0.5, 0.25]) assert len(divisions) == 5 assert divisions[0] == pt assert divisions[1] == Point2D(2, 3) assert divisions[2] == Point2D(2, 3.5) assert divisions[3] == Point2D(2, 3.75) assert divisions[4] == Point2D(2, 4) divisions = seg.subdivide_evenly(4) assert len(divisions) == 5 assert divisions[0] == pt assert divisions[1] == Point2D(2, 2.5) assert divisions[2] == Point2D(2, 3) assert divisions[3] == Point2D(2, 3.5) assert divisions[4] == Point2D(2, 4)
def chart_border(self): """Get a Polyline2D for the border of the plot.""" width = self._x_dim * len(self._months_int) height = self._y_dim pgon = Polygon2D.from_rectangle(self._base_point, Vector2D(0, 1), width, height) return Polyline2D.from_polygon(pgon)
def test_is_point_inside(): """Test the Polygon2D is_point_inside method.""" pts = (Point2D(0, 0), Point2D(2, 0), Point2D(2, 2), Point2D(0, 2)) polygon = Polygon2D(pts) assert not polygon.is_point_inside(Point2D(-1, 1)) assert not polygon.is_point_inside(Point2D(1, -1)) assert not polygon.is_point_inside(Point2D(1, 3)) assert not polygon.is_point_inside(Point2D(3, 1)) assert polygon.is_point_inside(Point2D(1, 1)) assert not polygon.is_point_inside(Point2D(-1, 1), Vector2D(0, 1)) assert not polygon.is_point_inside(Point2D(1, -1), Vector2D(0, 1)) assert not polygon.is_point_inside(Point2D(1, 3), Vector2D(0, 1)) assert not polygon.is_point_inside(Point2D(3, 1), Vector2D(0, 1)) assert polygon.is_point_inside(Point2D(1, 1), Vector2D(0, 1))