Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variationModel.interpolateFromMasters doesn't extrapolate as expected #2843

Closed
LettError opened this issue Oct 11, 2022 · 6 comments
Closed
Assignees

Comments

@LettError
Copy link
Collaborator

With extrapolate=True there is an issue withvariationModel.interpolateFromMasters as it clips results in 2 value models. Results are as expected in 3 value models.

from fontTools.varLib.models import VariationModel

# extrapolate under and over a 3 value system
locations = [
    dict(wght=-1),
    dict(wght=0),
    dict(wght=1),    
]

values = [30, 40, 50]

m = VariationModel(locations, extrapolate=True)
assert m.interpolateFromMasters(dict(wght=-1.5), values) == 25
assert m.interpolateFromMasters(dict(wght=-1), values) == 30
assert m.interpolateFromMasters(dict(wght=0), values) == 40
assert m.interpolateFromMasters(dict(wght=0.5), values) == 45
assert m.interpolateFromMasters(dict(wght=1), values) == 50
assert m.interpolateFromMasters(dict(wght=1.5), values) == 55


# extrapolate under and over a 2 value system
locations = [
    dict(wght=0),
    dict(wght=1),    
]

values = [40, 50]

m = VariationModel(locations, extrapolate=True)

# values under 0 are clipped.
print(m.interpolateFromMasters(dict(wght=-1), values))
print(m.interpolateFromMasters(dict(wght=-2), values))
print(m.interpolateFromMasters(dict(wght=-3), values))

#> 40.0
#> 40.0
#> 40.0

# this one fails
#assert m.interpolateFromMasters(dict(wght=-1), values) == 30

# the rest works as expected
assert m.interpolateFromMasters(dict(wght=0), values) == 40
assert m.interpolateFromMasters(dict(wght=0.5), values) == 45
assert m.interpolateFromMasters(dict(wght=1), values) == 50
assert m.interpolateFromMasters(dict(wght=1.5), values) == 55
@anthrotype
Copy link
Member

at least it appears to be intentional e.g. see the docstring of VariationModel (emphasis mine)

5284ac3

If the extrapolate argument is set to True, then location values are
interpretted [sic] in the normalized space, ie. in the [-1,+1] range, and
values are extrapolated outside this range.

I'm sure @behdad can clarify that.

@behdad
Copy link
Member

behdad commented Oct 11, 2022

What @anthrotype said. Current extrapolation implementation extrapolations the values at -1 and +1.

@LettError
Copy link
Collaborator Author

Would it be possible to express the hope it would eventually also work for values between [0,1]?

@behdad
Copy link
Member

behdad commented Oct 11, 2022

I have to check the code. I think it's possible, yes. In that case it wouldn't need any specific range and would adapt to the min/max specified.

@behdad behdad self-assigned this Oct 11, 2022
@behdad
Copy link
Member

behdad commented Oct 11, 2022

This is trivial for one axis, less so for more axes.

@LettError
Copy link
Collaborator Author

LettError commented Oct 11, 2022

True. In MutatorMath that was a bit of work (lines starting here). This is too specific and can't be re-used for varlib. But I imagine it will be similar enough: a couple of different cases that need to be calculated separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants