use the 'hypotenuse' function that has been sitting there waiting to be used
This commit is contained in:
10
src/onTap.js
10
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,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user