From b77e9b6a40dfb0dcf06927f7bd1cc30b6414bb03 Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Mon, 24 Sep 2018 20:49:45 -0400 Subject: [PATCH] use the 'hypotenuse' function that has been sitting there waiting to be used --- src/onTap.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/onTap.js b/src/onTap.js index edef3bf..cd41eca 100644 --- a/src/onTap.js +++ b/src/onTap.js @@ -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, });