Exemplo n.º 1
0
def reflect(shape, position, _angle, keep_original):
    """Mirrors and copies the geometry across an invisible axis."""
    if shape is None: return None
    
    new_shape = shape.cloneAndClear()
    for contour in shape.contours:
        c = Contour()
        for point in contour.points:  
            d = distance(point.x, point.y, position.x, position.y)
            a = angle(point.x, point.y, position.x, position.y)
            x, y = coordinates(position.x, position.y, d * cos(radians(a - _angle)), 180 + _angle)
            d = distance(point.x, point.y, x, y)
            a = angle(point.x, point.y, x, y)
            px, py = coordinates(point.x, point.y, d * 2, a)
            c.addPoint(Point(px, py, point.type))
        if contour.closed:
            c.close()
        new_shape.add(c)
        
    if keep_original:
        g = Geometry()
        g.add(shape)
        g.add(new_shape)
        return g
        
    return new_shape
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
def wiggle_contours(contours, offset):
    new_contours = []
    for contour in contours:
        dx = (uniform(0, 1) - 0.5) * offset.x * 2
        dy = (uniform(0, 1) - 0.5) * offset.y * 2
        t = Transform()
        t.translate(dx, dy)
        new_contours.append(Contour(t.map(contour.points), contour.closed))
    return new_contours
Exemplo n.º 5
0
def reflect(shape, position, _angle, keep_original):
    """Mirrors and copies the geometry across an invisible axis."""
    if shape is None: return None

    new_shape = shape.cloneAndClear()
    for contour in shape.contours:
        c = Contour()
        for point in contour.points:
            d = distance(point.x, point.y, position.x, position.y)
            a = angle(point.x, point.y, position.x, position.y)
            x, y = coordinates(position.x, position.y,
                               d * cos(radians(a - _angle)), 180 + _angle)
            d = distance(point.x, point.y, x, y)
            a = angle(point.x, point.y, x, y)
            px, py = coordinates(point.x, point.y, d * 2, a)
            c.addPoint(Point(px, py, point.type))
        if contour.closed:
            c.close()
        new_shape.add(c)

    if keep_original:
        g = Geometry()
        g.add(shape)
        g.add(new_shape)
        return g

    return new_shape
Exemplo n.º 6
0
 def _function(shape, *args, **kwargs):
     from java.util import List
     if isinstance(shape, (list, tuple, List)):
         return fn(shape, *args, **kwargs)
     elif isinstance(shape, Path):
         new_path = Path(shape, False)
         for c in shape.contours:
             new_path.add(Contour(fn(c.points, *args, **kwargs), c.closed))
         return new_path
     elif isinstance(shape, Geometry):
         new_geo = Geometry()
         for path in shape.paths:
             new_geo.add(_map_geo_to_points(fn)(path, *args, **kwargs))
         return new_geo
     return None
Exemplo n.º 7
0
 def _function(shape, *args, **kwargs):
     from java.util import List
     if isinstance(shape, (list, tuple, List)):
         return fn(shape, *args, **kwargs)
     elif isinstance(shape, Point):
         return fn([shape], *args, **kwargs)[0]
     elif isinstance(shape, Contour):
         new_points = fn(shape.points, *args, **kwargs)
         return Contour(new_points, shape.closed)
     elif isinstance(shape, Path):
         path = shape.cloneAndClear()
         for contour in shape.contours:
             path.add(_function(contour, *args, **kwargs))
         return path
     elif isinstance(shape, Geometry):
         g = Geometry()
         for p in shape.paths:
             g.add(_function(p, *args, **kwargs))
         return g