示例#1
0
def test_join_paths(p1, p2, result):
    pth1, pth2 = Path(p1), Path(p2)
    pth1r, pth2r = Path(p1[::-1]), Path(p2[::-1])
    if result is not None:
        result = Path(result)

    def same(p1, p2):
        if p1 is None and p2 is None:
            return True
        elif p1 is None or p2 is None:
            return False
        else:
            return equal_path(p1, p2)

    assert same(pth1.join(pth2), result)
    assert same(pth1r.join(pth2), result)
    assert same(pth1.join(pth2r), result)
    assert same(pth1r.join(pth2r), result)
示例#2
0
def path_pieces(path, segs_to_points):
    """Produce a new series of paths, split at intersection points.

    Yields a series of pieces (paths).  The pieces trace the same line as the
    original path.  The endpoints of the pieces are all intersection points
    in `segs_to_points`, or the endpoints of the original path, if it isn't
    circular.  The pieces are in order along `path`, so consecutive pieces
    end and begin at the same point. If `path` is closed, then the first piece
    returned will begin at the first cut, not at the path's first point.

    """
    # If path is circular, then the first piece we collect has to be added to
    # the last piece, so save it for later.
    collecting_head = path.closed
    head = None

    piece = []
    for pt in path:
        if not piece:
            piece.append(pt)
        else:
            seg = Segment(piece[-1], pt)
            cuts = segs_to_points.get(seg)
            if cuts is not None:
                cuts = seg.sort_along(cuts)
                for cut in cuts:
                    ptcut = Point(*cut)
                    piece.append(ptcut)
                    if collecting_head:
                        head = piece
                        collecting_head = False
                    else:
                        yield Path(piece)
                    piece = [ptcut]
            piece.append(pt)

    piece = Path(piece)
    if head:
        piece = piece.join(Path(head))
    yield piece