Python matplotlib.path.Path.CURVE3 Examples

The following are 30 code examples of matplotlib.path.Path.CURVE3(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.path.Path , or try the search function .
Example #1
Source File: firefox.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def svg_parse(path):
    commands = {'M': (Path.MOVETO,),
                'L': (Path.LINETO,),
                'Q': (Path.CURVE3,)*2,
                'C': (Path.CURVE4,)*3,
                'Z': (Path.CLOSEPOLY,)}
    path_re = re.compile(r'([MLHVCSQTAZ])([^MLHVCSQTAZ]+)', re.IGNORECASE)
    float_re = re.compile(r'(?:[\s,]*)([+-]?\d+(?:\.\d+)?)')
    vertices = []
    codes = []
    last = (0, 0)
    for cmd, values in path_re.findall(path):
        points = [float(v) for v in float_re.findall(values)]
        points = np.array(points).reshape((len(points)//2, 2))
        if cmd.islower():
            points += last
        cmd = cmd.capitalize()
        last = points[-1]
        codes.extend(commands[cmd])
        vertices.extend(points.tolist())
    return codes, vertices

# SVG to matplotlib 
Example #2
Source File: patches.py    From Computable with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example #3
Source File: shapes.py    From viznet with MIT License 6 votes vote down vote up
def rounded_path(vertices, roundness, close=False):
    '''make rounded path from vertices.'''
    vertices = np.asarray(vertices)
    if roundness == 0:
        vertices = vertices if not close else np.concatenate([vertices, vertices[:1]],axis=0)
        return Path(vertices, codes=[Path.MOVETO]+[Path.LINETO]*(len(vertices)-1))
    if close:
        vertices = np.concatenate([vertices, vertices[:2]], axis=0)

    codes = [Path.MOVETO]
    vertices_new = [vertices[0]]
    if close:
        cur, nex = vertices[:2]
        vertices_new[0] = cur + (nex - cur)/norm(cur-nex)*roundness
    for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
        codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
        dv_pre = (pre - cur)/norm(cur-pre)*roundness
        dv_nex = (nex - cur)/norm(cur-nex)*roundness
        vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
    if not close:
        codes.append(Path.LINETO)
        vertices_new.append(vertices[-1])
    return Path(vertices_new, codes) 
Example #4
Source File: backend_cairo.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _append_paths_slow(ctx, paths, transforms, clip=None):
    for path, transform in zip(paths, transforms):
        for points, code in path.iter_segments(
                transform, remove_nans=True, clip=clip):
            if code == Path.MOVETO:
                ctx.move_to(*points)
            elif code == Path.CLOSEPOLY:
                ctx.close_path()
            elif code == Path.LINETO:
                ctx.line_to(*points)
            elif code == Path.CURVE3:
                cur = np.asarray(ctx.get_current_point())
                a = points[:2]
                b = points[-2:]
                ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
            elif code == Path.CURVE4:
                ctx.curve_to(*points) 
Example #5
Source File: patches.py    From Computable with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example #6
Source File: backend_cairo.py    From CogAlg with MIT License 6 votes vote down vote up
def _append_path(ctx, path, transform, clip=None):
    for points, code in path.iter_segments(
            transform, remove_nans=True, clip=clip):
        if code == Path.MOVETO:
            ctx.move_to(*points)
        elif code == Path.CLOSEPOLY:
           ctx.close_path()
        elif code == Path.LINETO:
            ctx.line_to(*points)
        elif code == Path.CURVE3:
            cur = np.asarray(ctx.get_current_point())
            a = points[:2]
            b = points[-2:]
            ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
        elif code == Path.CURVE4:
            ctx.curve_to(*points) 
Example #7
Source File: brush.py    From viznet with MIT License 6 votes vote down vote up
def rounded_path(vertices, roundness):
    '''make rounded path from vertices.'''
    vertices = np.asarray(vertices)
    if roundness == 0:
        return Path(vertices)

    codes = [Path.MOVETO]
    vertices_new = [vertices[0]]
    for pre, cur, nex in zip(vertices[:-2], vertices[1:-1], vertices[2:]):
        codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
        dv_pre = (pre - cur)/norm(cur-pre)*roundness
        dv_nex = (nex - cur)/norm(cur-nex)*roundness
        vertices_new.extend([cur+dv_pre,cur,cur+dv_nex])
    codes.append(Path.LINETO)
    vertices_new.append(vertices[-1])
    return Path(vertices_new, codes) 
Example #8
Source File: patches.py    From Computable with MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example #9
Source File: drawing.py    From discopy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_wire(axis, source, target,
              bend_out=False, bend_in=False, to_tikz=False):
    """
    Draws a wire from source to target using a Bezier curve.
    """
    mid = (target[0], source[1]) if bend_out else (source[0], target[1])
    if to_tikz == "controls":
        cmd = "\\draw {} .. controls {} .. {};\n"
        axis.append(cmd.format(*("({}, {})".format(*point)
                                 for point in [source, mid, target])))
    elif to_tikz:
        out = -90 if not bend_out or source[0] == target[0]\
            else (180 if source[0] > target[0] else 0)
        inp = 90 if not bend_in or source[0] == target[0]\
            else (180 if source[0] < target[0] else 0)
        cmd = "\\draw [out={}, in={}] {{}} to {{}};\n".format(out, inp)
        axis.append(cmd.format(*("({}, {})".format(*point)
                                 for point in [source, target])))
    else:
        path = Path([source, mid, target],
                    [Path.MOVETO, Path.CURVE3, Path.CURVE3])
        axis.add_patch(PathPatch(path, facecolor='none')) 
Example #10
Source File: backend_cairo.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _append_path(ctx, path, transform, clip=None):
    for points, code in path.iter_segments(
            transform, remove_nans=True, clip=clip):
        if code == Path.MOVETO:
            ctx.move_to(*points)
        elif code == Path.CLOSEPOLY:
           ctx.close_path()
        elif code == Path.LINETO:
            ctx.line_to(*points)
        elif code == Path.CURVE3:
            cur = np.asarray(ctx.get_current_point())
            a = points[:2]
            b = points[-2:]
            ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
        elif code == Path.CURVE4:
            ctx.curve_to(*points) 
Example #11
Source File: patches.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example #12
Source File: patches.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example #13
Source File: patches.py    From ImageFusion with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example #14
Source File: patches.py    From ImageFusion with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example #15
Source File: patches.py    From neural-network-animation with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB
            x12, y12 = (x1 + x2) / 2., (y1 + y2) / 2.
            dx, dy = x2 - x1, y2 - y1

            f = self.rad

            cx, cy = x12 + f * dy, y12 - f * dx

            vertices = [(x1, y1),
                        (cx, cy),
                        (x2, y2)]
            codes = [Path.MOVETO,
                     Path.CURVE3,
                     Path.CURVE3]

            return Path(vertices, codes) 
Example #16
Source File: patches.py    From neural-network-animation with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example #17
Source File: plots.py    From nxviz with MIT License 6 votes vote down vote up
def draw_edges(self):
        """
        Renders edges to the figure.
        """
        for i, (start, end) in enumerate(self.graph.edges()):
            start_theta = node_theta(self.nodes, start)
            end_theta = node_theta(self.nodes, end)
            verts = [
                get_cartesian(self.plot_radius, start_theta),
                (0, 0),
                get_cartesian(self.plot_radius, end_theta),
            ]
            color = self.edge_colors[i]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]
            lw = self.edge_widths[i]
            path = Path(verts, codes)
            patch = patches.PathPatch(
                path, lw=lw, edgecolor=color, zorder=1, **self.edgeprops
            )
            self.ax.add_patch(patch) 
Example #18
Source File: patches.py    From neural-network-animation with MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example #19
Source File: backend_cairo.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def _append_paths_slow(ctx, paths, transforms, clip=None):
    for path, transform in zip(paths, transforms):
        for points, code in path.iter_segments(transform, clip=clip):
            if code == Path.MOVETO:
                ctx.move_to(*points)
            elif code == Path.CLOSEPOLY:
                ctx.close_path()
            elif code == Path.LINETO:
                ctx.line_to(*points)
            elif code == Path.CURVE3:
                cur = ctx.get_current_point()
                ctx.curve_to(
                    *np.concatenate([cur / 3 + points[:2] * 2 / 3,
                                     points[:2] * 2 / 3 + points[-2:] / 3]))
            elif code == Path.CURVE4:
                ctx.curve_to(*points) 
Example #20
Source File: patches.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def connect(self, posA, posB):
            x1, y1 = posA
            x2, y2 = posB

            cosA, sinA = math.cos(self.angleA / 180. * math.pi),\
                         math.sin(self.angleA / 180. * math.pi),
            cosB, sinB = math.cos(self.angleB / 180. * math.pi),\
                         math.sin(self.angleB / 180. * math.pi),

            cx, cy = get_intersection(x1, y1, cosA, sinA,
                                      x2, y2, cosB, sinB)

            vertices = [(x1, y1), (cx, cy), (x2, y2)]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]

            return Path(vertices, codes) 
Example #21
Source File: backend_cairo.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _append_paths_slow(ctx, paths, transforms, clip=None):
    for path, transform in zip(paths, transforms):
        for points, code in path.iter_segments(
                transform, remove_nans=True, clip=clip):
            if code == Path.MOVETO:
                ctx.move_to(*points)
            elif code == Path.CLOSEPOLY:
                ctx.close_path()
            elif code == Path.LINETO:
                ctx.line_to(*points)
            elif code == Path.CURVE3:
                cur = np.asarray(ctx.get_current_point())
                a = points[:2]
                b = points[-2:]
                ctx.curve_to(*(cur / 3 + a * 2 / 3), *(a * 2 / 3 + b / 3), *b)
            elif code == Path.CURVE4:
                ctx.curve_to(*points) 
Example #22
Source File: patches.py    From ImageFusion with MIT License 6 votes vote down vote up
def transmute(self, path, mutation_size, linewidth):

            x0, y0, x1, y1, x2, y2 = self.ensure_quadratic_bezier(path)

            arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
            b_plus, b_minus = make_wedged_bezier2(
                                    arrow_path,
                                    self.tail_width * mutation_size / 2.,
                                    wm=self.shrink_factor)

            patch_path = [(Path.MOVETO, b_plus[0]),
                          (Path.CURVE3, b_plus[1]),
                          (Path.CURVE3, b_plus[2]),
                          (Path.LINETO, b_minus[2]),
                          (Path.CURVE3, b_minus[1]),
                          (Path.CURVE3, b_minus[0]),
                          (Path.CLOSEPOLY, b_minus[0]),
                          ]
            path = Path([p for c, p in patch_path], [c for c, p in patch_path])

            return path, True 
Example #23
Source File: __init__.py    From beziers.py with MIT License 5 votes vote down vote up
def asMatplot(self):
    from matplotlib.path import Path
    nl = self.asNodelist()
    verts = [(nl[0].x,nl[0].y)]
    codes = [Path.MOVETO]

    for i in range(1,len(nl)):
      n = nl[i]
      verts.append((n.x,n.y))
      if n.type == "offcurve":
        if nl[i+1].type == "offcurve" or nl[i-1].type == "offcurve":
          codes.append(Path.CURVE4)
        else:
          codes.append(Path.CURVE3)
      elif n.type == "curve":
        if nl[i-1].type == "offcurve" and i >2 and nl[i-2].type == "offcurve":
          codes.append(Path.CURVE4)
        else:
          codes.append(Path.CURVE3)
      elif n.type == "line":
        codes.append(Path.LINETO)
      else:
        raise "Unknown node type"
    if self.closed:
      verts.append((nl[0].x,nl[0].y))
      codes.append(Path.CLOSEPOLY)
    return Path(verts, codes) 
Example #24
Source File: backend_wx.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def convert_path(gfx_ctx, path, transform):
        wxpath = gfx_ctx.CreatePath()
        for points, code in path.iter_segments(transform):
            if code == Path.MOVETO:
                wxpath.MoveToPoint(*points)
            elif code == Path.LINETO:
                wxpath.AddLineToPoint(*points)
            elif code == Path.CURVE3:
                wxpath.AddQuadCurveToPoint(*points)
            elif code == Path.CURVE4:
                wxpath.AddCurveToPoint(*points)
            elif code == Path.CLOSEPOLY:
                wxpath.CloseSubpath()
        return wxpath 
Example #25
Source File: backend_pgf.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _print_pgf_path(self, gc, path, transform, rgbFace=None):
        f = 1. / self.dpi
        # check for clip box / ignore clip for filled paths
        bbox = gc.get_clip_rectangle() if gc else None
        if bbox and (rgbFace is None):
            p1, p2 = bbox.get_points()
            clip = (p1[0], p1[1], p2[0], p2[1])
        else:
            clip = None
        # build path
        for points, code in path.iter_segments(transform, clip=clip):
            if code == Path.MOVETO:
                x, y = tuple(points)
                writeln(self.fh,
                        r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
                        (f * x, f * y))
            elif code == Path.CLOSEPOLY:
                writeln(self.fh, r"\pgfpathclose")
            elif code == Path.LINETO:
                x, y = tuple(points)
                writeln(self.fh,
                        r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
                        (f * x, f * y))
            elif code == Path.CURVE3:
                cx, cy, px, py = tuple(points)
                coords = cx * f, cy * f, px * f, py * f
                writeln(self.fh,
                        r"\pgfpathquadraticcurveto"
                        r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
                        % coords)
            elif code == Path.CURVE4:
                c1x, c1y, c2x, c2y, px, py = tuple(points)
                coords = c1x * f, c1y * f, c2x * f, c2y * f, px * f, py * f
                writeln(self.fh,
                        r"\pgfpathcurveto"
                        r"{\pgfqpoint{%fin}{%fin}}"
                        r"{\pgfqpoint{%fin}{%fin}}"
                        r"{\pgfqpoint{%fin}{%fin}}"
                        % coords) 
Example #26
Source File: test_simplification.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_simplify_curve():
    pp1 = patches.PathPatch(
        Path([(0, 0), (1, 0), (1, 1), (np.nan, 1), (0, 0), (2, 0), (2, 2),
              (0, 0)],
             [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3,
              Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]),
        fc="none")

    fig, ax = plt.subplots()
    ax.add_patch(pp1)
    ax.set_xlim((0, 2))
    ax.set_ylim((0, 2)) 
Example #27
Source File: plots.py    From nxviz with MIT License 5 votes vote down vote up
def draw_edges(self):
        """
        Renders edges to the figure.
        """
        for i, (start, end) in enumerate(self.graph.edges()):
            start_idx = self.nodes.index(start)
            start_x = self.node_coords["x"][start_idx]
            start_y = self.node_coords["y"][start_idx]

            end_idx = self.nodes.index(end)
            end_x = self.node_coords["x"][end_idx]
            end_y = self.node_coords["y"][end_idx]

            arc_radius = abs(end_x - start_x) / 2
            # we do min(start_x, end_x) just in case start_x is greater than
            # end_x.
            middle_x = min(start_x, end_x) + arc_radius
            middle_y = arc_radius * 2

            verts = [(start_x, start_y), (middle_x, middle_y), (end_x, end_y)]

            color = self.edge_colors[i]
            codes = [Path.MOVETO, Path.CURVE3, Path.CURVE3]
            lw = self.edge_widths[i]
            path = Path(verts, codes)
            patch = patches.PathPatch(
                path, lw=lw, edgecolor=color, zorder=1, **self.edgeprops
            )
            self.ax.add_patch(patch) 
Example #28
Source File: backend_pdf.py    From dnaplotlib with MIT License 5 votes vote down vote up
def pathOperations(path, transform, clip=None, simplify=None, sketch=None):
        cmds = []
        last_points = None
        for points, code in path.iter_segments(transform, clip=clip,
                                               simplify=simplify,
                                               sketch=sketch):
            if code == Path.MOVETO:
                # This is allowed anywhere in the path
                cmds.extend(points)
                cmds.append(Op.moveto)
            elif code == Path.CLOSEPOLY:
                cmds.append(Op.closepath)
            elif last_points is None:
                # The other operations require a previous point
                raise ValueError('Path lacks initial MOVETO')
            elif code == Path.LINETO:
                cmds.extend(points)
                cmds.append(Op.lineto)
            elif code == Path.CURVE3:
                points = quad2cubic(*(list(last_points[-2:]) + list(points)))
                cmds.extend(points[2:])
                cmds.append(Op.curveto)
            elif code == Path.CURVE4:
                cmds.extend(points)
                cmds.append(Op.curveto)
            last_points = points
        return cmds 
Example #29
Source File: backend_wx.py    From CogAlg with MIT License 5 votes vote down vote up
def convert_path(gfx_ctx, path, transform):
        wxpath = gfx_ctx.CreatePath()
        for points, code in path.iter_segments(transform):
            if code == Path.MOVETO:
                wxpath.MoveToPoint(*points)
            elif code == Path.LINETO:
                wxpath.AddLineToPoint(*points)
            elif code == Path.CURVE3:
                wxpath.AddQuadCurveToPoint(*points)
            elif code == Path.CURVE4:
                wxpath.AddCurveToPoint(*points)
            elif code == Path.CLOSEPOLY:
                wxpath.CloseSubpath()
        return wxpath 
Example #30
Source File: backend_cairo.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def convert_path(ctx, path, transform, clip=None):
        for points, code in path.iter_segments(transform, clip=clip):
            if code == Path.MOVETO:
                ctx.move_to(*points)
            elif code == Path.CLOSEPOLY:
                ctx.close_path()
            elif code == Path.LINETO:
                ctx.line_to(*points)
            elif code == Path.CURVE3:
                ctx.curve_to(points[0], points[1],
                             points[0], points[1],
                             points[2], points[3])
            elif code == Path.CURVE4:
                ctx.curve_to(*points)