def test_multiple_segments(self): p = Path() p.curve4_to((4, 0), (1, 2), (3, 2)) p.line_to((6, 0)) p.curve3_to((8, 0), (7, 1)) result = list(to_bsplines_and_vertices(p)) assert len(result) == 3, "expected three segments"
def test_approximate_curves(): path = Path() path.curve3_to((2, 0), (1, 1)) path.curve4_to((3, 0), (2, 1), (3, 1)) vertices = list(path.approximate(20)) assert len(vertices) == 41 assert vertices[0] == (0, 0) assert vertices[-1] == (3, 0)
def test_one_path_curve3_to(self): path = Path() path.curve3_to((2, 0), (1, 1)) result = transform_paths([path], Matrix44()) path0 = result[0] assert path0[0].type == Command.CURVE3_TO assert len(path0[0]) == 2 assert path0.start == (0, 0) assert path0.end == (2, 0)
def test_one_quadratic_bezier(self): p = Path() p.curve3_to((4, 0), (2, 2)) result = list(to_bsplines_and_vertices(p)) assert len(result) == 1, "expected one B-spline" cpnts = result[0].control_points # A quadratic bezier should be converted to cubic bezier curve, which # has a precise cubic B-spline representation. assert len(cpnts) == 4, "expected 4 control vertices" assert cpnts[0] == (0, 0) assert cpnts[3] == (4, 0)
def test_one_path_multiple_command(self): path = Path() path.line_to((1, 0)) path.curve3_to((2, 0), (2.5, 1)) path.curve4_to((3, 0), (2, 1), (3, 1)) result = transform_paths([path], Matrix44()) path0 = result[0] assert path0[0].type == Command.LINE_TO assert path0[1].type == Command.CURVE3_TO assert path0[2].type == Command.CURVE4_TO assert path0.start == (0, 0) assert path0.end == (3, 0)
def test_two_paths_multiple_commands(self): path_a = Path() path_a.line_to((1, 0)) path_a.curve3_to((2, 0), (2.5, 1)) path_a.curve4_to((3, 0), (2, 1), (3, 1)) path_b = path_a.transform(Matrix44.translate(4, 0, 0)) result = transform_paths([path_a, path_b], Matrix44()) path0 = result[0] assert path0[0].type == Command.LINE_TO assert path0[1].type == Command.CURVE3_TO assert path0[2].type == Command.CURVE4_TO assert path0.start == (0, 0) assert path0.end == (3, 0) path1 = result[1] assert path1[0].type == Command.LINE_TO assert path1[1].type == Command.CURVE3_TO assert path1[2].type == Command.CURVE4_TO assert path1.start == (4, 0) assert path1.end == (7, 0)
def test_reversing_one_curve3(): p = Path() p.curve3_to((3, 0), (1.5, 1)) p2 = list(p.reversed().control_vertices()) assert p2 == [(3, 0), (1.5, 1), (0, 0)]
def p1(): path = Path() path.line_to((2, 0)) path.curve4_to((4, 0), (2, 1), (4, 1)) # end, ctrl1, ctrl2 path.curve3_to((6, 0), (5, -1)) # end, ctrl return path
def test_curve3_to(): path = Path() path.curve3_to((10, 0), (5, 5)) assert path[0] == ((10, 0), (5, 5)) assert path.end == (10, 0)
def quadratic(self): p = Path() p.curve3_to((2, 0), (1, 1)) return p