Merge pull request #2765 from fonttools/revert-narrow-tents
Revert "[varLib.models] Generate narrower tents"
This commit is contained in:
commit
e25ee4b606
@ -9,7 +9,6 @@ __all__ = [
|
||||
|
||||
from fontTools.misc.roundTools import noRound
|
||||
from .errors import VariationModelError
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def nonNone(lst):
|
||||
@ -225,8 +224,13 @@ class VariationModel(object):
|
||||
{0: 1.0},
|
||||
{0: 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: 0.6666666666666667}]
|
||||
{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,
|
||||
6: 0.4444444444444445,
|
||||
7: 0.6666666666666667}]
|
||||
"""
|
||||
|
||||
def __init__(self, locations, axisOrder=None, extrapolate=False):
|
||||
@ -385,48 +389,23 @@ class VariationModel(object):
|
||||
|
||||
def _locationsToRegions(self):
|
||||
locations = self.locations
|
||||
|
||||
# Compute min/max across each axis, use it as total range.
|
||||
# TODO Take this as input from outside?
|
||||
minV = {}
|
||||
maxV = {}
|
||||
axes = set()
|
||||
for l in locations:
|
||||
for axis in l.keys():
|
||||
axes.add(axis)
|
||||
for axis in axes:
|
||||
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)
|
||||
for k, v in l.items():
|
||||
minV[k] = min(v, minV.get(k, v))
|
||||
maxV[k] = max(v, maxV.get(k, v))
|
||||
|
||||
regions = []
|
||||
for loc in locations:
|
||||
region = {}
|
||||
for axis, peak in loc.items():
|
||||
assert peak != 0
|
||||
|
||||
offAxisLoc = loc.copy()
|
||||
offAxisLoc.pop(axis)
|
||||
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)
|
||||
for axis, locV in loc.items():
|
||||
if locV > 0:
|
||||
region[axis] = (0, locV, maxV[axis])
|
||||
else:
|
||||
region[axis] = (minV[axis], locV, 0)
|
||||
regions.append(region)
|
||||
return regions
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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)}, 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(
|
||||
@ -112,8 +112,8 @@ class VariationModelTest(object):
|
||||
{"wght": (0, 0.55, 1.0)},
|
||||
{"wght": (0.55, 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.66, 1.0, 1.0), "wght": (0, 0.66, 1.0)},
|
||||
{"wdth": (0, 1.0, 1.0), "wght": (0, 1.0, 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)},
|
||||
],
|
||||
[
|
||||
@ -124,8 +124,21 @@ class VariationModelTest(object):
|
||||
{0: 1.0},
|
||||
{0: 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.75, 1.0, 1.0)},
|
||||
{"foo": (0.0, 0.25, 0.5)},
|
||||
{"foo": (0.25, 0.5, 0.75)},
|
||||
{"foo": (0.0, 0.25, 1.0)},
|
||||
{"foo": (0.25, 0.5, 1.0)},
|
||||
{"foo": (0.5, 0.75, 1.0)},
|
||||
{"foo": (0.75, 1.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, 4: 0.3333333333333333, 5: 0.5},
|
||||
{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.75, 1.0, 1.0)},
|
||||
{"foo": (0, 0.25, 0.5)},
|
||||
{"foo": (0.25, 0.5, 0.75)},
|
||||
{"foo": (0, 0.25, 1.0)},
|
||||
{"foo": (0.25, 0.5, 1.0)},
|
||||
{"foo": (0.5, 0.75, 1.0)},
|
||||
{"foo": (0.75, 1.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, 4: 0.3333333333333333, 5: 0.5},
|
||||
{0: 1.0},
|
||||
],
|
||||
),
|
||||
@ -267,3 +280,45 @@ class VariationModelTest(object):
|
||||
{"bar": 1.0, "foo": 1.0},
|
||||
]
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"locations, axisOrder, masterValues, instanceLocation, expectedValue",
|
||||
[
|
||||
(
|
||||
[
|
||||
{},
|
||||
{"axis_A": 1.0},
|
||||
{"axis_B": 1.0},
|
||||
{"axis_A": 1.0, "axis_B": 1.0},
|
||||
{"axis_A": 0.5, "axis_B": 1.0},
|
||||
{"axis_A": 1.0, "axis_B": 0.5},
|
||||
],
|
||||
["axis_A", "axis_B"],
|
||||
[
|
||||
0,
|
||||
10,
|
||||
20,
|
||||
70,
|
||||
50,
|
||||
60,
|
||||
],
|
||||
{
|
||||
"axis_A": 0.5,
|
||||
"axis_B": 0.5,
|
||||
},
|
||||
37.5,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_interpolation(
|
||||
self,
|
||||
locations,
|
||||
axisOrder,
|
||||
masterValues,
|
||||
instanceLocation,
|
||||
expectedValue,
|
||||
):
|
||||
model = VariationModel(locations, axisOrder=axisOrder)
|
||||
interpolatedValue = model.interpolateFromMasters(instanceLocation, masterValues)
|
||||
|
||||
assert interpolatedValue == expectedValue
|
||||
|
Loading…
x
Reference in New Issue
Block a user