diff --git a/Lib/fontTools/varLib/instancer/solver.py b/Lib/fontTools/varLib/instancer/solver.py index 665def6fe..b3746c374 100644 --- a/Lib/fontTools/varLib/instancer/solver.py +++ b/Lib/fontTools/varLib/instancer/solver.py @@ -4,6 +4,8 @@ from functools import lru_cache __all__ = ['rebaseTent'] +EPSILON = 1 / (1 << 14) + def _reverse_negate(v): return (-v[2], -v[1], -v[0]) @@ -130,6 +132,10 @@ def _solve(tent, axisLimit, negative=False): # | # crossing else: + # A tent's peak cannot fall on axis default. Nudge it. + if upper == axisDef: + upper += EPSILON + # Downslope. loc1 = (crossing, upper, axisMax) scalar1 = 0 @@ -241,6 +247,10 @@ def _solve(tent, axisLimit, negative=False): # axisDef # else: + # A tent's peak cannot fall on axis default. Nudge it. + if lower == axisDef: + lower -= EPSILON + # Downslope. loc1 = (axisMin, lower, axisDef) scalar1 = 0 @@ -252,27 +262,7 @@ def _solve(tent, axisLimit, negative=False): out.append((scalar1 - gain, loc1)) out.append((scalar2 - gain, loc2)) - - # If peak ended up being zero, nudge it to the next value - EPSILON = 1 / (1 << 14) - new_out = [] - for scalar,triple in out: - if scalar == 0: - continue - - if triple is None: - new_out.append((scalar, triple)) - continue - - lower,peak,upper = triple - if peak == axisDef: - assert not (lower == upper == axisDef) - - peak += EPSILON if lower == axisDef else -EPSILON - - new_out.append((scalar, (lower,peak,upper))) - - return new_out + return out @lru_cache(128) @@ -299,6 +289,6 @@ def rebaseTent(tent, axisLimit): sols = _solve(tent, axisLimit) n = lambda v: normalizeValue(v, axisLimit, extrapolate=True) - sols = [(scalar, (n(v[0]), n(v[1]), n(v[2])) if v is not None else None) for scalar,v in sols] + sols = [(scalar, (n(v[0]), n(v[1]), n(v[2])) if v is not None else None) for scalar,v in sols if scalar] return sols diff --git a/Tests/varLib/instancer/solver_test.py b/Tests/varLib/instancer/solver_test.py index c64c8764a..606f58712 100644 --- a/Tests/varLib/instancer/solver_test.py +++ b/Tests/varLib/instancer/solver_test.py @@ -219,9 +219,9 @@ class RebaseTentTest(object): [ (1, None), (-1, (0, 0.0001220703, 1)), - (-1, (0, 1, 1)), + (-1, (0.0001220703, 1, 1)), (-1, (-1, -0.0001220703, 0)), - (-1, (-1, -1, 0)), + (-1, (-1, -1, -0.0001220703)), ] ), ],