axisStateX function
Computes the X-axis state given the current motion (signedAmount is the
motion direction sign, e.g., delta or velocity) and the rect geometry.
Implementation
AxisState axisStateX(
double signedAmount,
Rect currentRect,
Rect originRect,
Rect displayRect,
) {
final bound = boundForX(delta: signedAmount, currentRect: currentRect, baseRect: originRect);
final direction = directionStateForX(
delta: signedAmount,
currentRect: currentRect,
baseRect: originRect,
displayRect: displayRect,
);
final isRight = bound == .right;
final pastDisplay = direction == .extendingPast || direction == .retractingPast;
final progress = pastDisplay
? ((isRight
? currentRect.right - displayRect.right
: displayRect.left - currentRect.left) / displayRect.width).clamp(0.0, 1.0)
: ((currentRect.center.dx - originRect.center.dx).abs() / (displayRect.width / 2)).clamp(0.0, 1.0);
return (activeBound: bound, directionState: direction, progress: progress);
}