def from_primitive(cls, primitive_type, primitive):
     if primitive_type == PT_LINE:
         start = primitive[0] + primitive[1] * 1j
         end = primitive[2] + primitive[3] * 1j
         width = primitive[4]
         primitive = svgpathtools.Line(start, end)
     elif primitive_type == PT_QBEZIER:
         p1 = primitive[0] + primitive[1] * 1j
         p2 = primitive[2] + primitive[3] * 1j
         p3 = primitive[4] + primitive[5] * 1j
         width = primitive[6]
         primitive = svgpathtools.QuadraticBezier(p1, p2, p3)
     else:
         raise NotImplementedError
     path = svgpathtools.Path(primitive)
     attributes = {'stroke': 'black', 'stroke-width': f'{width}', 'fill': 'none'}
     return cls(path, attributes)
Пример #2
0
def find_path_between_points(p1, p2):
    # temp
    if ruv.distance(p1, p2) < 100:
        edist = 100 - ruv.distance(p1, p2)
        mid = np.array([
            (p1[0] + p1[1]) / 2,
            (p2[0] + p2[1]) / 2
        ])
        dir = p1[0] % 2 == 0
        vec = (p2 - p1) / ruv.distance(p1, p2)
        a = vec[0]
        b = vec[1]
        if dir:
            a = -a
        else:
            b = -b
        vec[0] = b
        vec[1] = a
        p0 = mid + (vec * edist)
        pth = svgpathtools.Path(svgpathtools.QuadraticBezier(complex_as_point(p1), complex_as_point(ruv.cp_for(p1, p0, p2)), complex_as_point(p2)))
    else:
        pth = svgpathtools.Path(svgpathtools.Line(complex_as_point(p1), complex_as_point(p2)))

    return pth.d()
Пример #3
0
def cubic_to_quadratic(curve):
    # Best L2 approximation
    m = (-curve.start + 3 * curve.control1 + 3 * curve.control2 -
         curve.end) / 4.0
    return svgpathtools.QuadraticBezier(curve.start, m, curve.end)
Пример #4
0
 def from_cubic(cls, segment):
     ccoords = [coord for point in segment.bpoints() for coord in (point.real, point.imag)]
     qcoords = cubic_to_quad(*ccoords)
     qpoints = [qcoords[i] + qcoords[i + 1] * 1j for i in range(0, len(qcoords), 2)]
     quads = [qpoints[i:i + 3] for i in range(0, len(qpoints) - 1, 2)]
     return [cls(svgpathtools.QuadraticBezier(*quad)) for quad in quads]
Пример #5
0
 def __init__(self, segment):
     self.segment = svgpathtools.QuadraticBezier(*(np.round(p, INTERNAL_PRECISION) for p in segment))