Esempio n. 1
0
File: geo.py Progetto: kloppen/ezdxf
def _boundaries_to_polygons(boundaries, ocs, elevation):
    paths = (Path.from_hatch_boundary_path(boundary, ocs, elevation)
             for boundary in boundaries)
    for polygon in nesting.fast_bbox_detection(paths):
        exterior = polygon[0]
        # only take exterior path of level 1 holes, nested holes are ignored
        yield exterior, [hole[0] for hole in polygon[1:]]
Esempio n. 2
0
def group_contour_and_holes(
        paths: Iterable[Path]) -> Iterable[Tuple[Path, List[Path]]]:
    """ Group paths created from text strings or entities by their contour
    paths. e.g. "abc" yields 3 [contour, holes] structures::

        ff = fonts.FontFace(family="Arial")
        paths = make_paths_from_str("abc", ff)

        for contour, holes in group_contour_and_holes(paths)
            for hole in holes:
                # hole is a Path() object
                pass

    This is the basic tool to create HATCH entities from paths.

    Warning: This function does not detect separated characters, e.g. "!"
    creates 2 contour paths.

    """
    polygons = nesting.fast_bbox_detection(paths)
    for polygon in polygons:
        contour = polygon[0]
        if len(polygon) > 1:  # are holes present?
            # holes can be recursive polygons, so flatten holes:
            holes = list(nesting.flatten_polygons(polygon[1:]))
        else:
            holes = []
        yield contour, holes
Esempio n. 3
0
def test_fast_bbox_detection(paths, polygons):
    assert nesting.fast_bbox_detection(paths) == polygons