@srsergio/taptapp-ar 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class OneEuroFilter {
|
|
2
|
+
constructor({ minCutOff, beta, dCutOff }: {
|
|
3
|
+
minCutOff?: number | undefined;
|
|
4
|
+
beta?: number | undefined;
|
|
5
|
+
dCutOff?: number | undefined;
|
|
6
|
+
});
|
|
7
|
+
minCutOff: number;
|
|
8
|
+
beta: number;
|
|
9
|
+
dCutOff: number;
|
|
10
|
+
x: any;
|
|
11
|
+
dx: any;
|
|
12
|
+
lastTime: any;
|
|
13
|
+
_alpha(cutoff: any, te: any): number;
|
|
14
|
+
reset(): void;
|
|
15
|
+
filter(time: any, value: any): any;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author: Gery Casiez
|
|
3
|
+
* Reference: http://www.lifl.fr/~casiez/1euro/
|
|
4
|
+
*/
|
|
5
|
+
class LowPassFilter {
|
|
6
|
+
constructor(alpha, initval = 0) {
|
|
7
|
+
this.y = initval;
|
|
8
|
+
this.s = initval;
|
|
9
|
+
this.alpha = alpha;
|
|
10
|
+
}
|
|
11
|
+
setAlpha(alpha) {
|
|
12
|
+
if (alpha <= 0 || alpha > 1) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.alpha = alpha;
|
|
16
|
+
}
|
|
17
|
+
filter(value) {
|
|
18
|
+
this.y = value;
|
|
19
|
+
this.s = this.alpha * value + (1.0 - this.alpha) * this.s;
|
|
20
|
+
return this.s;
|
|
21
|
+
}
|
|
22
|
+
filterWithAlpha(value, alpha) {
|
|
23
|
+
this.setAlpha(alpha);
|
|
24
|
+
return this.filter(value);
|
|
25
|
+
}
|
|
26
|
+
lastValue() {
|
|
27
|
+
return this.y;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class OneEuroFilter {
|
|
31
|
+
constructor({ minCutOff = 1.0, beta = 0.0, dCutOff = 1.0 }) {
|
|
32
|
+
this.minCutOff = minCutOff;
|
|
33
|
+
this.beta = beta;
|
|
34
|
+
this.dCutOff = dCutOff;
|
|
35
|
+
this.x = null;
|
|
36
|
+
this.dx = null;
|
|
37
|
+
this.lastTime = null;
|
|
38
|
+
}
|
|
39
|
+
_alpha(cutoff, te) {
|
|
40
|
+
const tau = 1.0 / (2 * Math.PI * cutoff);
|
|
41
|
+
return 1.0 / (1.0 + tau / te);
|
|
42
|
+
}
|
|
43
|
+
reset() {
|
|
44
|
+
this.lastTime = null;
|
|
45
|
+
this.x = null;
|
|
46
|
+
this.dx = null;
|
|
47
|
+
}
|
|
48
|
+
filter(time, value) {
|
|
49
|
+
if (this.lastTime === null || this.x === null) {
|
|
50
|
+
this.lastTime = time;
|
|
51
|
+
this.x = value.map((v) => new LowPassFilter(this._alpha(this.minCutOff, 1.0), v));
|
|
52
|
+
this.dx = value.map((v) => new LowPassFilter(this._alpha(this.dCutOff, 1.0), 0));
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
const te = (time - this.lastTime) / 1000.0;
|
|
56
|
+
if (te <= 0)
|
|
57
|
+
return value;
|
|
58
|
+
this.lastTime = time;
|
|
59
|
+
const filteredValue = [];
|
|
60
|
+
for (let i = 0; i < value.length; i++) {
|
|
61
|
+
const edvalue = (value[i] - this.x[i].lastValue()) / te;
|
|
62
|
+
const alpha_d = this._alpha(this.dCutOff, te);
|
|
63
|
+
const edvalue_filtered = this.dx[i].filterWithAlpha(edvalue, alpha_d);
|
|
64
|
+
const cutoff = this.minCutOff + this.beta * Math.abs(edvalue_filtered);
|
|
65
|
+
const alpha = this._alpha(cutoff, te);
|
|
66
|
+
filteredValue[i] = this.x[i].filterWithAlpha(value[i], alpha);
|
|
67
|
+
}
|
|
68
|
+
return filteredValue;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author: Gery Casiez
|
|
3
|
+
* Reference: http://www.lifl.fr/~casiez/1euro/
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class LowPassFilter {
|
|
7
|
+
constructor(alpha, initval = 0) {
|
|
8
|
+
this.y = initval;
|
|
9
|
+
this.s = initval;
|
|
10
|
+
this.alpha = alpha;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setAlpha(alpha) {
|
|
14
|
+
if (alpha <= 0 || alpha > 1) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.alpha = alpha;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
filter(value) {
|
|
21
|
+
this.y = value;
|
|
22
|
+
this.s = this.alpha * value + (1.0 - this.alpha) * this.s;
|
|
23
|
+
return this.s;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
filterWithAlpha(value, alpha) {
|
|
27
|
+
this.setAlpha(alpha);
|
|
28
|
+
return this.filter(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
lastValue() {
|
|
32
|
+
return this.y;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class OneEuroFilter {
|
|
37
|
+
constructor({ minCutOff = 1.0, beta = 0.0, dCutOff = 1.0 }) {
|
|
38
|
+
this.minCutOff = minCutOff;
|
|
39
|
+
this.beta = beta;
|
|
40
|
+
this.dCutOff = dCutOff;
|
|
41
|
+
this.x = null;
|
|
42
|
+
this.dx = null;
|
|
43
|
+
this.lastTime = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_alpha(cutoff, te) {
|
|
47
|
+
const tau = 1.0 / (2 * Math.PI * cutoff);
|
|
48
|
+
return 1.0 / (1.0 + tau / te);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
reset() {
|
|
52
|
+
this.lastTime = null;
|
|
53
|
+
this.x = null;
|
|
54
|
+
this.dx = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
filter(time, value) {
|
|
58
|
+
if (this.lastTime === null || this.x === null) {
|
|
59
|
+
this.lastTime = time;
|
|
60
|
+
this.x = value.map((v) => new LowPassFilter(this._alpha(this.minCutOff, 1.0), v));
|
|
61
|
+
this.dx = value.map((v) => new LowPassFilter(this._alpha(this.dCutOff, 1.0), 0));
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const te = (time - this.lastTime) / 1000.0;
|
|
66
|
+
if (te <= 0) return value;
|
|
67
|
+
this.lastTime = time;
|
|
68
|
+
|
|
69
|
+
const filteredValue = [];
|
|
70
|
+
for (let i = 0; i < value.length; i++) {
|
|
71
|
+
const edvalue = (value[i] - this.x[i].lastValue()) / te;
|
|
72
|
+
const alpha_d = this._alpha(this.dCutOff, te);
|
|
73
|
+
const edvalue_filtered = this.dx[i].filterWithAlpha(edvalue, alpha_d);
|
|
74
|
+
|
|
75
|
+
const cutoff = this.minCutOff + this.beta * Math.abs(edvalue_filtered);
|
|
76
|
+
const alpha = this._alpha(cutoff, te);
|
|
77
|
+
filteredValue[i] = this.x[i].filterWithAlpha(value[i], alpha);
|
|
78
|
+
}
|
|
79
|
+
return filteredValue;
|
|
80
|
+
}
|
|
81
|
+
}
|