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)
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"
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
def test_multiple_first_move_to(self): path = Path(start=(1, 0, 0)) path.move_to((2, 0, 0)) path.move_to((3, 0, 0)) path.move_to((4, 0, 0)) assert path.start.isclose((4, 0, 0)), "should reset the start point" assert len(path) == 0, "should not add a MOVETO cmd as first cmd" assert path.has_sub_paths is False
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)
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
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_extend_path_by_another_multi_path(): path = Path((1, 0, 0)) path.line_to((2, 0, 0)) p1 = Path((3, 0, 0)) p1.line_to((4, 0, 0)) p1.move_to((5, 0, 0)) path.extend_multi_path(p1) assert path.has_sub_paths is True assert path.start == (1, 0, 0) assert path.end == (5, 0, 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
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
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)
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)
def simple_multi_path(self): path = Path(start=(1, 0, 0)) path.line_to((2, 0, 0)) path.move_to((3, 0, 0)) return path