a zip code crypto-currency system good for red ONLY

recognizers.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var PanRecognizer = (function () {
  13. function PanRecognizer(direction, threshold, maxAngle) {
  14. this.direction = direction;
  15. this.dirty = false;
  16. this._angle = 0;
  17. this._isPan = 0;
  18. var radians = maxAngle * (Math.PI / 180);
  19. this.maxCosine = Math.cos(radians);
  20. this.threshold = threshold * threshold;
  21. }
  22. PanRecognizer.prototype.start = function (coord) {
  23. this.startCoord = coord;
  24. this._angle = 0;
  25. this._isPan = 0;
  26. this.dirty = true;
  27. };
  28. PanRecognizer.prototype.detect = function (coord) {
  29. if (!this.dirty) {
  30. return false;
  31. }
  32. var deltaX = (coord.x - this.startCoord.x);
  33. var deltaY = (coord.y - this.startCoord.y);
  34. var distance = deltaX * deltaX + deltaY * deltaY;
  35. if (distance >= this.threshold) {
  36. var angle = Math.atan2(deltaY, deltaX);
  37. var cosine = (this.direction === 'y')
  38. ? Math.sin(angle)
  39. : Math.cos(angle);
  40. this._angle = angle;
  41. if (cosine > this.maxCosine) {
  42. this._isPan = 1;
  43. }
  44. else if (cosine < -this.maxCosine) {
  45. this._isPan = -1;
  46. }
  47. else {
  48. this._isPan = 0;
  49. }
  50. this.dirty = false;
  51. return true;
  52. }
  53. return false;
  54. };
  55. PanRecognizer.prototype.angle = function () {
  56. return this._angle;
  57. };
  58. PanRecognizer.prototype.pan = function () {
  59. return this._isPan;
  60. };
  61. return PanRecognizer;
  62. }());
  63. exports.PanRecognizer = PanRecognizer;
  64. });
  65. //# sourceMappingURL=recognizers.js.map