Каталог файловhammer.js
601 * velocity is calculated every x ms602 * @param {Object} session603 * @param {Object} input604 */605 function computeIntervalInputData(session, input) {606 var last = session.lastInterval || input,607 deltaTime = input.timeStamp - last.timeStamp,608 velocity, velocityX, velocityY, direction;609 610 if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {611 var deltaX = input.deltaX - last.deltaX;612
История файла и сравнение версий
var deltaY = input.deltaY - last.deltaY;
614 var v = getVelocity(deltaTime, deltaX, deltaY); 617 velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y; 618 direction = getDirection(deltaX, deltaY); 620 session.lastInterval = input; 622 // use latest velocity info if it doesn't overtake a minimum period 623 velocity = last.velocity; 624 velocityX = last.velocityX; 625 velocityY = last.velocityY; 626 direction = last.direction; 629 input.velocity = velocity; 630 input.velocityX = velocityX; 631 input.velocityY = velocityY; 632 input.direction = direction; 636 * create a simple clone from the input used for storage of firstInput and firstMultiple 637 * @param {Object} input 638 * @returns {Object} clonedInputData 640 function simpleCloneInputData(input) { 641 // make a simple copy of the pointers because we will get a reference if we don't 642 // we only need clientXY for the calculations 645 while (i < input.pointers.length) { 647 clientX: round(input.pointers[i].clientX), 648 clientY: round(input.pointers[i].clientY) 656 center: getCenter(pointers), 657 deltaX: input.deltaX, 663 * get the center of all the pointers 664 * @param {Array} pointers 665 * @return {Object} center contains `x` and `y` properties 667 function getCenter(pointers) { 668 var pointersLength = pointers.length; 670 // no need to loop when only one touch 671 if (pointersLength === 1) { 673 x: round(pointers[0].clientX), 674 y: round(pointers[0].clientY) 678 var x = 0, y = 0, i = 0; 679 while (i < pointersLength) { 680 x += pointers[i].clientX; 681 y += pointers[i].clientY; 686 x: round(x / pointersLength), 687 y: round(y / pointersLength) 692 * calculate the velocity between two points. unit is in px per ms. 693 * @param {Number} deltaTime 696 * @return {Object} velocity `x` and `y` 698 function getVelocity(deltaTime, x, y) { 700 x: x / deltaTime || 0,