Exemplo n.º 1
0
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]
Exemplo n.º 2
0
def _segments_to_quadratic(segments, max_err, stats):
    """Return quadratic approximations of cubic segments."""

    assert all(s[0] == 'curve' for s in segments), 'Non-cubic given to convert'

    new_points = curves_to_quadratic([s[1] for s in segments], max_err)
    n = len(new_points[0])
    assert all(len(s) == n for s in new_points[1:]), 'Converted incompatibly'

    spline_length = str(n - 2)
    stats[spline_length] = stats.get(spline_length, 0) + 1

    return [('qcurve', p) for p in new_points]
Exemplo n.º 3
0
def _segments_to_quadratic(segments, max_err, stats):
    """Return quadratic approximations of cubic segments."""

    assert all(s[0] == 'curve' for s in segments), 'Non-cubic given to convert'

    new_points = curves_to_quadratic([s[1] for s in segments], max_err)
    n = len(new_points[0])
    assert all(len(s) == n for s in new_points[1:]), 'Converted incompatibly'

    spline_length = str(n - 2)
    if stats is not None:
        stats[spline_length] = stats.get(spline_length, 0) + 1

    return [('qcurve', p) for p in new_points]
Exemplo n.º 4
0
Arquivo: ufo.py Projeto: UIKit0/cu2qu
def _segments_to_quadratic(segments, max_err, stats):
    """Return quadratic approximations of cubic segments."""

    assert all(s[0] == 'curve' for s in segments), 'Non-cubic given to convert'

    new_points, _ = curves_to_quadratic([s[1] for s in segments], max_err)
    n = len(new_points[0])
    assert all(len(s) == n for s in new_points[1:]), 'Converted incompatibly'

    n = str(n)
    if stats is not None:
        stats[n] = stats.get(n, 0) + 1

    return [('qcurve', p) for p in new_points]
Exemplo n.º 5
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 = []
Exemplo n.º 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 = []
Exemplo n.º 7
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 = []