Revert "[varLib.models] Generate narrower tents"

This reverts commit 688939394b8cae3b2a0d5747e435cbd828a14531.
This commit is contained in:
Cosimo Lupo 2022-08-23 17:15:37 +01:00
parent 5284ac3c58
commit f5933c1cfa
3 changed files with 478 additions and 486 deletions

View File

@ -9,7 +9,6 @@ __all__ = [
from fontTools.misc.roundTools import noRound from fontTools.misc.roundTools import noRound
from .errors import VariationModelError from .errors import VariationModelError
from collections import defaultdict
def nonNone(lst): def nonNone(lst):
@ -225,8 +224,13 @@ class VariationModel(object):
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0},
{0: 1.0, 4: 1.0, 5: 1.0}, {0: 1.0, 4: 1.0, 5: 1.0},
{0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0}, {0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0, 6: 0.6666666666666666},
{0: 1.0, 3: 0.75, 4: 0.25, 5: 0.6666666666666667}] {0: 1.0,
3: 0.75,
4: 0.25,
5: 0.6666666666666667,
6: 0.4444444444444445,
7: 0.6666666666666667}]
""" """
def __init__(self, locations, axisOrder=None, extrapolate=False): def __init__(self, locations, axisOrder=None, extrapolate=False):
@ -385,48 +389,23 @@ class VariationModel(object):
def _locationsToRegions(self): def _locationsToRegions(self):
locations = self.locations locations = self.locations
# Compute min/max across each axis, use it as total range. # Compute min/max across each axis, use it as total range.
# TODO Take this as input from outside?
minV = {} minV = {}
maxV = {} maxV = {}
axes = set()
for l in locations: for l in locations:
for axis in l.keys(): for k, v in l.items():
axes.add(axis) minV[k] = min(v, minV.get(k, v))
for axis in axes: maxV[k] = max(v, maxV.get(k, v))
minV[axis] = 0.0
maxV[axis] = 0.0
for l in locations:
for axis, v in l.items():
minV[axis] = min(v, minV.get(axis, v))
maxV[axis] = max(v, maxV.get(axis, v))
axisPoints = defaultdict(lambda: defaultdict(lambda: {0.0}))
for loc in locations:
for axis, value in loc.items():
offAxisLoc = loc.copy()
offAxisLoc.pop(axis)
offAxisLoc = tuple(sorted(offAxisLoc.items()))
axisPoints[axis][offAxisLoc].add(value)
regions = [] regions = []
for loc in locations: for loc in locations:
region = {} region = {}
for axis, peak in loc.items(): for axis, locV in loc.items():
assert peak != 0 if locV > 0:
region[axis] = (0, locV, maxV[axis])
offAxisLoc = loc.copy() else:
offAxisLoc.pop(axis) region[axis] = (minV[axis], locV, 0)
offAxisLoc = tuple(sorted(offAxisLoc.items()))
points = axisPoints[axis][offAxisLoc]
points.add(minV[axis])
points.add(maxV[axis])
points = sorted(points)
peakIndex = points.index(peak)
lower = peak if peakIndex == 0 else points[peakIndex - 1]
upper = peak if peakIndex == len(points) - 1 else points[peakIndex + 1]
region[axis] = (lower, peak, upper)
regions.append(region) regions.append(region)
return regions return regions

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@ def test_supportScalar():
assert supportScalar({"wght": 4}, {"wght": (0, 2, 2)}) == 0.0 assert supportScalar({"wght": 4}, {"wght": (0, 2, 2)}) == 0.0
assert supportScalar({"wght": 4}, {"wght": (0, 2, 2)}, extrapolate=True) == 2.0 assert supportScalar({"wght": 4}, {"wght": (0, 2, 2)}, extrapolate=True) == 2.0
assert supportScalar({"wght": 4}, {"wght": (0, 2, 3)}, extrapolate=True) == 2.0 assert supportScalar({"wght": 4}, {"wght": (0, 2, 3)}, extrapolate=True) == 2.0
assert supportScalar({"wght": 2}, {"wght": (0, .75, 1)}, extrapolate=True) == -4.0 assert supportScalar({"wght": 2}, {"wght": (0, 0.75, 1)}, extrapolate=True) == -4.0
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -112,8 +112,8 @@ class VariationModelTest(object):
{"wght": (0, 0.55, 1.0)}, {"wght": (0, 0.55, 1.0)},
{"wght": (0.55, 1.0, 1.0)}, {"wght": (0.55, 1.0, 1.0)},
{"wdth": (0, 1.0, 1.0)}, {"wdth": (0, 1.0, 1.0)},
{"wdth": (0, 1.0, 1.0), "wght": (0.66, 1.0, 1.0)}, {"wdth": (0, 1.0, 1.0), "wght": (0, 1.0, 1.0)},
{"wdth": (0.66, 1.0, 1.0), "wght": (0, 0.66, 1.0)}, {"wdth": (0, 1.0, 1.0), "wght": (0, 0.66, 1.0)},
{"wdth": (0, 0.66, 1.0), "wght": (0, 0.66, 1.0)}, {"wdth": (0, 0.66, 1.0), "wght": (0, 0.66, 1.0)},
], ],
[ [
@ -124,8 +124,21 @@ class VariationModelTest(object):
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0},
{0: 1.0, 4: 1.0, 5: 1.0}, {0: 1.0, 4: 1.0, 5: 1.0},
{0: 1.0, 3: 0.7555555555555555, 4: 0.24444444444444444, 5: 1.0}, {
{0: 1.0, 3: 0.7555555555555555, 4: 0.24444444444444444, 5: 0.66}, 0: 1.0,
3: 0.7555555555555555,
4: 0.24444444444444444,
5: 1.0,
6: 0.66,
},
{
0: 1.0,
3: 0.7555555555555555,
4: 0.24444444444444444,
5: 0.66,
6: 0.43560000000000004,
7: 0.66,
},
], ],
), ),
( (
@ -187,22 +200,22 @@ class VariationModelTest(object):
], ],
[ [
{}, {},
{"bar": (0.0, 0.25, 0.75)}, {"bar": (0.0, 0.25, 1.0)},
{"bar": (0.25, 0.75, 1.0)}, {"bar": (0.25, 0.75, 1.0)},
{"bar": (0.75, 1.0, 1.0)}, {"bar": (0.75, 1.0, 1.0)},
{"foo": (0.0, 0.25, 0.5)}, {"foo": (0.0, 0.25, 1.0)},
{"foo": (0.25, 0.5, 0.75)}, {"foo": (0.25, 0.5, 1.0)},
{"foo": (0.5, 0.75, 1.0)}, {"foo": (0.5, 0.75, 1.0)},
{"foo": (0.75, 1.0, 1.0)}, {"foo": (0.75, 1.0, 1.0)},
], ],
[ [
{}, {},
{0: 1.0}, {0: 1.0},
{0: 1.0, 1: 0.3333333333333333},
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0, 4: 0.6666666666666666},
{0: 1.0}, {0: 1.0, 4: 0.3333333333333333, 5: 0.5},
{0: 1.0},
{0: 1.0}, {0: 1.0},
], ],
), ),
@ -230,22 +243,22 @@ class VariationModelTest(object):
], ],
[ [
{}, {},
{"bar": (0, 0.25, 0.75)}, {"bar": (0, 0.25, 1.0)},
{"bar": (0.25, 0.75, 1.0)}, {"bar": (0.25, 0.75, 1.0)},
{"bar": (0.75, 1.0, 1.0)}, {"bar": (0.75, 1.0, 1.0)},
{"foo": (0, 0.25, 0.5)}, {"foo": (0, 0.25, 1.0)},
{"foo": (0.25, 0.5, 0.75)}, {"foo": (0.25, 0.5, 1.0)},
{"foo": (0.5, 0.75, 1.0)}, {"foo": (0.5, 0.75, 1.0)},
{"foo": (0.75, 1.0, 1.0)}, {"foo": (0.75, 1.0, 1.0)},
], ],
[ [
{}, {},
{0: 1.0}, {0: 1.0},
{0: 1.0, 1: 0.3333333333333333},
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0},
{0: 1.0}, {0: 1.0, 4: 0.6666666666666666},
{0: 1.0}, {0: 1.0, 4: 0.3333333333333333, 5: 0.5},
{0: 1.0},
{0: 1.0}, {0: 1.0},
], ],
), ),