[interpolatable] Add --tolerance
This commit is contained in:
parent
9612d67f80
commit
60aaa35000
@ -13,6 +13,7 @@ from fontTools.pens.statisticsPen import StatisticsPen
|
||||
from fontTools.pens.momentsPen import OpenContourError
|
||||
from fontTools.varLib.models import piecewiseLinearMap
|
||||
from collections import defaultdict
|
||||
from functools import wraps
|
||||
import math
|
||||
import itertools
|
||||
import sys
|
||||
@ -150,7 +151,9 @@ except ImportError:
|
||||
)
|
||||
|
||||
|
||||
def test_gen(glyphsets, glyphs=None, names=None, ignore_missing=False):
|
||||
def test_gen(
|
||||
glyphsets, glyphs=None, names=None, ignore_missing=False, *, tolerance=0.95
|
||||
):
|
||||
if names is None:
|
||||
names = glyphsets
|
||||
if glyphs is None:
|
||||
@ -330,7 +333,7 @@ def test_gen(glyphsets, glyphs=None, names=None, ignore_missing=False):
|
||||
identity_cost = sum(costs[i][i] for i in range(len(m0)))
|
||||
if (
|
||||
matching != identity_matching
|
||||
and matching_cost < identity_cost * 0.95
|
||||
and matching_cost < identity_cost * tolerance
|
||||
):
|
||||
yield (
|
||||
glyph_name,
|
||||
@ -364,7 +367,7 @@ def test_gen(glyphsets, glyphs=None, names=None, ignore_missing=False):
|
||||
costs = [_vdiff_hypot2_complex(c0, c1) for c1 in contour1]
|
||||
min_cost = min(costs)
|
||||
first_cost = costs[0]
|
||||
if min_cost < first_cost * 0.95:
|
||||
if min_cost < first_cost * tolerance:
|
||||
yield (
|
||||
glyph_name,
|
||||
{
|
||||
@ -382,9 +385,10 @@ def test_gen(glyphsets, glyphs=None, names=None, ignore_missing=False):
|
||||
)
|
||||
|
||||
|
||||
def test(glyphsets, glyphs=None, names=None, ignore_missing=False):
|
||||
@wraps(test_gen)
|
||||
def test(*args, **kwargs):
|
||||
problems = defaultdict(list)
|
||||
for glyphname, problem in test_gen(glyphsets, glyphs, names, ignore_missing):
|
||||
for glyphname, problem in test_gen(*args, **kwargs):
|
||||
problems[glyphname].append(problem)
|
||||
return problems
|
||||
|
||||
@ -411,6 +415,12 @@ def main(args=None):
|
||||
action="store",
|
||||
help="Space-separate name of glyphs to check",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--tolerance",
|
||||
action="store",
|
||||
type=float,
|
||||
help="Error tolerance. Default 0.95",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--json",
|
||||
action="store_true",
|
||||
@ -567,7 +577,11 @@ def main(args=None):
|
||||
|
||||
log.info("Running on %d glyphsets", len(glyphsets))
|
||||
problems_gen = test_gen(
|
||||
glyphsets, glyphs=glyphs, names=names, ignore_missing=args.ignore_missing
|
||||
glyphsets,
|
||||
glyphs=glyphs,
|
||||
names=names,
|
||||
ignore_missing=args.ignore_missing,
|
||||
tolerance=args.tolerance or 0.95,
|
||||
)
|
||||
problems = defaultdict(list)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user