Skip to content

fix: use smoothed velocity direction for touch flings to prevent off-axis glides#2226

Open
JonasGrunau wants to merge 1 commit into
fleaflet:masterfrom
JonasGrunau:fix/touch-fling-direction
Open

fix: use smoothed velocity direction for touch flings to prevent off-axis glides#2226
JonasGrunau wants to merge 1 commit into
fleaflet:masterfrom
JonasGrunau:fix/touch-fling-direction

Conversation

@JonasGrunau

Copy link
Copy Markdown

Fixes #2225.

What

On touch input, derive the fling direction from the gesture recognizer's velocity (Flutter's VelocityTracker, a least-squares fit over the last ~100 ms of samples) instead of the single last tracked pointer segment. Mouse/trackpad input keeps the tracked-segment behaviour introduced in #2158, which handles the pointer leaving the window mid-drag — a case that cannot occur with touch.

Also negates the velocityDirection passed into flingDirection() as the division-by-zero fallback (#2220), so all three direction candidates share the tracked-offset sign convention (end: flingOffset + direction * distance). Previously the degenerate zero/zero case glided against the swipe, since details.velocity.pixelsPerSecond points along the pointer motion while finalSegment/flingOffset run opposite to it (8.2.2 used the velocity with - direction * distance).

Why

The last tracked segment is one frame-to-frame delta. At fast swipe speeds it is dominated by touch-sampling noise and lift-off thumb-roll, so its direction routinely deviates 30–90° from the swipe axis: fast flicks glide off-axis and repeated flicks visibly zigzag (see #2225 for the full analysis). The fitted velocity direction is stable — it's what the pre-8.3.0 fling used and what platform map apps use.

How

  • MapInteractiveViewerState records the device kind of the last pointer-down.
  • flingDirection() gains a preferVelocityDirection parameter; when set (touch), the already-normalized velocityDirection is returned directly, otherwise the existing preference order (final segment → overall drag offset → velocity fallback) is unchanged.
  • Existing flingDirection tests updated for the new parameter; new test covers the touch preference.

All existing tests pass (flutter test), dart analyze clean, dart format clean.

…axis glides

Since fleaflet#2158 the fling direction is derived from the single last tracked
pointer segment. That fixed the pointer-leaves-window case on web/desktop,
but on touch devices the last segment is dominated by sampling noise and
lift-off thumb-roll, so fast swipes glide off-axis and repeated flicks
visibly zigzag (fleaflet#2225).

Prefer the gesture recognizer's velocity direction - a least-squares fit
over the last ~100ms of samples - when the gesture came from a touch
pointer, where the pointer cannot leave the window mid-drag. Mouse and
trackpad input keep the tracked-segment behaviour from fleaflet#2158.

Also negate the velocityDirection passed as the division-by-zero fallback
(fleaflet#2220) so all three direction candidates share the tracked-offset sign
convention; previously the degenerate case glided against the swipe.

Fixes fleaflet#2225.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fling direction is derived from the noisy last pointer segment on touch: fast swipes glide off-axis / zigzag since 8.3.0

1 participant