示例#1
0
def delete_points(path, bounding, delete_selected=True):
    if path is None or bounding is None: return None
    new_path = Path(path, False) # cloneContours = False
    for old_contour in path.contours:
        new_contour = Contour()
        for point in old_contour.points:
            if bounding.contains(point) == delete_selected:
                new_contour.addPoint(Point(point.x, point.y, point.type))
        new_contour.closed = old_contour.closed
        new_path.add(new_contour)
    return new_path
示例#2
0
def snap(shape, distance, strength, position=Point.ZERO):
    """Snap geometry to a grid."""
    def _snap(v, offset=0.0, distance=10.0, strength=1.0):
        return (v * (1.0-strength)) + (strength * round(v / distance) * distance)

    if shape is None: return None
    new_shape = shape.cloneAndClear()
    strength /= 100.0
    for contour in shape.contours:
        c = Contour()
        for pt in contour.points:
            x = _snap(pt.x + position.x, position.x, distance, strength) - position.x
            y = _snap(pt.y + position.y, position.y, distance, strength) - position.y
            c.addPoint(Point(x, y, pt.type))
        c.closed = contour.closed
        new_shape.add(c)
    return new_shape