Exemplo n.º 1
0
def _structure_Path(data, cls):
    points = []
    extraData = None
    if data[-1].__class__ is dict:
        extraData = data[-1]
        data = data[:-1]
    for arr in data:
        if arr[-1].__class__ is dict:
            _extraData = arr[-1]
            point = Point(*arr[:-1])
            point._extraData = _extraData
        else:
            point = Point(*arr)
        points.append(point)
    path = cls(points)
    if extraData is not None:
        path._extraData = extraData
    return path
Exemplo n.º 2
0
def _structure_Path(data, cls):
    points = []
    for element in data:
        if element.__class__ is dict:
            point._extraData = element
        else:
            point = Point(*element)
            points.append(point)
    return cls(points)
Exemplo n.º 3
0
 def intoCurve(self):
     points = self._points
     index = self._end
     onCurve = points[index]
     if onCurve.type == "line":
         start = points[self._start - 1]
         points.insert(
             index,
             Point(
                 start.x + .65 * (onCurve.x - start.x),
                 start.y + .65 * (onCurve.y - start.y),
             ))
         points.insert(
             index,
             Point(
                 start.x + .35 * (onCurve.x - start.x),
                 start.y + .35 * (onCurve.y - start.y),
             ))
         onCurve.type = "curve"
Exemplo n.º 4
0
 def splitSegment(self, index, t):
     segments = self._segments
     segment = segments[index]
     pts = segment.points
     pts_len = len(pts)
     if pts_len == 2:
         p1, p2 = pts
         p = Point(p1.x + (p2.x - p1.x) * t, p1.y + (p2.y - p1.y) * t,
                   "line")
         self._points.insert(segment._start, p)
         newSegment = copy(segment)
         segments.insert(index, newSegment)
         for seg in segments[index + 1:]:
             seg._start += 1
             seg._end += 1
     elif pts_len == 4:
         # inline
         p1, p2, p3, p4 = [(p.x, p.y) for p in pts]
         (p1, p2, p3,
          p4), (p5, p6, p7,
                p8) = bezierTools.splitCubicAtT(p1, p2, p3, p4, t)
         points = self._points
         start = segment._start
         p = points[start]
         p.x, p.y = p6
         p = points[start + 1]
         p.x, p.y = p7
         p = points[start + 2]
         p.x, p.y = p8
         points[start:start] = [
             Point(*p2),
             Point(*p3),
             Point(*p4, "curve", smooth=True)
         ]
         newSegment = copy(segment)
         segments.insert(index, newSegment)
         for seg in segments[index + 1:]:
             seg._start += 3
             seg._end += 3
     else:
         raise ValueError("unattended len %d" % pts_len)
     return newSegment
Exemplo n.º 5
0
 def addOffCurves(self):
     points = self._points
     index = self._end
     onCurve = points[index]
     if onCurve.type == "line":
         start = points[self._start - 1]
         points.insert(
             index,
             Point(
                 start.x + .65 * (onCurve.x - start.x),
                 start.y + .65 * (onCurve.y - start.y),
             ))
         points.insert(
             index,
             Point(
                 start.x + .35 * (onCurve.x - start.x),
                 start.y + .35 * (onCurve.y - start.y),
             ))
         onCurve.type = "curve"
     else:
         raise NotImplementedError("cannot add offCurves to %r segment" %
                                   onCurve.type)