示例#1
0
文件: pens.py 项目: anthrotype/cu2qu
 def _flushContour(self, segments):
     assert len(segments) >= 1
     closed = segments[0][0] != "move"
     new_segments = []
     prev_points = segments[-1][1]
     prev_on_curve = prev_points[-1][0]
     for segment_type, points in segments:
         if segment_type == 'curve':
             for sub_points in self._split_super_bezier_segments(points):
                 on_curve, smooth, name, kwargs = sub_points[-1]
                 bcp1, bcp2 = sub_points[0][0], sub_points[1][0]
                 cubic = [prev_on_curve, bcp1, bcp2, on_curve]
                 quad = curve_to_quadratic(cubic, self.max_err)
                 if self.stats is not None:
                     n = str(len(quad))
                     self.stats[n] = self.stats.get(n, 0) + 1
                 new_points = [(pt, False, None, {}) for pt in quad[1:-1]]
                 new_points.append((on_curve, smooth, name, kwargs))
                 new_segments.append(["qcurve", new_points])
                 prev_on_curve = sub_points[-1][0]
         else:
             new_segments.append([segment_type, points])
             prev_on_curve = points[-1][0]
     if closed:
         # the BasePointToSegmentPen.endPath method that calls _flushContour
         # rotates the point list of closed contours so that they end with
         # the first on-curve point. We restore the original starting point.
         new_segments = new_segments[-1:] + new_segments[:-1]
     self._drawPoints(new_segments)
示例#2
0
文件: pens.py 项目: anthrotype/cu2qu
 def _curve_to_quadratic(self, pt1, pt2, pt3):
     curve = (self.current_pt, pt1, pt2, pt3)
     quadratic = curve_to_quadratic(curve, self.max_err)
     if self.stats is not None:
         n = str(len(quadratic))
         self.stats[n] = self.stats.get(n, 0) + 1
     self.qCurveTo(*quadratic[1:])
示例#3
0
 def _curve_to_quadratic(self, pt1, pt2, pt3):
     curve = (self.current_pt, pt1, pt2, pt3)
     quadratic = curve_to_quadratic(curve, self.max_err)
     if self.stats is not None:
         n = str(len(quadratic))
         self.stats[n] = self.stats.get(n, 0) + 1
     self.qCurveTo(*quadratic[1:])
示例#4
0
 def _flushContour(self, segments):
     assert len(segments) >= 1
     closed = segments[0][0] != "move"
     new_segments = []
     prev_points = segments[-1][1]
     prev_on_curve = prev_points[-1][0]
     for segment_type, points in segments:
         if segment_type == 'curve':
             for sub_points in self._split_super_bezier_segments(points):
                 on_curve, smooth, name, kwargs = sub_points[-1]
                 bcp1, bcp2 = sub_points[0][0], sub_points[1][0]
                 cubic = [prev_on_curve, bcp1, bcp2, on_curve]
                 quad = curve_to_quadratic(cubic, self.max_err)
                 if self.stats is not None:
                     n = str(len(quad))
                     self.stats[n] = self.stats.get(n, 0) + 1
                 new_points = [(pt, False, None, {}) for pt in quad[1:-1]]
                 new_points.append((on_curve, smooth, name, kwargs))
                 new_segments.append(["qcurve", new_points])
                 prev_on_curve = sub_points[-1][0]
         else:
             new_segments.append([segment_type, points])
             prev_on_curve = points[-1][0]
     if closed:
         # the BasePointToSegmentPen.endPath method that calls _flushContour
         # rotates the point list of closed contours so that they end with
         # the first on-curve point. We restore the original starting point.
         new_segments = new_segments[-1:] + new_segments[:-1]
     self._drawPoints(new_segments)
示例#5
0
文件: rf.py 项目: adrientetar/cu2qu
def points_to_quadratic(p0, p1, p2, p3, max_err):
    """Return a quadratic spline approximating the cubic bezier defined by these
    points (or collections of points).
    """

    if hasattr(p0, 'x'):
        curve = [(float(i.x), float(i.y)) for i in [p0, p1, p2, p3]]
        return curve_to_quadratic(curve, max_err)[0]

    curves = [[(float(i.x), float(i.y)) for i in p] for p in zip(p0, p1, p2, p3)]
    return curves_to_quadratic(curves, max_err)[0]
示例#6
0
    def setUpClass(cls):
        """Do the curve conversion ahead of time, and run tests on results."""

        random.seed(1)
        curves = [generate_curve() for i in range(1000)]

        cls.single_splines, cls.single_errors = zip(*[
            curve_to_quadratic(c, MAX_ERR) for c in curves])

        cls.compat_splines, cls.compat_errors = zip(*[
            curves_to_quadratic(curves[i:i + 3], [MAX_ERR] * 3)
            for i in range(0, 300, 3)])

        cls.results = []
示例#7
0
    def setUpClass(cls):
        """Do the curve conversion ahead of time, and run tests on results."""

        random.seed(1)
        curves = [generate_curve() for i in range(1000)]

        cls.single_splines, cls.single_errors = zip(
            *[curve_to_quadratic(c, MAX_ERR) for c in curves])

        cls.compat_splines, cls.compat_errors = zip(*[
            curves_to_quadratic(curves[i:i + 3], [MAX_ERR] * 3)
            for i in range(0, 300, 3)
        ])

        cls.results = []
示例#8
0
    def setUpClass(cls):
        """Do the curve conversion ahead of time, and run tests on results."""
        with open(os.path.join(DATADIR, "curves.json"), "r") as fp:
            curves = json.load(fp)

        cls.single_splines = [
            curve_to_quadratic(c, MAX_ERR) for c in curves]
        cls.single_errors = [
            cls.curve_spline_dist(c, s)
            for c, s in zip(curves, cls.single_splines)]

        curve_groups = [curves[i:i + 3] for i in range(0, 300, 3)]
        cls.compat_splines = [
            curves_to_quadratic(c, [MAX_ERR] * 3) for c in curve_groups]
        cls.compat_errors = [
            [cls.curve_spline_dist(c, s) for c, s in zip(curve_group, splines)]
            for curve_group, splines in zip(curve_groups, cls.compat_splines)]

        cls.results = []