a zip code crypto-currency system good for red ONLY

recognizers.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var PanRecognizer = (function () {
  2. function PanRecognizer(direction, threshold, maxAngle) {
  3. this.direction = direction;
  4. this.dirty = false;
  5. this._angle = 0;
  6. this._isPan = 0;
  7. var radians = maxAngle * (Math.PI / 180);
  8. this.maxCosine = Math.cos(radians);
  9. this.threshold = threshold * threshold;
  10. }
  11. PanRecognizer.prototype.start = function (coord) {
  12. this.startCoord = coord;
  13. this._angle = 0;
  14. this._isPan = 0;
  15. this.dirty = true;
  16. };
  17. PanRecognizer.prototype.detect = function (coord) {
  18. if (!this.dirty) {
  19. return false;
  20. }
  21. var deltaX = (coord.x - this.startCoord.x);
  22. var deltaY = (coord.y - this.startCoord.y);
  23. var distance = deltaX * deltaX + deltaY * deltaY;
  24. if (distance >= this.threshold) {
  25. var angle = Math.atan2(deltaY, deltaX);
  26. var cosine = (this.direction === 'y')
  27. ? Math.sin(angle)
  28. : Math.cos(angle);
  29. this._angle = angle;
  30. if (cosine > this.maxCosine) {
  31. this._isPan = 1;
  32. }
  33. else if (cosine < -this.maxCosine) {
  34. this._isPan = -1;
  35. }
  36. else {
  37. this._isPan = 0;
  38. }
  39. this.dirty = false;
  40. return true;
  41. }
  42. return false;
  43. };
  44. PanRecognizer.prototype.angle = function () {
  45. return this._angle;
  46. };
  47. PanRecognizer.prototype.pan = function () {
  48. return this._isPan;
  49. };
  50. return PanRecognizer;
  51. }());
  52. export { PanRecognizer };
  53. //# sourceMappingURL=recognizers.js.map