Allow extrapolation in normalization

This commit is contained in:
Simon Cozens 2022-10-13 12:34:59 +01:00
parent 4742960f7f
commit 4d21550052

View File

@ -43,7 +43,7 @@ def subList(truth, lst):
return [l for l, t in zip(lst, truth) if t] return [l for l, t in zip(lst, truth) if t]
def normalizeValue(v, triple): def normalizeValue(v, triple, extrapolate=False):
"""Normalizes value based on a min/default/max triple. """Normalizes value based on a min/default/max triple.
>>> normalizeValue(400, (100, 400, 900)) >>> normalizeValue(400, (100, 400, 900))
@ -59,6 +59,7 @@ def normalizeValue(v, triple):
f"Invalid axis values, must be minimum, default, maximum: " f"Invalid axis values, must be minimum, default, maximum: "
f"{lower:3.3f}, {default:3.3f}, {upper:3.3f}" f"{lower:3.3f}, {default:3.3f}, {upper:3.3f}"
) )
if not extrapolate:
v = max(min(v, upper), lower) v = max(min(v, upper), lower)
if v == default: if v == default:
v = 0.0 v = 0.0
@ -69,7 +70,7 @@ def normalizeValue(v, triple):
return v return v
def normalizeLocation(location, axes): def normalizeLocation(location, axes, extrapolate=False):
"""Normalizes location based on axis min/default/max values from axes. """Normalizes location based on axis min/default/max values from axes.
>>> axes = {"wght": (100, 400, 900)} >>> axes = {"wght": (100, 400, 900)}
@ -111,7 +112,7 @@ def normalizeLocation(location, axes):
out = {} out = {}
for tag, triple in axes.items(): for tag, triple in axes.items():
v = location.get(tag, triple[1]) v = location.get(tag, triple[1])
out[tag] = normalizeValue(v, triple) out[tag] = normalizeValue(v, triple, extrapolate=extrapolate)
return out return out