noflo / noflo-gestures

Gesture recognition library for NoFlo
MIT License
3 stars 4 forks source link

Include center point and scale to position data #1

Closed bergie closed 11 years ago

bergie commented 11 years ago

For some gestures like pinch-to-zoom, it would be useful to have scale and center point of the gesture available.

Quick JavaScript example for calculating:

          var startX = [];
          var startY = [];
          var startPoints = [];
          var movePoints = [];
          for (var touch in e.detail) {
            if (e.detail[touch].startpoint) {
              startX.push(e.detail[touch].startpoint.x);
              startY.push(e.detail[touch].startpoint.y);
              startPoints.push(e.detail[touch].startpoint);
            }
            if (e.detail[touch].movepoint) {
              movePoints.push(e.detail[touch].movepoint);
            }
          }
          var center = {
            x: ((Math.min.apply(Math, startX) + Math.max.apply(Math, startX)) / 2),
            y: ((Math.min.apply(Math, startY) + Math.max.apply(Math, startY)) / 2)
          };
          var scale = 1;
          if (startPoints.length > 1 && movePoints.length > 1) {
            scale = getDistance(movePoints[0], movePoints[1]) / getDistance(startPoints[0], startPoints[1]);
          }