1 | var PanRecognizer = (function () {
|
2 | |
3 |
|
4 |
|
5 |
|
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 |
|
18 |
|
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 |
|
28 |
|
29 |
|
30 | PanRecognizer.prototype.detect = function (coord) {
|
31 | if (!this.dirty) {
|
32 | return false;
|
33 | }
|
34 | var deltaX = (coord.x - this.startCoord.x);
|
35 | var deltaY = (coord.y - this.startCoord.y);
|
36 | var distance = deltaX * deltaX + deltaY * deltaY;
|
37 | if (distance >= this.threshold) {
|
38 | var angle = Math.atan2(deltaY, deltaX);
|
39 | var 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 |
|
59 |
|
60 | PanRecognizer.prototype.angle = function () {
|
61 | return this._angle;
|
62 | };
|
63 | |
64 |
|
65 |
|
66 | PanRecognizer.prototype.pan = function () {
|
67 | return this._isPan;
|
68 | };
|
69 | return PanRecognizer;
|
70 | }());
|
71 | export { PanRecognizer };
|
72 | function PanRecognizer_tsickle_Closure_declarations() {
|
73 |
|
74 | PanRecognizer.prototype.startCoord;
|
75 |
|
76 | PanRecognizer.prototype.dirty;
|
77 |
|
78 | PanRecognizer.prototype.threshold;
|
79 |
|
80 | PanRecognizer.prototype.maxCosine;
|
81 |
|
82 | PanRecognizer.prototype._angle;
|
83 |
|
84 | PanRecognizer.prototype._isPan;
|
85 |
|
86 | PanRecognizer.prototype.direction;
|
87 | }
|
88 |
|
\ | No newline at end of file |