dom-examples icon indicating copy to clipboard operation
dom-examples copied to clipboard

Improper Distance Calculation in Zoom Event

Open InkboxSoftware opened this issue 2 years ago • 2 comments

https://github.com/mdn/dom-examples/blob/master/pointerevents/Pinch_zoom_gestures.html

Line 79 of this script should be: var curDiff = Math.sqrt(Math.pow(evCache[1].clientX - evCache[0].clientX, 2) + Math.pow(evCache[1].clientY - evCache[0].clientY, 2));

Currently line 79 is only calculating the difference between the X coordinates of the touches, but it should actually be measuring the distance between the two points. In the case of the difference of the X coordinates not changing or even decreasing, but the overall distance between the two touches is increasing then the current line 79 would not register a zoom out, but a zoom in. The line written above prevents such confusion.

InkboxSoftware avatar Aug 17 '22 04:08 InkboxSoftware

Yep, Euclidian distance. Do you want to create a PR?

teoli2003 avatar Aug 17 '22 05:08 teoli2003

I've just submitted a pull request. I'm not quite so familiar with GitHub, so I hope I did it correctly.

InkboxSoftware avatar Aug 18 '22 01:08 InkboxSoftware

Resolved via https://github.com/mdn/dom-examples/issues/155.

caugner avatar Oct 25 '23 15:10 caugner

Just ran into this. Does this not relate to https://github.com/mdn/dom-examples/issues/9 ?

benjamingwynn avatar Oct 25 '23 15:10 benjamingwynn