mdn / dom-examples

Code examples that accompany various MDN DOM and Web API documentation pages

Home Page:https://developer.mozilla.org/en-US/docs/Web/API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improper Distance Calculation in Zoom Event

InkboxSoftware opened this issue · 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.

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.