dom-examples
dom-examples copied to clipboard
Improper Distance Calculation in Zoom Event
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.
Yep, Euclidian distance. Do you want to create a PR?
I've just submitted a pull request. I'm not quite so familiar with GitHub, so I hope I did it correctly.
Resolved via https://github.com/mdn/dom-examples/issues/155.
Just ran into this. Does this not relate to https://github.com/mdn/dom-examples/issues/9 ?