use the 'hypotenuse' function that has been sitting there waiting to be used

This commit is contained in:
Gavin McDonald
2018-09-24 20:49:45 -04:00
parent 25fd30a2fa
commit b77e9b6a40

View File

@@ -1,4 +1,4 @@
import {noop} from './utils.js';
import {hypotenuse, noop} from './utils.js';
const MODULE = 'onTap';
@@ -123,8 +123,10 @@ export default class OnTap {
this.state.lastY = event.offsetY;
if (event.touches.length > 1) {
this.state.scaleStart = hypotenuse(touches[0].pageX - touches[1].pageX, touches[0].pageY - touches[1].pageY);
this.state.pinching = true;
this.state.scaleStart = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2));
this.state.lastPinch = 1;
clearTimeout(this.state.pressTO);
}
@@ -240,12 +242,12 @@ export default class OnTap {
event.scale = event.scale ? event.scale :
touches.length < 2 ? 1 :
Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)) / this.state.scaleStart;
hypotenuse(touches[0].pageX - touches[1].pageX, touches[0].pageY - touches[1].pageY) / this.state.scaleStart;
Object.assign(event, {
offsetX: touches.reduce((memo, touch) => memo + touch.pageX, 0) / touches.length,
offsetY: touches.reduce((memo, touch) => memo + touch.pageY, 0) / touches.length,
scaleStep: event.scale / (this.state.lastPinch || 1),
scaleStep: event.scale / this.state.lastPinch,
mobile: true,
});