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