Swap order of "max_err" and "max_n" parameters

I like this new order better, since max_err seems to be the more
important parameter, and it corresponds more closely with the actual
font object params (which can be lists) than max_n (which is always
a single value).
This commit is contained in:
jamesgk 2015-11-20 12:06:18 -08:00
parent e94071a2d8
commit 79ea6b4973
2 changed files with 10 additions and 10 deletions

View File

@ -136,7 +136,7 @@ def curve_spline_dist(bezier, spline):
return error
def curve_to_quadratic(p, max_n, max_err):
def curve_to_quadratic(p, max_err, max_n):
"""Return a quadratic spline approximating this cubic bezier."""
for n in range(1, max_n + 1):
@ -146,7 +146,7 @@ def curve_to_quadratic(p, max_n, max_err):
return spline
def curves_to_quadratic(curves, max_n, max_errors):
def curves_to_quadratic(curves, max_errors, max_n):
"""Return quadratic splines approximating these cubic beziers."""
for n in range(1, max_n + 1):

View File

@ -52,7 +52,7 @@ def fonts_to_quadratic(*fonts, **kwargs):
report = {}
for glyph in FontCollection(fonts):
glyph_to_quadratic(glyph, max_n, max_errors, report)
glyph_to_quadratic(glyph, max_errors, max_n, report)
spline_lengths = report.keys()
spline_lengths.sort()
@ -61,7 +61,7 @@ def fonts_to_quadratic(*fonts, **kwargs):
'\n'.join('%s: %d' % (l, report[l]) for l in spline_lengths))
def glyph_to_quadratic(glyph, max_n, max_err, report):
def glyph_to_quadratic(glyph, max_err, max_n, report):
"""Convert a glyph's curves to quadratic, in place."""
for contour in glyph:
@ -70,13 +70,13 @@ def glyph_to_quadratic(glyph, max_n, max_err, report):
segment = contour[i]
if segment.type == 'curve':
segments.append(segment_to_quadratic(
contour, i, max_n, max_err, report))
contour, i, max_err, max_n, report))
else:
segments.append(segment)
replace_segments(contour, segments)
def segment_to_quadratic(contour, segment_id, max_n, max_err, report):
def segment_to_quadratic(contour, segment_id, max_err, max_n, report):
"""Return a quadratic approximation of a cubic segment."""
segment = contour[segment_id]
@ -88,7 +88,7 @@ def segment_to_quadratic(contour, segment_id, max_n, max_err, report):
prev_segment = contour[segment_id - 1]
points = points_to_quadratic(prev_segment.points[-1], segment.points[0],
segment.points[1], segment.points[2],
max_n, max_err)
max_err, max_n)
if isinstance(points[0][0], float): # just one spline
n = str(len(points))
@ -102,17 +102,17 @@ def segment_to_quadratic(contour, segment_id, max_n, max_err, report):
return as_quadratic(segment, points)
def points_to_quadratic(p0, p1, p2, p3, max_n, max_err):
def points_to_quadratic(p0, p1, p2, p3, max_err, max_n):
"""Return a quadratic spline approximating the cubic bezier defined by these
points (or collections of points).
"""
if hasattr(p0, 'x'):
curve = [Point([i.x, i.y]) for i in [p0, p1, p2, p3]]
return curve_to_quadratic(curve, max_n, max_err)
return curve_to_quadratic(curve, max_err, max_n)
curves = [[Point([i.x, i.y]) for i in p] for p in zip(p0, p1, p2, p3)]
return curves_to_quadratic(curves, max_n, max_err)
return curves_to_quadratic(curves, max_err, max_n)
def replace_segments(contour, segments):