directionStateForX function
Four-value X-axis direction state: combines the motion direction
(extending vs retracting, decided by delta's sign relative to
boundForX) with whether the rect's relevant edge is past the
display edge.
Implementation
DragDirectionState directionStateForX({
required double delta,
required Rect currentRect,
required Rect baseRect,
required Rect displayRect,
}) {
final isRight = boundForX(delta: delta, currentRect: currentRect, baseRect: baseRect) == .right;
// Past-display semantic depends on rect size: small rect ⇒ far edge off
// display; zoomed rect ⇒ near edge past display edge (uncovers display).
final pastDisplay = currentRect.width <= displayRect.width
? (isRight
? currentRect.right > displayRect.right
: currentRect.left < displayRect.left)
: (isRight
? currentRect.left > displayRect.left
: currentRect.right < displayRect.right);
final extending = isRight ? delta > 0 : delta < 0;
if (extending) return pastDisplay ? .extendingPast : .extending;
return pastDisplay ? .retractingPast : .retracting;
}