Esempio n. 1
0
 def test_close_last_sub_path(self):
     p = Path()
     p.line_to((1, 0, 0))
     p.move_to((2, 0, 0))
     p.line_to((3, 0, 0))
     p.close_sub_path()
     assert p.end == (2, 0, 0)
Esempio n. 2
0
 def test_for_very_short_line_segments(self, start, delta):
     path = Path((start, 0, 0))
     path.line_to((start + delta, 0, 0))
     path = lines_to_curve4(path)
     assert len(path) == 1
     assert path[0].type == Command.CURVE4_TO
     assert len(list(path.flattening(1))) > 3
Esempio n. 3
0
def test_append_empty_path():
    path = Path((1, 0, 0))
    path.line_to((2, 0, 0))
    start = path.start
    end = path.end
    path.append_path(Path())
    assert start == path.start and end == path.end, "path should be unchanged"
Esempio n. 4
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"
Esempio n. 5
0
 def test_move_to_creates_a_multi_path_object(self):
     path = Path(start=(1, 0, 0))
     path.line_to((2, 0, 0))
     path.move_to((3, 0, 0))
     assert len(path) == 2, "should add a MOVETO cmd as last cmd"
     assert path.has_sub_paths is True, "should be a multi path object"
     assert path.end.isclose((3, 0, 0)), "should end at the MOVETO location"
Esempio n. 6
0
 def test_does_nothing_if_last_sub_path_is_empty(self):
     p = Path()
     p.line_to((1, 0, 0))
     p.move_to((2, 0, 0))
     assert len(p) == 2
     p.close_sub_path()
     assert len(p) == 2
     assert p.end == (2, 0, 0)
Esempio n. 7
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)
Esempio n. 8
0
def test_single_paths_from_a_multi_path_object():
    p = Path((1, 0, 0))
    p.line_to((2, 0, 0))  # 1st sub-path
    p.move_to((3, 0, 0))  # 2nd sub-path
    p.line_to((4, 0, 0))
    p.move_to((5, 0, 0))  # 3rd sub-path
    paths = list(single_paths([p]))
    assert len(paths) == 3
Esempio n. 9
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
Esempio n. 10
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)
Esempio n. 11
0
def test_to_multi_path_ignores_empty_paths():
    p0 = Path((1, 0, 0))
    p0.line_to((2, 0, 0))
    empty = Path((100, 0, 0))
    path = to_multi_path([p0, empty])
    assert len(path) == 1
    assert path.has_sub_paths is False
    assert path.end.isclose((2, 0, 0))
Esempio n. 12
0
 def test_multi_path_to_lwpolylines(self):
     path = Path()
     path.line_to((1, 0, 0))
     path.move_to((2, 0, 0))
     path.line_to((3, 0, 0))
     polylines = list(to_lwpolylines(path))
     assert len(polylines) == 2
     assert len(polylines[0]) == 2
     assert len(polylines[1]) == 2
Esempio n. 13
0
def test_extend_path_by_another_none_empty_path():
    p0 = Path((1, 0, 0))
    p0.line_to((2, 0, 0))
    p1 = Path((3, 0, 0))
    p1.line_to((3, 0, 0))
    p0.extend_multi_path(p1)
    assert p0.has_sub_paths is True
    assert p0.start == (1, 0, 0)
    assert p0.end == (3, 0, 0)
Esempio n. 14
0
def test_extend_path_by_another_single_path():
    path = Path((1, 0, 0))
    path.line_to((2, 0, 0))
    p1 = Path((3, 0, 0))
    p1.line_to((4, 0, 0))
    path.extend_multi_path(p1)
    assert path.has_sub_paths is True
    assert path.start == (1, 0, 0)
    assert path.end == (4, 0, 0)
Esempio n. 15
0
def test_append_path_with_a_gap():
    p1 = Path((1, 0, 0))
    p1.line_to((2, 0, 0))
    p2 = Path((3, 0, 0))
    p2.line_to((4, 0, 0))
    p1.append_path(p2)
    assert p1.start == (1, 0)
    assert p1.end == (4, 0)
    assert len(p1) == 3
Esempio n. 16
0
 def test_which_length_is_too_short_to_create_a_curve(self, start, delta):
     path = Path((start, 0, 0))
     path.line_to((start + delta, 0, 0))
     path = lines_to_curve4(path)
     assert len(path) == 1
     assert (
         path[0].type == Command.LINE_TO
     ), "should not remove a single line segment representing a point"
     assert len(list(path.flattening(1))) == 2
