Example #1
0
 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"
Example #2
0
 def test_one_path_line_to(self):
     path = Path()
     path.line_to((1, 0))
     result = transform_paths([path], Matrix44())
     path0 = result[0]
     assert path0[0].type == Command.LINE_TO
     assert path0.start == (0, 0)
     assert path0.end == (1, 0)
Example #3
0
 def test_to_ocs(self):
     p = Path((0, 1, 1))
     p.line_to((0, 1, 3))
     ocs = OCS((1, 0, 0))  # x-Axis
     result = list(transform_paths_to_ocs([p], ocs))
     p0 = result[0]
     assert ocs.from_wcs((0, 1, 1)) == p0.start
     assert ocs.from_wcs((0, 1, 3)) == p0[0].end
Example #4
0
def test_approximate_lines():
    path = Path()
    path.line_to((1, 1))
    path.line_to((2, 0))
    vertices = list(path.approximate())
    assert len(vertices) == 3
    assert vertices[0] == path.start == (0, 0)
    assert vertices[2] == path.end == (2, 0)
Example #5
0
def test_approximate_line_curves():
    path = Path()
    path.line_to((2, 0))
    path.curve_to((4, 0), (2, 1), (4, 1))
    vertices = list(path.approximate(10))
    assert len(vertices) == 12
    assert vertices[0] == (0, 0)
    assert vertices[1] == (2, 0)
    assert vertices[-1] == (4, 0)
Example #6
0
def test_has_clockwise_orientation():
    # basic has_clockwise_orientation() function is tested in:
    # test_617_clockwise_orientation
    path = Path.from_vertices([(0, 0), (1, 0), (1, 1), (0, 1)])
    assert path.has_clockwise_orientation() is True

    path = Path()
    path.line_to((2, 0))
    path.curve_to((4, 0), (2, 1), (4, 1))  # end, ctrl1, ctrl2
    assert path.has_clockwise_orientation() is False
Example #7
0
def test_transform():
    path = Path()
    path.line_to((2, 0))
    path.curve_to((4, 0), (2, 1), (4, 1))
    p2 = path.transform(Matrix44.translate(1, 1, 0))
    assert p2.start == (1, 1)
    assert p2[0][1] == (3, 1)  # line to location
    assert p2[1][1] == (5, 1)  # cubic to location
    assert p2[1][2] == (3, 2)  # cubic ctrl1
    assert p2[1][3] == (5, 2)  # cubic ctrl2
    assert p2.end == (5, 1)
Example #8
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)
Example #9
0
    def test_two_paths_one_command(self):
        path_a = Path()
        path_a.line_to((1, 0))
        path_b = Path((2, 0))
        path_b.line_to((3, 0))
        result = transform_paths([path_a, path_b], Matrix44())

        path0 = result[0]
        assert path0[0].type == Command.LINE_TO
        assert path0.start == (0, 0)
        assert path0.end == (1, 0)

        path1 = result[1]
        assert path1[0].type == Command.LINE_TO
        assert path1.start == (2, 0)
        assert path1.end == (3, 0)
Example #10
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)
Example #11
0
def test_line_to():
    path = Path()
    path.line_to((1, 2, 3))
    assert path[0] == (Vector(1, 2, 3), )
    assert path.end == (1, 2, 3)
Example #12
0
 def path(self):
     p = Path()
     p.line_to((4, 0, 0))
     p.curve4_to((0, 0, 0), (3, 1, 1), (1, 1, 1))
     return p
Example #13
0
 def test_one_path(self):
     p = Path()
     p.line_to((1, 2, 3))
     assert bbox([p]).size == (1, 2, 3)
Example #14
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
Example #15
0
 def test_two_path(self):
     p1 = Path()
     p1.line_to((1, 2, 3))
     p2 = Path()
     p2.line_to((-3, -2, -1))
     assert bbox([p1, p2]).size == (4, 4, 4)
Example #16
0
def p1():
    path = Path()
    path.line_to((2, 0))
    path.curve_to((4, 0), (2, 1), (4, 1))  # end, ctrl1, ctrl2
    return path
Example #17
0
 def spath(self):
     p = Path()
     p.line_to((1, 2, 3))
     return p
Example #18
0
def test_reversing_one_line():
    p = Path()
    p.line_to((1, 0))
    p2 = list(p.reversed().control_vertices())
    assert p2 == [(1, 0), (0, 0)]
Example #19
0
def test_line_to():
    path = Path()
    path.line_to((1, 2, 3))
    assert path[0] == (Command.LINE_TO, Vector(1, 2, 3))
    assert path.end == (1, 2, 3)