[instancer] Merge pinTupleVariationAxes and limitTupleVariationAxisRanges
This commit is contained in:
parent
a8943d99c9
commit
7856a5cc46
@ -184,17 +184,8 @@ def instantiateTupleVariationStore(
|
|||||||
Returns:
|
Returns:
|
||||||
List[float]: the overall delta adjustment after applicable deltas were summed.
|
List[float]: the overall delta adjustment after applicable deltas were summed.
|
||||||
"""
|
"""
|
||||||
pinnedLocation, axisRanges = splitAxisLocationAndRanges(
|
|
||||||
axisLimits, rangeType=NormalizedAxisRange
|
|
||||||
)
|
|
||||||
|
|
||||||
newVariations = variations
|
newVariations = changeTupleVariationsAxisLimits(variations, axisLimits)
|
||||||
|
|
||||||
if pinnedLocation:
|
|
||||||
newVariations = pinTupleVariationAxes(variations, pinnedLocation)
|
|
||||||
|
|
||||||
if axisRanges:
|
|
||||||
newVariations = limitTupleVariationAxisRanges(newVariations, axisRanges)
|
|
||||||
|
|
||||||
mergedVariations = collections.OrderedDict()
|
mergedVariations = collections.OrderedDict()
|
||||||
for var in newVariations:
|
for var in newVariations:
|
||||||
@ -220,29 +211,11 @@ def instantiateTupleVariationStore(
|
|||||||
return defaultVar.coordinates if defaultVar is not None else []
|
return defaultVar.coordinates if defaultVar is not None else []
|
||||||
|
|
||||||
|
|
||||||
def pinTupleVariationAxes(variations, location):
|
def changeTupleVariationsAxisLimits(variations, axisLimits):
|
||||||
|
for axisTag, axisLimit in sorted(axisLimits.items()):
|
||||||
newVariations = []
|
newVariations = []
|
||||||
for var in variations:
|
for var in variations:
|
||||||
# Compute the scalar support of the axes to be pinned at the desired location,
|
newVariations.extend(changeTupleVariationAxisLimit(var, axisTag, axisLimit))
|
||||||
# excluding any axes that we are not pinning.
|
|
||||||
# If a TupleVariation doesn't mention an axis, it implies that the axis peak
|
|
||||||
# is 0 (i.e. the axis does not participate).
|
|
||||||
support = {axis: var.axes.pop(axis, (-1, 0, +1)) for axis in location}
|
|
||||||
scalar = supportScalar(location, support)
|
|
||||||
if scalar == 0.0:
|
|
||||||
# no influence, drop the TupleVariation
|
|
||||||
continue
|
|
||||||
if scalar != 1.0:
|
|
||||||
var.scaleDeltas(scalar)
|
|
||||||
newVariations.append(var)
|
|
||||||
return newVariations
|
|
||||||
|
|
||||||
|
|
||||||
def limitTupleVariationAxisRanges(variations, axisRanges):
|
|
||||||
for axisTag, axisRange in sorted(axisRanges.items()):
|
|
||||||
newVariations = []
|
|
||||||
for var in variations:
|
|
||||||
newVariations.extend(limitTupleVariationAxisRange(var, axisTag, axisRange))
|
|
||||||
variations = newVariations
|
variations = newVariations
|
||||||
return variations
|
return variations
|
||||||
|
|
||||||
@ -251,28 +224,39 @@ def _negate(*values):
|
|||||||
yield from (-1 * v for v in values)
|
yield from (-1 * v for v in values)
|
||||||
|
|
||||||
|
|
||||||
def limitTupleVariationAxisRange(var, axisTag, axisRange):
|
def changeTupleVariationAxisLimit(var, axisTag, axisLimit):
|
||||||
assert isinstance(axisRange, NormalizedAxisRange)
|
assert isinstance(axisLimit, NormalizedAxisTent)
|
||||||
|
|
||||||
|
# if axis is fully pinned down, get it out of the way
|
||||||
|
if axisLimit.minimum == axisLimit.maximum:
|
||||||
|
support = {axisTag: var.axes.pop(axisTag, (-1, 0, 1))}
|
||||||
|
scalar = supportScalar({axisTag: axisLimit.default}, support)
|
||||||
|
if scalar == 0.0:
|
||||||
|
return []
|
||||||
|
if scalar != 1.0:
|
||||||
|
var.scaleDeltas(scalar)
|
||||||
|
return [var]
|
||||||
|
|
||||||
# skip when current axis is missing (i.e. doesn't participate), or when the
|
# skip when current axis is missing (i.e. doesn't participate), or when the
|
||||||
# 'tent' isn't fully on either the negative or positive side
|
# 'tent' isn't fully on either the negative or positive side
|
||||||
lower, peak, upper = var.axes.get(axisTag, (-1, 0, 1))
|
lower, peak, upper = var.axes.get(axisTag, (-1, 0, 1))
|
||||||
|
|
||||||
if peak == 0 or lower > peak or peak > upper or (lower < 0 and upper > 0):
|
if peak == 0 or lower > peak or peak > upper or (lower < 0 and upper > 0):
|
||||||
return [var]
|
return [var]
|
||||||
|
|
||||||
negative = lower < 0
|
negative = lower < 0
|
||||||
if negative:
|
if negative:
|
||||||
if axisRange.minimum == -1.0:
|
if axisLimit.minimum == -1.0:
|
||||||
return [var]
|
return [var]
|
||||||
elif axisRange.minimum == 0.0:
|
elif axisLimit.minimum == 0.0:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
if axisRange.maximum == 1.0:
|
if axisLimit.maximum == 1.0:
|
||||||
return [var]
|
return [var]
|
||||||
elif axisRange.maximum == 0.0:
|
elif axisLimit.maximum == 0.0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
limit = axisRange.minimum if negative else axisRange.maximum
|
limit = axisLimit.minimum if negative else axisLimit.maximum
|
||||||
|
|
||||||
# Rebase axis bounds onto the new limit, which then becomes the new -1.0 or +1.0.
|
# Rebase axis bounds onto the new limit, which then becomes the new -1.0 or +1.0.
|
||||||
# The results are always positive, because both dividend and divisor are either
|
# The results are always positive, because both dividend and divisor are either
|
||||||
|
Loading…
x
Reference in New Issue
Block a user