[varLib.models] Simplify based on review

This commit is contained in:
Behdad Esfahbod 2023-12-12 04:39:05 -07:00
parent 86b2bf62e6
commit 36e2c6dcd3
3 changed files with 16 additions and 16 deletions

View File

@ -1069,7 +1069,7 @@ def merge(merger, self, lst):
model = merger.model model = merger.model
masterScalars = merger.masterScalars masterScalars = merger.masterScalars
self.Coordinate = otRound( self.Coordinate = otRound(
model.interpolateFromMastersAndMasterScalars(Coords, masterScalars) model.interpolateFromValuesAndScalars(Coords, masterScalars)
) )
@ -1081,10 +1081,10 @@ def merge(merger, self, lst):
model = merger.model model = merger.model
masterScalars = merger.masterScalars masterScalars = merger.masterScalars
self.XCoordinate = otRound( self.XCoordinate = otRound(
model.interpolateFromMastersAndMasterScalars(XCoords, masterScalars) model.interpolateFromValuesAndScalars(XCoords, masterScalars)
) )
self.YCoordinate = otRound( self.YCoordinate = otRound(
model.interpolateFromMastersAndMasterScalars(YCoords, masterScalars) model.interpolateFromValuesAndScalars(YCoords, masterScalars)
) )
@ -1104,7 +1104,7 @@ def merge(merger, self, lst):
if hasattr(self, name): if hasattr(self, name):
values = [getattr(a, name, 0) for a in lst] values = [getattr(a, name, 0) for a in lst]
value = otRound( value = otRound(
model.interpolateFromMastersAndMasterScalars(values, masterScalars) model.interpolateFromValuesAndScalars(values, masterScalars)
) )
setattr(self, name, value) setattr(self, name, value)

View File

@ -486,7 +486,7 @@ class VariationModel(object):
"""Return multipliers for each master, for the given location. """Return multipliers for each master, for the given location.
If interpolating many master-values at the same location, If interpolating many master-values at the same location,
this function allows speed up by fetching the scalars once this function allows speed up by fetching the scalars once
and using them with interpolateFromMastersAndMasterScalars(). and using them with interpolateFromValuesAndScalars().
Note that the scalars used in interpolateFromMastersAndScalars(), Note that the scalars used in interpolateFromMastersAndScalars(),
are *not* the same as the ones returned here. They are the result are *not* the same as the ones returned here. They are the result
@ -501,7 +501,15 @@ class VariationModel(object):
@staticmethod @staticmethod
def interpolateFromValuesAndScalars(values, scalars): def interpolateFromValuesAndScalars(values, scalars):
"""Interpolate from values and scalars coefficients.""" """Interpolate from values and scalars coefficients.
If the values are master-values, then the scalars should be
fetched from getMasterScalars().
If the values are deltas, then the scalars should be fetched
from getScalars(); in which case this is the same as
interpolateFromDeltasAndScalars().
"""
v = None v = None
assert len(values) == len(scalars) assert len(values) == len(scalars)
for value, scalar in zip(values, scalars): for value, scalar in zip(values, scalars):
@ -527,7 +535,7 @@ class VariationModel(object):
def interpolateFromMasters(self, loc, masterValues, *, round=noRound): def interpolateFromMasters(self, loc, masterValues, *, round=noRound):
"""Interpolate from master-values, at location loc.""" """Interpolate from master-values, at location loc."""
scalars = self.getMasterScalars(loc) scalars = self.getMasterScalars(loc)
return self.interpolateFromMastersAndMasterScalars(masterValues, scalars) return self.interpolateFromValuesAndScalars(masterValues, scalars)
def interpolateFromMastersAndScalars(self, masterValues, scalars, *, round=noRound): def interpolateFromMastersAndScalars(self, masterValues, scalars, *, round=noRound):
"""Interpolate from master-values, and scalars fetched from """Interpolate from master-values, and scalars fetched from
@ -536,14 +544,6 @@ class VariationModel(object):
deltas = self.getDeltas(masterValues, round=round) deltas = self.getDeltas(masterValues, round=round)
return self.interpolateFromDeltasAndScalars(deltas, scalars) return self.interpolateFromDeltasAndScalars(deltas, scalars)
@staticmethod
def interpolateFromMastersAndMasterScalars(masterValues, masterScalars):
"""Interpolate from master-values and master-scalars fetched
from getMasterScalars()."""
return VariationModel.interpolateFromValuesAndScalars(
masterValues, masterScalars
)
def piecewiseLinearMap(v, mapping): def piecewiseLinearMap(v, mapping):
keys = mapping.keys() keys = mapping.keys()

View File

@ -453,7 +453,7 @@ class VariationModelTest(object):
assert masterScalars == model.getMasterScalars(instanceLocation) assert masterScalars == model.getMasterScalars(instanceLocation)
assert model.interpolateFromMastersAndMasterScalars( assert model.interpolateFromValuesAndScalars(
masterValues, masterScalars masterValues, masterScalars
) == pytest.approx(interpolatedValue) ) == pytest.approx(interpolatedValue)