pubo-utils 1.0.129 → 1.0.142
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.
- package/dist/pubo-utils.js +1 -1
- package/es/color/utils.js +21 -19
- package/es/debounce/index.js +16 -52
- package/es/emitter/index.js +217 -229
- package/es/factory/index.js +3 -32
- package/es/filter/sensor.js +58 -65
- package/es/level/index.js +6 -4
- package/es/loop/index.d.ts +1 -1
- package/es/loop/index.js +92 -163
- package/es/math/geometry.js +28 -107
- package/es/promise/index.js +9 -41
- package/es/queue/index.js +97 -174
- package/es/random/index.js +1 -32
- package/es/regexp-list/index.js +6 -5
- package/es/sleep/index.js +23 -128
- package/es/stack/index.js +20 -17
- package/es/throttle/index.js +1 -36
- package/es/trigger/index.js +17 -12
- package/es/watch-dog/index.js +12 -10
- package/lib/color/utils.js +20 -17
- package/lib/debounce/index.js +16 -52
- package/lib/emitter/index.js +216 -226
- package/lib/factory/index.js +3 -32
- package/lib/filter/sensor.js +57 -62
- package/lib/level/index.js +5 -2
- package/lib/loop/index.d.ts +1 -1
- package/lib/loop/index.js +78 -150
- package/lib/math/geometry.js +28 -107
- package/lib/promise/index.js +9 -41
- package/lib/queue/index.js +96 -172
- package/lib/random/index.js +1 -32
- package/lib/regexp-list/index.js +5 -3
- package/lib/sleep/index.js +22 -129
- package/lib/stack/index.js +19 -15
- package/lib/throttle/index.js +1 -36
- package/lib/trigger/index.js +16 -10
- package/lib/watch-dog/index.js +11 -8
- package/package.json +2 -2
package/es/filter/sensor.js
CHANGED
|
@@ -1,43 +1,49 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
i = 0;
|
|
5
|
-
if (m) return m.call(o);
|
|
6
|
-
if (o && typeof o.length === "number") return {
|
|
7
|
-
next: function next() {
|
|
8
|
-
if (o && i >= o.length) o = void 0;
|
|
9
|
-
return {
|
|
10
|
-
value: o && o[i++],
|
|
11
|
-
done: !o
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
16
|
-
};
|
|
1
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
4
|
// 过滤跳变数据
|
|
18
|
-
var SensorDataFilter =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
export var SensorDataFilter = /*#__PURE__*/function () {
|
|
6
|
+
// 缓冲区
|
|
7
|
+
|
|
8
|
+
// 最大缓存
|
|
9
|
+
|
|
10
|
+
// 跳变步长
|
|
11
|
+
|
|
12
|
+
// 最小值
|
|
13
|
+
|
|
14
|
+
// 最大值
|
|
15
|
+
|
|
16
|
+
// 与缓冲区不一致的值连续出现的次数 (不一致指的是与缓冲区中数量最多的数值不同且差值大于步长)
|
|
17
|
+
|
|
18
|
+
// 与缓冲区不一致的值
|
|
19
|
+
|
|
20
|
+
// 上一次正确返回的值
|
|
21
|
+
|
|
22
|
+
function SensorDataFilter(_temp) {
|
|
23
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
24
|
+
_ref$size = _ref.size,
|
|
25
|
+
size = _ref$size === void 0 ? 5 : _ref$size,
|
|
26
|
+
_ref$step = _ref.step,
|
|
27
|
+
step = _ref$step === void 0 ? 5 : _ref$step,
|
|
28
|
+
_ref$min = _ref.min,
|
|
29
|
+
min = _ref$min === void 0 ? -Infinity : _ref$min,
|
|
30
|
+
_ref$max = _ref.max,
|
|
31
|
+
max = _ref$max === void 0 ? Infinity : _ref$max;
|
|
30
32
|
this.tmp = [];
|
|
31
|
-
|
|
33
|
+
this.size = void 0;
|
|
34
|
+
this.step = void 0;
|
|
35
|
+
this.min = void 0;
|
|
36
|
+
this.max = void 0;
|
|
32
37
|
this.count = 0;
|
|
33
|
-
// 与缓冲区不一致的值
|
|
34
38
|
this.value = NaN;
|
|
39
|
+
this.old = void 0;
|
|
35
40
|
this.size = size;
|
|
36
41
|
this.step = step;
|
|
37
42
|
this.min = min;
|
|
38
43
|
this.max = max;
|
|
39
44
|
}
|
|
40
|
-
SensorDataFilter.prototype
|
|
45
|
+
var _proto = SensorDataFilter.prototype;
|
|
46
|
+
_proto.filter = function filter(n) {
|
|
41
47
|
// 溢出范围的值将被忽略
|
|
42
48
|
if (n < this.min || n > this.max) {
|
|
43
49
|
return this.old;
|
|
@@ -46,7 +52,7 @@ var SensorDataFilter = /** @class */function () {
|
|
|
46
52
|
this.old = this.calc(n);
|
|
47
53
|
return this.old;
|
|
48
54
|
};
|
|
49
|
-
|
|
55
|
+
_proto.calc = function calc(n) {
|
|
50
56
|
// 缓冲区没有值时直接返回当前值
|
|
51
57
|
if (this.tmp.length < 1) {
|
|
52
58
|
return n;
|
|
@@ -54,9 +60,9 @@ var SensorDataFilter = /** @class */function () {
|
|
|
54
60
|
if (this.tmp.length > this.size) {
|
|
55
61
|
this.tmp.shift();
|
|
56
62
|
}
|
|
57
|
-
var
|
|
58
|
-
res =
|
|
59
|
-
dic =
|
|
63
|
+
var _this$getMostNumberOf = this.getMostNumberOfTmp(),
|
|
64
|
+
res = _this$getMostNumberOf.res,
|
|
65
|
+
dic = _this$getMostNumberOf.dic;
|
|
60
66
|
// 当前值与缓冲区数量最多的值不一致且差值大于步长
|
|
61
67
|
if (res !== n && Math.abs(res - n) > this.step) {
|
|
62
68
|
// 累计跳变数据连续出现的次数
|
|
@@ -79,39 +85,26 @@ var SensorDataFilter = /** @class */function () {
|
|
|
79
85
|
return n;
|
|
80
86
|
}
|
|
81
87
|
return res;
|
|
82
|
-
}
|
|
88
|
+
}
|
|
83
89
|
/**
|
|
84
90
|
* A function to calculate the most frequent element in the 'tmp' array and its frequency.
|
|
85
91
|
*
|
|
86
92
|
* @return {object} An object containing the most frequent element and its frequency.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var e_1, _a;
|
|
93
|
+
*/;
|
|
94
|
+
_proto.getMostNumberOfTmp = function getMostNumberOfTmp() {
|
|
90
95
|
var a = {};
|
|
91
96
|
var max = 0;
|
|
92
97
|
var res;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
a[item] += 1;
|
|
100
|
-
}
|
|
101
|
-
if (a[item] > max) {
|
|
102
|
-
max = a[item];
|
|
103
|
-
res = item;
|
|
104
|
-
}
|
|
98
|
+
for (var _iterator = _createForOfIteratorHelperLoose(this.tmp), _step; !(_step = _iterator()).done;) {
|
|
99
|
+
var item = _step.value;
|
|
100
|
+
if (!a[item]) {
|
|
101
|
+
a[item] = 1;
|
|
102
|
+
} else {
|
|
103
|
+
a[item] += 1;
|
|
105
104
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
} finally {
|
|
111
|
-
try {
|
|
112
|
-
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
|
|
113
|
-
} finally {
|
|
114
|
-
if (e_1) throw e_1.error;
|
|
105
|
+
if (a[item] > max) {
|
|
106
|
+
max = a[item];
|
|
107
|
+
res = item;
|
|
115
108
|
}
|
|
116
109
|
}
|
|
117
110
|
return {
|
|
@@ -121,24 +114,24 @@ var SensorDataFilter = /** @class */function () {
|
|
|
121
114
|
};
|
|
122
115
|
return SensorDataFilter;
|
|
123
116
|
}();
|
|
124
|
-
export { SensorDataFilter };
|
|
125
117
|
/**
|
|
126
118
|
* Splits the input string using the specified split symbol and returns an array of substrings.
|
|
127
119
|
*
|
|
128
120
|
* @param {string} str - the input string to be split
|
|
129
121
|
* @return {string[]} an array of substrings
|
|
130
122
|
*/
|
|
131
|
-
var StringSplit =
|
|
123
|
+
export var StringSplit = /*#__PURE__*/function () {
|
|
132
124
|
function StringSplit(splitSymbol) {
|
|
125
|
+
this._splitSymbol = void 0;
|
|
133
126
|
this._cache = '';
|
|
134
127
|
this._splitSymbol = splitSymbol;
|
|
135
128
|
}
|
|
136
|
-
StringSplit.prototype
|
|
129
|
+
var _proto2 = StringSplit.prototype;
|
|
130
|
+
_proto2.split = function split(str) {
|
|
137
131
|
var tmp = this._cache + str;
|
|
138
132
|
var arr = tmp.split(this._splitSymbol);
|
|
139
133
|
this._cache = arr.splice(arr.length - 1, 1)[0];
|
|
140
134
|
return arr;
|
|
141
135
|
};
|
|
142
136
|
return StringSplit;
|
|
143
|
-
}();
|
|
144
|
-
export { StringSplit };
|
|
137
|
+
}();
|
package/es/level/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
var Level =
|
|
1
|
+
export var Level = /*#__PURE__*/function () {
|
|
2
2
|
function Level(props) {
|
|
3
|
+
this.config = void 0;
|
|
4
|
+
this.step = void 0;
|
|
3
5
|
this.config = props;
|
|
4
6
|
this.step = (this.config.max - this.config.min) / (this.config.count - 2);
|
|
5
7
|
}
|
|
6
|
-
Level.prototype
|
|
8
|
+
var _proto = Level.prototype;
|
|
9
|
+
_proto.get = function get(value) {
|
|
7
10
|
if (value <= this.config.min) {
|
|
8
11
|
return 1;
|
|
9
12
|
}
|
|
@@ -18,5 +21,4 @@ var Level = /** @class */function () {
|
|
|
18
21
|
return this.config.count;
|
|
19
22
|
};
|
|
20
23
|
return Level;
|
|
21
|
-
}();
|
|
22
|
-
export { Level };
|
|
24
|
+
}();
|
package/es/loop/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {number} time - The time interval in milliseconds for the loop.
|
|
6
6
|
* @return {Function} The stop function that can be used to stop the loop.
|
|
7
7
|
*/
|
|
8
|
-
export declare const loop: (cb: (
|
|
8
|
+
export declare const loop: (cb: () => Promise<void>, time: number) => () => void;
|
|
9
9
|
type WaitForBool = () => boolean | Promise<boolean>;
|
|
10
10
|
/**
|
|
11
11
|
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
package/es/loop/index.js
CHANGED
|
@@ -1,118 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) {
|
|
9
|
-
try {
|
|
10
|
-
step(generator.next(value));
|
|
11
|
-
} catch (e) {
|
|
12
|
-
reject(e);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function rejected(value) {
|
|
16
|
-
try {
|
|
17
|
-
step(generator["throw"](value));
|
|
18
|
-
} catch (e) {
|
|
19
|
-
reject(e);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function step(result) {
|
|
23
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
-
}
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __generator = this && this.__generator || function (thisArg, body) {
|
|
29
|
-
var _ = {
|
|
30
|
-
label: 0,
|
|
31
|
-
sent: function sent() {
|
|
32
|
-
if (t[0] & 1) throw t[1];
|
|
33
|
-
return t[1];
|
|
34
|
-
},
|
|
35
|
-
trys: [],
|
|
36
|
-
ops: []
|
|
37
|
-
},
|
|
38
|
-
f,
|
|
39
|
-
y,
|
|
40
|
-
t,
|
|
41
|
-
g;
|
|
42
|
-
return g = {
|
|
43
|
-
next: verb(0),
|
|
44
|
-
"throw": verb(1),
|
|
45
|
-
"return": verb(2)
|
|
46
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
47
|
-
return this;
|
|
48
|
-
}), g;
|
|
49
|
-
function verb(n) {
|
|
50
|
-
return function (v) {
|
|
51
|
-
return step([n, v]);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function step(op) {
|
|
55
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
58
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
-
switch (op[0]) {
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [0];
|
|
74
|
-
continue;
|
|
75
|
-
case 7:
|
|
76
|
-
op = _.ops.pop();
|
|
77
|
-
_.trys.pop();
|
|
78
|
-
continue;
|
|
79
|
-
default:
|
|
80
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
-
_ = 0;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
-
_.label = op[1];
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
-
_.label = t[1];
|
|
90
|
-
t = op;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
if (t && _.label < t[2]) {
|
|
94
|
-
_.label = t[2];
|
|
95
|
-
_.ops.push(op);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
if (t[2]) _.ops.pop();
|
|
99
|
-
_.trys.pop();
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
op = body.call(thisArg, _);
|
|
103
|
-
} catch (e) {
|
|
104
|
-
op = [6, e];
|
|
105
|
-
y = 0;
|
|
106
|
-
} finally {
|
|
107
|
-
f = t = 0;
|
|
108
|
-
}
|
|
109
|
-
if (op[0] & 5) throw op[1];
|
|
110
|
-
return {
|
|
111
|
-
value: op[0] ? op[1] : void 0,
|
|
112
|
-
done: true
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
1
|
import { sleep } from '../sleep';
|
|
117
2
|
/**
|
|
118
3
|
* Executes the given callback function in a loop with the specified time interval.
|
|
@@ -121,72 +6,116 @@ import { sleep } from '../sleep';
|
|
|
121
6
|
* @param {number} time - The time interval in milliseconds for the loop.
|
|
122
7
|
* @return {Function} The stop function that can be used to stop the loop.
|
|
123
8
|
*/
|
|
9
|
+
|
|
10
|
+
function _empty() {} /**
|
|
11
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
12
|
+
*
|
|
13
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
14
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
15
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
16
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
17
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function _call(body, then, direct) {
|
|
21
|
+
if (direct) {
|
|
22
|
+
return then ? then(body()) : body();
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
var result = Promise.resolve(body());
|
|
26
|
+
return then ? result.then(then) : result;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return Promise.reject(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function _callIgnored(body, direct) {
|
|
32
|
+
return _call(body, _empty, direct);
|
|
33
|
+
}
|
|
34
|
+
function _catch(body, recover) {
|
|
35
|
+
try {
|
|
36
|
+
var result = body();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return recover(e);
|
|
39
|
+
}
|
|
40
|
+
if (result && result.then) {
|
|
41
|
+
return result.then(void 0, recover);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function _await(value, then, direct) {
|
|
46
|
+
if (direct) {
|
|
47
|
+
return then ? then(value) : value;
|
|
48
|
+
}
|
|
49
|
+
if (!value || !value.then) {
|
|
50
|
+
value = Promise.resolve(value);
|
|
51
|
+
}
|
|
52
|
+
return then ? value.then(then) : value;
|
|
53
|
+
}
|
|
54
|
+
function _continue(value, then) {
|
|
55
|
+
return value && value.then ? value.then(then) : then(value);
|
|
56
|
+
}
|
|
57
|
+
function _async(f) {
|
|
58
|
+
return function () {
|
|
59
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
60
|
+
args[i] = arguments[i];
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return Promise.resolve(f.apply(this, args));
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return Promise.reject(e);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
124
69
|
export var loop = function loop(cb, time) {
|
|
125
70
|
var onOff = true;
|
|
126
71
|
var stop = function stop() {
|
|
127
72
|
onOff = false;
|
|
128
73
|
};
|
|
129
|
-
var
|
|
130
|
-
return
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
return [2 /*return*/];
|
|
74
|
+
var fn = _async(function () {
|
|
75
|
+
return _continue(_catch(function () {
|
|
76
|
+
return _callIgnored(cb);
|
|
77
|
+
}, function (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
}), function () {
|
|
80
|
+
return _await(sleep(time), function () {
|
|
81
|
+
if (onOff) {
|
|
82
|
+
fn();
|
|
83
|
+
} else {
|
|
84
|
+
fn = null;
|
|
85
|
+
cb = null;
|
|
86
|
+
stop = null;
|
|
87
|
+
onOff = null;
|
|
88
|
+
time = null;
|
|
146
89
|
}
|
|
147
90
|
});
|
|
148
91
|
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
_fn();
|
|
92
|
+
});
|
|
93
|
+
fn();
|
|
152
94
|
return stop;
|
|
153
95
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* @param {Object} options - optional parameters for checkTime and timeout
|
|
159
|
-
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
160
|
-
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
161
|
-
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
162
|
-
*/
|
|
163
|
-
export var waitFor = function waitFor(bool, _a) {
|
|
164
|
-
var _b = _a === void 0 ? {} : _a,
|
|
165
|
-
checkTime = _b.checkTime,
|
|
166
|
-
timeout = _b.timeout;
|
|
96
|
+
export var waitFor = function waitFor(bool, _temp) {
|
|
97
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
98
|
+
checkTime = _ref.checkTime,
|
|
99
|
+
timeout = _ref.timeout;
|
|
167
100
|
return new Promise(function (resolve, reject) {
|
|
168
101
|
var stop = loop(function () {
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (res) {
|
|
178
|
-
stop();
|
|
179
|
-
resolve(res);
|
|
180
|
-
}
|
|
181
|
-
return [2 /*return*/];
|
|
182
|
-
}
|
|
183
|
-
});
|
|
102
|
+
return _call(bool, function (res) {
|
|
103
|
+
if (res) {
|
|
104
|
+
stop();
|
|
105
|
+
stop = null;
|
|
106
|
+
bool = null;
|
|
107
|
+
resolve(res);
|
|
108
|
+
resolve = null;
|
|
109
|
+
}
|
|
184
110
|
});
|
|
185
111
|
}, checkTime || 100);
|
|
186
112
|
if (timeout) {
|
|
187
113
|
setTimeout(function () {
|
|
188
114
|
stop();
|
|
115
|
+
stop = null;
|
|
116
|
+
bool = null;
|
|
189
117
|
reject('timeout');
|
|
118
|
+
reject = null;
|
|
190
119
|
}, timeout);
|
|
191
120
|
}
|
|
192
121
|
});
|
package/es/math/geometry.js
CHANGED
|
@@ -1,60 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
6
|
-
}
|
|
7
|
-
return t;
|
|
8
|
-
};
|
|
9
|
-
return __assign.apply(this, arguments);
|
|
10
|
-
};
|
|
11
|
-
var __values = this && this.__values || function (o) {
|
|
12
|
-
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
13
|
-
m = s && o[s],
|
|
14
|
-
i = 0;
|
|
15
|
-
if (m) return m.call(o);
|
|
16
|
-
if (o && typeof o.length === "number") return {
|
|
17
|
-
next: function next() {
|
|
18
|
-
if (o && i >= o.length) o = void 0;
|
|
19
|
-
return {
|
|
20
|
-
value: o && o[i++],
|
|
21
|
-
done: !o
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
26
|
-
};
|
|
27
|
-
var __read = this && this.__read || function (o, n) {
|
|
28
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
29
|
-
if (!m) return o;
|
|
30
|
-
var i = m.call(o),
|
|
31
|
-
r,
|
|
32
|
-
ar = [],
|
|
33
|
-
e;
|
|
34
|
-
try {
|
|
35
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
e = {
|
|
38
|
-
error: error
|
|
39
|
-
};
|
|
40
|
-
} finally {
|
|
41
|
-
try {
|
|
42
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
43
|
-
} finally {
|
|
44
|
-
if (e) throw e.error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return ar;
|
|
48
|
-
};
|
|
49
|
-
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
58
5
|
// 获取两点的距离
|
|
59
6
|
export var getDistance = function getDistance(a, b) {
|
|
60
7
|
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
@@ -68,9 +15,9 @@ export var radians = function radians(deg) {
|
|
|
68
15
|
return deg * Math.PI / 180;
|
|
69
16
|
};
|
|
70
17
|
// 获取三角形角度
|
|
71
|
-
export var getAngle = function getAngle(
|
|
72
|
-
var w =
|
|
73
|
-
h =
|
|
18
|
+
export var getAngle = function getAngle(_ref) {
|
|
19
|
+
var w = _ref.w,
|
|
20
|
+
h = _ref.h;
|
|
74
21
|
return degrees(Math.atan2(h, w));
|
|
75
22
|
};
|
|
76
23
|
// 关键点过滤
|
|
@@ -92,28 +39,15 @@ export function filterKeyPoints(list, len) {
|
|
|
92
39
|
}
|
|
93
40
|
// 获取中心点坐标
|
|
94
41
|
export function getCenter(list) {
|
|
95
|
-
var e_1, _a;
|
|
96
42
|
var tmp = [0, 0];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
tmp[1] += item.y;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} catch (e_1_1) {
|
|
109
|
-
e_1 = {
|
|
110
|
-
error: e_1_1
|
|
111
|
-
};
|
|
112
|
-
} finally {
|
|
113
|
-
try {
|
|
114
|
-
if (list_1_1 && !list_1_1.done && (_a = list_1["return"])) _a.call(list_1);
|
|
115
|
-
} finally {
|
|
116
|
-
if (e_1) throw e_1.error;
|
|
43
|
+
for (var _iterator = _createForOfIteratorHelperLoose(list), _step; !(_step = _iterator()).done;) {
|
|
44
|
+
var item = _step.value;
|
|
45
|
+
if (Array.isArray(item)) {
|
|
46
|
+
tmp[0] += item[0];
|
|
47
|
+
tmp[1] += item[1];
|
|
48
|
+
} else {
|
|
49
|
+
tmp[0] += item.x;
|
|
50
|
+
tmp[1] += item.y;
|
|
117
51
|
}
|
|
118
52
|
}
|
|
119
53
|
return {
|
|
@@ -137,38 +71,25 @@ export var getPositionTheta = function getPositionTheta(a, b) {
|
|
|
137
71
|
};
|
|
138
72
|
// 获取距离和方向最佳的位置点
|
|
139
73
|
export var getBestPointIndex = function getBestPointIndex(points, pose) {
|
|
140
|
-
var e_2, _a;
|
|
141
74
|
if (points.length < 2) {
|
|
142
75
|
return 0;
|
|
143
76
|
}
|
|
144
77
|
var temp = [];
|
|
145
78
|
var minDistance = Infinity;
|
|
146
79
|
var index = 0;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
minDistance = distance;
|
|
154
|
-
}
|
|
155
|
-
temp.push(__assign(__assign({}, item), {
|
|
156
|
-
index: index,
|
|
157
|
-
distance: distance,
|
|
158
|
-
theta: theta
|
|
159
|
-
}));
|
|
160
|
-
index += 1;
|
|
161
|
-
}
|
|
162
|
-
} catch (e_2_1) {
|
|
163
|
-
e_2 = {
|
|
164
|
-
error: e_2_1
|
|
165
|
-
};
|
|
166
|
-
} finally {
|
|
167
|
-
try {
|
|
168
|
-
if (points_1_1 && !points_1_1.done && (_a = points_1["return"])) _a.call(points_1);
|
|
169
|
-
} finally {
|
|
170
|
-
if (e_2) throw e_2.error;
|
|
80
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(points), _step2; !(_step2 = _iterator2()).done;) {
|
|
81
|
+
var item = _step2.value;
|
|
82
|
+
var distance = getDistance(item, pose);
|
|
83
|
+
var theta = getPositionTheta(pose, item) - pose.theta;
|
|
84
|
+
if (minDistance > distance) {
|
|
85
|
+
minDistance = distance;
|
|
171
86
|
}
|
|
87
|
+
temp.push(_extends({}, item, {
|
|
88
|
+
index: index,
|
|
89
|
+
distance: distance,
|
|
90
|
+
theta: theta
|
|
91
|
+
}));
|
|
92
|
+
index += 1;
|
|
172
93
|
}
|
|
173
94
|
var results = temp.filter(function (item) {
|
|
174
95
|
return item.distance - minDistance < 0.1;
|
|
@@ -188,7 +109,7 @@ export var orderByDistance = function orderByDistance(points, pose) {
|
|
|
188
109
|
}
|
|
189
110
|
var current = pose;
|
|
190
111
|
var results = [];
|
|
191
|
-
var arr =
|
|
112
|
+
var arr = [].concat(points);
|
|
192
113
|
while (arr.length > 0) {
|
|
193
114
|
var index = getBestPointIndex(arr, current);
|
|
194
115
|
results.push(arr[index]);
|