UNPKG

2.51 kBJavaScriptView Raw
1var PanRecognizer = (function () {
2 /**
3 * @param {?} direction
4 * @param {?} threshold
5 * @param {?} maxAngle
6 */
7 function PanRecognizer(direction, threshold, maxAngle) {
8 this.direction = direction;
9 this.dirty = false;
10 this._angle = 0;
11 this._isPan = 0;
12 var radians = maxAngle * (Math.PI / 180);
13 this.maxCosine = Math.cos(radians);
14 this.threshold = threshold * threshold;
15 }
16 /**
17 * @param {?} coord
18 * @return {?}
19 */
20 PanRecognizer.prototype.start = function (coord) {
21 this.startCoord = coord;
22 this._angle = 0;
23 this._isPan = 0;
24 this.dirty = true;
25 };
26 /**
27 * @param {?} coord
28 * @return {?}
29 */
30 PanRecognizer.prototype.detect = function (coord) {
31 if (!this.dirty) {
32 return false;
33 }
34 var /** @type {?} */ deltaX = (coord.x - this.startCoord.x);
35 var /** @type {?} */ deltaY = (coord.y - this.startCoord.y);
36 var /** @type {?} */ distance = deltaX * deltaX + deltaY * deltaY;
37 if (distance >= this.threshold) {
38 var /** @type {?} */ angle = Math.atan2(deltaY, deltaX);
39 var /** @type {?} */ cosine = (this.direction === 'y')
40 ? Math.sin(angle)
41 : Math.cos(angle);
42 this._angle = angle;
43 if (cosine > this.maxCosine) {
44 this._isPan = 1;
45 }
46 else if (cosine < -this.maxCosine) {
47 this._isPan = -1;
48 }
49 else {
50 this._isPan = 0;
51 }
52 this.dirty = false;
53 return true;
54 }
55 return false;
56 };
57 /**
58 * @return {?}
59 */
60 PanRecognizer.prototype.angle = function () {
61 return this._angle;
62 };
63 /**
64 * @return {?}
65 */
66 PanRecognizer.prototype.pan = function () {
67 return this._isPan;
68 };
69 return PanRecognizer;
70}());
71export { PanRecognizer };
72function PanRecognizer_tsickle_Closure_declarations() {
73 /** @type {?} */
74 PanRecognizer.prototype.startCoord;
75 /** @type {?} */
76 PanRecognizer.prototype.dirty;
77 /** @type {?} */
78 PanRecognizer.prototype.threshold;
79 /** @type {?} */
80 PanRecognizer.prototype.maxCosine;
81 /** @type {?} */
82 PanRecognizer.prototype._angle;
83 /** @type {?} */
84 PanRecognizer.prototype._isPan;
85 /** @type {?} */
86 PanRecognizer.prototype.direction;
87}
88//# sourceMappingURL=recognizers.js.map
\No newline at end of file