25 Commits

Author SHA1 Message Date
Behdad Esfahbod
85883f09bc [varLib.models] Add getMasterScalars 2023-12-07 12:29:00 -07:00
Cosimo Lupo
1dea06f66f
add tests for normalizeLocation(extrapolate=True)
These fails at the moment with various division-by-zero errors, fix in follow-up commit.
2022-10-13 18:35:45 +01:00
Just van Rossum
8b8fbf390e formatting 2022-10-13 12:56:04 +02:00
Just van Rossum
2afac999ef Add test for VariationModel with extrapolate=True, and test a two-dimensional designspace for expected interpolation values 2022-10-13 12:50:21 +02:00
Just van Rossum
b073fb8f6f Demand axisRanges is given when extrapolate is True 2022-10-13 12:27:46 +02:00
Just van Rossum
16183b9436 Adjust extrapolate test cases, and added some for extrapolating below the minimum 2022-10-13 09:03:42 +02:00
Behdad Esfahbod
f0f7b93f11 [varLib.models_test] Add test
from https://github.com/fonttools/fonttools/issues/2764
2022-08-23 10:32:57 -06:00
Cosimo Lupo
f5933c1cfa Revert "[varLib.models] Generate narrower tents"
This reverts commit 688939394b8cae3b2a0d5747e435cbd828a14531.
2022-08-23 17:20:57 +01:00
Behdad Esfahbod
bad70c68ef [varLib] Support extrapolation
Fixes https://github.com/fonttools/fonttools/issues/1252
2022-08-23 09:56:33 -06:00
Behdad Esfahbod
32904d43bb [models_test] Add tests from Just 2022-08-16 12:46:44 -06:00
Behdad Esfahbod
3325b47606
Merge pull request #2717 from fonttools/varLib-narrow
[varLib.models] Generate narrower tents
2022-08-16 12:46:22 -06:00
Behdad Esfahbod
03d264756b
Test var model error (#2217)
* [varLib.models] Add test for modeling rounding error

Tests https://github.com/fonttools/fonttools/pull/2214

If you flip demo to True, it does a slower test and demos the new error as well
as the error the old code was producing (ie. rounding deltas post-modeling).

Indeed, the new error is always capped by 0.5 as expected, whereas the old one
was unbounded. Here's the worst-case error of the bad code:

...
240     0.42    4.8
...

240 is just the line number. 0.42 is new error. 4.8 is old error.

* turn test_modeling_error into a parametrized pytest test

Like the other test methods in the same module, all those whose name starts with 'test_' are automatically discovered and run by pytest which is our default test runner. So there is no need to call the test method itself in the top-level module scope. One simply runs the test via pytest. To execute this specific test method one can do 'pytest Tests/varLib/models_test.py::test_modeling_error'.

* use pytest markers to mark specific test as 'slow'

So that one can optionally deselect tests marked with specific marker by passing -m option (e.g. to deselect 'slow' tests, pytest -m 'not slow' ...).

https://docs.pytest.org/en/stable/mark.html#registering-marks
https://docs.pytest.org/en/stable/example/parametrize.html#set-marks-or-test-id-for-individual-parametrized-test

* [varLib/models_test] Comment out non-test code

Co-authored-by: Cosimo Lupo <clupo@google.com>
2022-08-15 10:30:45 -06:00
Behdad Esfahbod
688939394b [varLib.models] Generate narrower tents
Based on https://github.com/fonttools/fonttools/pull/2218
but modify the general solver instead.
2022-08-14 14:00:09 -06:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
Nikolaus Waxweiler
5a53d1d4ad models: Use new exceptions where input is checked 2020-02-13 15:01:52 +00:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Cosimo Lupo
c813b65d32 models_test: test default 0.0 input locations are omitted internally 2019-03-04 12:38:32 -08:00
Cosimo Lupo
0811834b3c models_test: VariationModel input locations should be in normalized space
not only base should be at 0, but min/max respectively at -1.0 and +1.0.
that's how varLib constructs models internally, so update test case to reflect that
2019-03-04 12:31:08 -08:00
Cosimo Lupo
05824b8616 VariationModel: assert that locations are unique 2019-03-04 11:42:54 -08:00
Cosimo Lupo
b9aa815d06 models_test: bundle test methods under VariationModelTest class
in preparation for adding more unit tests to VariationModel class.
2019-03-04 11:03:34 -08:00
Cosimo Lupo
7e85782900 models_test: parametrize VariationModel tests
I noticed there were two functions called 'test_VariationModel', the second one
shadowing the first.
2019-03-04 11:00:11 -08:00
Behdad Esfahbod
1801248938 [varLib.models] Fix model resolution
Oops.  Was introduced when I last changed modeling.

The problem was, for checking that a previous master m is outside the current
influence box of the current master, I was doing "not (lower < m[loc] < upper)".
This is wrong, where lower,peak,upper is the support of previous master.
This fails if lower == peak == m[loc], or m[loc] == peak == upper.

Fixes https://github.com/fonttools/fonttools/issues/1269#issuecomment-397655016
2018-06-16 14:07:18 -04:00
Behdad Esfahbod
42bef176a3 [varLib] Tweak support-resolution algorithm
Improve varLib model algorithm.

This, basically means any varfont built that had an unusual master
configuration will change when rebuilt.

Here's a good test: a two-axis with 8 masters at unusual locations:

2-----------------5----------3
|                            |
|                    7       |
|                            |
|              6             |
|                            |
|                            |
|                            |
0-----------4----------------1

Previously, the reach of master 3 (Black Extended) would
have started from A=.4, ie, the A position of master 4.
It now correctly starts from 0. Same thing with masters
after it. Ie, master 5 gets a span on the A axis from
0 to 1, whereas before it was getting from .4 to 1.

Previously, the on-axis masters always cut the space. They
don't anymore. That's more consistent, and fixes the main
issue Erik showed at TYPO Labs 2017.  Same issue was also
causing the reach of master 3 to be limited, which I think
is the issue being discussed in the linked issue. Both should
be fixed.

It's hard to describe exactly what happened before / after.
Best to read the actual support values:

Before:
Sorted locations:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
[{},
 {'A': 0.4},
 {'A': 1.0},
 {'B': 1.0},
 {'A': 1.0, 'B': 1.0},
 {'A': 0.6, 'B': 1.0},
 {'A': 0.5, 'B': 0.5},
 {'A': 0.7, 'B': 0.7}]
Supports:
[{},
 {'A': (0.0, 0.4, 1.0)},
 {'A': (0.4, 1.0, 1.0)},
 {'B': (0.0, 1.0, 1.0)},
 {'A': (0.4, 1.0, 1.0), 'B': (0.0, 1.0, 1.0)},
 {'A': (0.4, 0.6, 1.0), 'B': (0.0, 1.0, 1.0)},
 {'A': (0.4, 0.5, 1.0), 'B': (0.0, 0.5, 1.0)},
 {'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]

After:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
Sorted locations:
[{},
 {'A': 0.4},
 {'A': 1.0},
 {'B': 1.0},
 {'A': 1.0, 'B': 1.0},
 {'A': 0.6, 'B': 1.0},
 {'A': 0.5, 'B': 0.5},
 {'A': 0.7, 'B': 0.7}]
Supports:
[{},
 {'A': (0, 0.4, 1.0)},
 {'A': (0.4, 1.0, 1.0)},
 {'B': (0, 1.0, 1.0)},
 {'A': (0, 1.0, 1.0), 'B': (0, 1.0, 1.0)},
 {'A': (0, 0.6, 1.0), 'B': (0, 1.0, 1.0)},
 {'A': (0, 0.5, 1.0), 'B': (0, 0.5, 1.0)},
 {'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]

TODO: We should add this as a test case.

There's another improvement I want to make, but that's separate.
2018-03-26 20:32:27 -07:00
Behdad Esfahbod
968c25dd7f [varLib] Generate avar table
Fixes https://github.com/fonttools/fonttools/issues/916
2017-04-12 21:54:43 -07:00
Cosimo Lupo
a79bb0fa01
[Tests] convert varLib/models.py doctests into models_test.py 2017-01-17 13:39:38 +00:00