From 0edb0072f3939c6b8f6dab2b3efb362ff341ae5c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 7 Dec 2023 13:34:15 -0700 Subject: [PATCH] [varLib.models] Port getMasterScalars tests from Just https://github.com/fonttools/fonttools/pull/3380#issuecomment-1846051270 --- Tests/varLib/models_test.py | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/Tests/varLib/models_test.py b/Tests/varLib/models_test.py index bc8b45afd..496002c41 100644 --- a/Tests/varLib/models_test.py +++ b/Tests/varLib/models_test.py @@ -192,6 +192,17 @@ def test_modeling_error(numLocations, numSamples): # print("{:d} {:.2} {:.2}".format(i, err, err_bad)) +locationsA = [{}, {"wght": 1}, {"wdth": 1}] +locationsB = [{}, {"wght": 1}, {"wdth": 1}, {"wght": 1, "wdth": 1}] +locationsC = [ + {}, + {"wght": 0.5}, + {"wght": 1}, + {"wdth": 1}, + {"wght": 1, "wdth": 1}, +] + + class VariationModelTest(object): @pytest.mark.parametrize( "locations, axisOrder, sortedLocs, supports, deltaWeights", @@ -441,3 +452,81 @@ class VariationModelTest(object): assert interpolatedValue == expectedValue assert masterScalars == model.getMasterScalars(instanceLocation) + + @pytest.mark.parametrize( + "masterLocations, location, expected", + [ + (locationsA, {"wght": 0, "wdth": 0}, [1, 0, 0]), + ( + locationsA, + {"wght": 0.5, "wdth": 0}, + [0.5, 0.5, 0], + ), + (locationsA, {"wght": 1, "wdth": 0}, [0, 1, 0]), + ( + locationsA, + {"wght": 0, "wdth": 0.5}, + [0.5, 0, 0.5], + ), + (locationsA, {"wght": 0, "wdth": 1}, [0, 0, 1]), + (locationsA, {"wght": 1, "wdth": 1}, [-1, 1, 1]), + ( + locationsA, + {"wght": 0.5, "wdth": 0.5}, + [0, 0.5, 0.5], + ), + ( + locationsA, + {"wght": 0.75, "wdth": 0.75}, + [-0.5, 0.75, 0.75], + ), + ( + locationsB, + {"wght": 1, "wdth": 1}, + [0, 0, 0, 1], + ), + ( + locationsB, + {"wght": 0.5, "wdth": 0}, + [0.5, 0.5, 0, 0], + ), + ( + locationsB, + {"wght": 1, "wdth": 0.5}, + [0, 0.5, 0, 0.5], + ), + ( + locationsB, + {"wght": 0.5, "wdth": 0.5}, + [0.25, 0.25, 0.25, 0.25], + ), + ( + locationsC, + {"wght": 0.5, "wdth": 0}, + [0, 1, 0, 0, 0], + ), + ( + locationsC, + {"wght": 0.25, "wdth": 0}, + [0.5, 0.5, 0, 0, 0], + ), + ( + locationsC, + {"wght": 0.75, "wdth": 0}, + [0, 0.5, 0.5, 0, 0], + ), + ( + locationsC, + {"wght": 0.5, "wdth": 1}, + [-0.5, 1, -0.5, 0.5, 0.5], + ), + ( + locationsC, + {"wght": 0.75, "wdth": 1}, + [-0.25, 0.5, -0.25, 0.25, 0.75], + ), + ], + ) + def test_getMasterLocations(self, masterLocations, location, expected): + model = VariationModel(masterLocations) + assert model.getMasterScalars(location) == expected