Esempio n. 17
0
def test_sub_paths_inherit_parent_user_data():
    path = Path()
    path.user_data = "data"
    path.line_to((1, 2, 3))
    path.move_to((7, 8, 9))
    path.line_to((7, 8, 9))
    assert path.has_sub_paths is True
    for p in path.sub_paths():
        assert p.user_data == "data"
 def test_draw_scaled_path(self, backend):
     p1 = Path((1, 2))
     p1.line_to((2, 3))
     backend.draw_path(p1, Properties())
     f = backend.factor
     expected_p2 = p1.transform(Matrix44.scale(f, f, f))
     p2 = backend.collector[0][1]
     for v1, v2 in zip(p2.control_vertices(),
                       expected_p2.control_vertices()):
         assert v1.isclose(v2)
Esempio n. 19
0
 def test_remove_line_segments_of_zero_length_at_the_end(self):
     # CURVE3_TO and CURVE4_TO can not process zero length segments
     path = Path()
     path.line_to((1, 0))
     path.line_to((1, 0))  # line segment of length==0 should be removed
     path = lines_to_curve4(path)
     assert len(path) == 1
     assert path.start == (0, 0)
     assert path[0].type == Command.CURVE4_TO
     assert path[0].end == (1, 0)
Esempio n. 20
0
def test_has_clockwise_orientation():
    # basic has_clockwise_orientation() function is tested in:
    # test_617_clockwise_orientation
    path = converter.from_vertices([(0, 0), (1, 0), (1, 1), (0, 1)])
    assert path.has_clockwise_orientation() is False

    path = Path()
    path.line_to((2, 0))
    path.curve4_to((4, 0), (2, 1), (4, 1))  # end, ctrl1, ctrl2
    assert path.has_clockwise_orientation() is True
Esempio n. 21
0
 def test_line_to_curve_creates_a_linear_segment(self, func):
     v1, v2 = 1, 2
     path = Path(start=(v1, v1, v1))
     path.line_to((v2, v2, v2))
     path = func(path)
     vertices = list(path.flattening(1))
     assert len(vertices) > 2
     assert all([
         math.isclose(v.x, v.y) and math.isclose(v.x, v.z) for v in vertices
     ]), "all vertices have to be located along a line (x == y == z)"
Esempio n. 22
0
def test_reversing_multi_path_with_a_move_to_cmd_at_the_end():
    p = Path()
    p.line_to((1, 0, 0))
    p.move_to((2, 0, 0))
    # The last move_to will become the first move_to.
    # A move_to as first command just moves the start point.
    r = p.reversed()
    assert len(r) == 1
    assert r.start == (1, 0, 0)
    assert r.end == (0, 0, 0)
    assert r.has_sub_paths is False
Esempio n. 23
0
 def test_multi_path_objects(self):
     path = Path()
     path.line_to((1, 0, 0))
     path.move_to((2, 0, 0))
     paths = transform_paths([path], Matrix44.translate(0, 1, 0))
     assert len(paths) == 1
     path2 = paths[0]
     assert path2.start.isclose((0, 1, 0))
     assert len(path2) == 2
     assert path2.end.isclose((2, 1, 0))
     assert path2.has_sub_paths is True
Esempio n. 24
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)
Esempio n. 25
0
def test_to_multi_path():
    p0 = Path((1, 0, 0))
    p0.line_to((2, 0, 0))
    p0.move_to((3, 0, 0))  # will be replaced by move_to(4, 0, 0)
    p1 = Path((4, 0, 0))
    p1.line_to((5, 0, 0))
    p1.move_to((6, 0, 0))
    path = to_multi_path([p0, p1])
    assert path.has_sub_paths is True
    assert path.start == (1, 0, 0)
    assert path.end == (6, 0, 0)
    assert path[1].type == Command.MOVE_TO
    assert path[1].end == (4, 0, 0)
Esempio n. 26
0
def test_reversing_multi_path():
    p = Path()
    p.line_to((1, 0, 0))
    p.move_to((2, 0, 0))
    p.line_to((3, 0, 0))
    r = p.reversed()
    assert r.has_sub_paths is True
    assert len(r) == 3
    assert r.start == (3, 0, 0)
    assert r.end == (0, 0, 0)

    r0, r1 = r.sub_paths()
    assert r0.start == (3, 0, 0)
    assert r0.end == (2, 0, 0)
    assert r1.start == (1, 0, 0)
    assert r1.end == (0, 0, 0)
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
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)]
Esempio n. 30
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