Release.toDisplay constructor

Release.toDisplay(
  1. ReleaseContext data
)

The default plan: settle back into the viewport (display). Per axis, physics-derived flings whose final settle (rubber) lands at a viewport- correct position — covers display when zoomed (with maxScale clamp + proportional pan preservation), snaps to base when not zoomed.

Implementation

factory Release.toDisplay(ReleaseContext data) {
  final scaleRelease = _scaleReleaseFor(data);
  final scaleTargetWidth = scaleRelease.settle?.to
      ?? (scaleRelease.decay.isEmpty
          ? data.currentRect.width
          : scaleRelease.decay.last.to);
  // Rect at the post-scale-settle dims — used by per-axis helpers to
  // compute viewport-fit at gesture-end *and* decay-end positions.
  final projectedRect = data.currentRect.resize(
    scaleTargetWidth,
    scaleTargetWidth / data.aspectRatio,
  );
  // Damp translation velocity by how scale-y the gesture was at end —
  // a strong pinch means the residual finger drift on the focal point
  // shouldn't translate into a pan fling. `scaleVelocityCancel` (0..1)
  // tunes the overall strength.
  //
  return Release(
    x: releaseFromStateX(
      currentRect: data.currentRect,
      displayRect: data.displayRect,
      bounds: data.gesture.bounds,
      velocity: data.velocity.pixelsPerSecond.dx,
      projectedRect: projectedRect,
    ),
    y: releaseFromStateY(
      currentRect: data.currentRect,
      displayRect: data.displayRect,
      bounds: data.gesture.bounds,
      velocity: data.velocity.pixelsPerSecond.dy,
      projectedRect: projectedRect,
    ),
    scale: scaleRelease,
  );
}