How to use the svgpathtools.path.Arc function in svgpathtools

To help you get started, we’ve selected a few svgpathtools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathandy / svgpathtools / svgpathtools / path.py View on Github external
def cropped(self, t0, t1):
        """returns a cropped copy of this segment which starts at
        self.point(t0) and ends at self.point(t1)."""
        if abs(self.delta*(t1 - t0)) <= 180:
            new_large_arc = 0
        else:
            new_large_arc = 1
        return Arc(self.point(t0), radius=self.radius, rotation=self.rotation,
                   large_arc=new_large_arc, sweep=self.sweep,
                   end=self.point(t1), autoscale_radius=self.autoscale_radius)
github mathandy / svgpathtools / svgpathtools / path.py View on Github external
def translate(curve, z0):
    """Shifts the curve by the complex quantity z such that
    translate(curve, z0).point(t) = curve.point(t) + z0"""
    if isinstance(curve, Path):
        return Path(*[translate(seg, z0) for seg in curve])
    elif is_bezier_segment(curve):
        return bpoints2bezier([bpt + z0 for bpt in curve.bpoints()])
    elif isinstance(curve, Arc):
        new_start = curve.start + z0
        new_end = curve.end + z0
        return Arc(new_start, radius=curve.radius, rotation=curve.rotation,
                   large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")
github mathandy / svgpathtools / svgpathtools / parser.py View on Github external
end += current_pos

            segments.append(QuadraticBezier(current_pos, control, end))
            current_pos = end

        elif command == 'A':
            radius = float(elements.pop()) + float(elements.pop()) * 1j
            rotation = float(elements.pop())
            arc = float(elements.pop())
            sweep = float(elements.pop())
            end = float(elements.pop()) + float(elements.pop()) * 1j

            if not absolute:
                end += current_pos

            segments.append(Arc(current_pos, radius, rotation, arc, sweep, end))
            current_pos = end

    return segments
github mathandy / svgpathtools / svgpathtools / path.py View on Github external
if sy is None:
            return sx*z
        return sx*z.real + isy*z.imag          

    def scale_bezier(bez):
        p = [_scale(c) for c in bez2poly(bez)]
        p[-1] += origin - _scale(origin)
        return poly2bez(p)

    if isinstance(curve, Path):
        return Path(*[scale(seg, sx, sy, origin) for seg in curve])
    elif is_bezier_segment(curve):
        return scale_bezier(curve)
    elif isinstance(curve, Arc):
        if sy is None or sy == sx:
            return Arc(start=sx*(curve.start - origin) + origin,
                       radius=sx*curve.radius,
                       rotation=curve.rotation, 
                       large_arc=curve.large_arc, 
                       sweep=curve.sweep, 
                       end=sx*(curve.end - origin) + origin)
        else:
            raise Exception("\nFor `Arc` objects, only scale transforms "
                            "with sx==sy are implemented.\n")
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")
github mathandy / svgpathtools / svgpathtools / path.py View on Github external
def to_vector(z):
        return np.array([[z.real], [z.imag], [0.0]])

    def to_complex(v):
        return v.item(0) + 1j * v.item(1)

    if isinstance(curve, Path):
        return Path(*[transform(segment, tf) for segment in curve])
    elif is_bezier_segment(curve):
        return bpoints2bezier([to_complex(tf.dot(to_point(p)))
                               for p in curve.bpoints()])
    elif isinstance(curve, Arc):
        new_start = to_complex(tf.dot(to_point(curve.start)))
        new_end = to_complex(tf.dot(to_point(curve.end)))
        new_radius = to_complex(tf.dot(to_vector(curve.radius)))
        return Arc(new_start, radius=new_radius, rotation=curve.rotation,
                   large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")
github mathandy / svgpathtools / svgpathtools / path.py View on Github external
if origin is None:
        if isinstance(curve, Arc):
            origin = curve.center
        else:
            origin = curve.point(0.5)

    if isinstance(curve, Path):
        return Path(*[rotate(seg, degs, origin=origin) for seg in curve])
    elif is_bezier_segment(curve):
        return bpoints2bezier([transform(bpt) for bpt in curve.bpoints()])
    elif isinstance(curve, Arc):
        new_start = transform(curve.start)
        new_end = transform(curve.end)
        new_rotation = curve.rotation + degs
        return Arc(new_start, radius=curve.radius, rotation=new_rotation,
                   large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
    else:
        raise TypeError("Input `curve` should be a Path, Line, "
                        "QuadraticBezier, CubicBezier, or Arc object.")