Skip to content

Use cartesian distance for pinch zoom gesture#42728

Merged
sideshowbarker merged 2 commits intomdn:mainfrom
atg:patch-1
Jan 19, 2026
Merged

Use cartesian distance for pinch zoom gesture#42728
sideshowbarker merged 2 commits intomdn:mainfrom
atg:patch-1

Conversation

@atg
Copy link
Copy Markdown
Contributor

@atg atg commented Jan 11, 2026

Pinch zoom gestures should use cartesian distance, because they are usually executed diagonally, and so that they can optionally be combined with a rotate gesture.

Description

The previous code used the following distance calculation that only looks at the horizontal component of the pinch:

const curDiff = Math.abs(evCache[0].clientX - evCache[1].clientX);

If you actually try to zoom like this, it's very challenging ergonomically: your thumb, index finger, hand and forearm and all on the same line, your arm wants to be perpendicular to your body and the trackpad, so doing a pinch zoom horizontally requires your forearm to be almost parallel to the trackpad. In other words, the vertical component is the primary component for a pinch zoom and the horizontal component is secondary.

Usually a pinch zoom is implemented as cartesian distance because it is complemented by the rotate gesture. So a 1 dimensional pinch zoom is inconsistent with user expectations.

Pinch zoom gestures should use cartesian distance, because they are usually executed diagonally, and so that they can optionally be combined with a rotate gesture.
@atg atg requested a review from a team as a code owner January 11, 2026 04:04
@atg atg requested review from sideshowbarker and removed request for a team January 11, 2026 04:04
@github-actions github-actions bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Jan 11, 2026
Comment thread files/en-us/web/api/pointer_events/pinch_zoom_gestures/index.md Outdated
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Jan 11, 2026
@sideshowbarker sideshowbarker merged commit 5f6be19 into mdn:main Jan 19, 2026
8 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@sideshowbarker
Copy link
Copy Markdown
Member

@atg, congrats on landing your first docs change here — welcome aboard 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants