pubo-utils 1.0.157 → 1.0.159
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/base64/index.js +6 -7
- package/es/color/utils.d.ts +1 -10
- package/es/color/utils.js +17 -12
- package/es/debounce/index.js +6 -7
- package/es/emitter/index.js +15 -5
- package/es/factory/index.js +3 -4
- package/es/filter/sensor.js +15 -17
- package/es/index.js +1 -1
- package/es/level/index.js +2 -2
- package/es/loop/index.d.ts +2 -2
- package/es/loop/index.js +9 -13
- package/es/math/geometry.js +45 -25
- package/es/promise/index.js +15 -14
- package/es/queue/index.js +10 -6
- package/es/random/index.js +5 -10
- package/es/regexp-list/index.js +2 -2
- package/es/sleep/index.js +3 -4
- package/es/stack/index.js +1 -1
- package/es/str.js +2 -5
- package/es/throttle/index.d.ts +1 -1
- package/es/throttle/index.js +13 -14
- package/es/trigger/index.js +2 -2
- package/es/watch-dog/index.js +2 -2
- package/lib/base64/index.js +23 -15
- package/lib/color/utils.d.ts +1 -10
- package/lib/color/utils.js +40 -20
- package/lib/debounce/index.js +15 -10
- package/lib/emitter/index.js +34 -11
- package/lib/factory/index.js +12 -12
- package/lib/filter/sensor.js +32 -26
- package/lib/index.js +165 -73
- package/lib/level/index.js +11 -5
- package/lib/loop/index.d.ts +2 -2
- package/lib/loop/index.js +28 -33
- package/lib/math/geometry.js +94 -54
- package/lib/promise/index.js +25 -18
- package/lib/queue/index.js +19 -9
- package/lib/random/index.js +23 -20
- package/lib/regexp-list/index.js +11 -5
- package/lib/sleep/index.js +13 -8
- package/lib/stack/index.js +10 -4
- package/lib/str.js +12 -9
- package/lib/throttle/index.d.ts +1 -1
- package/lib/throttle/index.js +22 -17
- package/lib/trigger/index.js +11 -5
- package/lib/watch-dog/index.js +11 -5
- package/package.json +2 -14
package/lib/index.js
CHANGED
|
@@ -1,76 +1,168 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
Base64Utils: function() {
|
|
13
|
+
return _base64;
|
|
14
|
+
},
|
|
15
|
+
ContinuousTrigger: function() {
|
|
16
|
+
return _trigger.ContinuousTrigger;
|
|
17
|
+
},
|
|
18
|
+
Emitter: function() {
|
|
19
|
+
return _emitter.Emitter;
|
|
20
|
+
},
|
|
21
|
+
HistoryStack: function() {
|
|
22
|
+
return _stack.HistoryStack;
|
|
23
|
+
},
|
|
24
|
+
Level: function() {
|
|
25
|
+
return _level.Level;
|
|
26
|
+
},
|
|
27
|
+
RegExpList: function() {
|
|
28
|
+
return _regexplist.RegExpList;
|
|
29
|
+
},
|
|
30
|
+
SensorDataFilter: function() {
|
|
31
|
+
return _sensor.SensorDataFilter;
|
|
32
|
+
},
|
|
33
|
+
StringSplit: function() {
|
|
34
|
+
return _sensor.StringSplit;
|
|
35
|
+
},
|
|
36
|
+
SyncQueue: function() {
|
|
37
|
+
return _queue.SyncQueue;
|
|
38
|
+
},
|
|
39
|
+
WatchDog: function() {
|
|
40
|
+
return _watchdog.WatchDog;
|
|
41
|
+
},
|
|
42
|
+
callbackToPromise: function() {
|
|
43
|
+
return _promise.callbackToPromise;
|
|
44
|
+
},
|
|
45
|
+
debounce: function() {
|
|
46
|
+
return _debounce.debounce;
|
|
47
|
+
},
|
|
48
|
+
degrees: function() {
|
|
49
|
+
return _geometry.degrees;
|
|
50
|
+
},
|
|
51
|
+
filterKeyPoints: function() {
|
|
52
|
+
return _geometry.filterKeyPoints;
|
|
53
|
+
},
|
|
54
|
+
getAngle: function() {
|
|
55
|
+
return _geometry.getAngle;
|
|
56
|
+
},
|
|
57
|
+
getBestPointIndex: function() {
|
|
58
|
+
return _geometry.getBestPointIndex;
|
|
59
|
+
},
|
|
60
|
+
getCenter: function() {
|
|
61
|
+
return _geometry.getCenter;
|
|
62
|
+
},
|
|
63
|
+
getDistance: function() {
|
|
64
|
+
return _geometry.getDistance;
|
|
65
|
+
},
|
|
66
|
+
getPositionTheta: function() {
|
|
67
|
+
return _geometry.getPositionTheta;
|
|
68
|
+
},
|
|
69
|
+
getRotate: function() {
|
|
70
|
+
return _geometry.getRotate;
|
|
71
|
+
},
|
|
72
|
+
getVectorTheta: function() {
|
|
73
|
+
return _geometry.getVectorTheta;
|
|
74
|
+
},
|
|
75
|
+
hex2rgb: function() {
|
|
76
|
+
return _utils.hex2rgb;
|
|
77
|
+
},
|
|
78
|
+
loop: function() {
|
|
79
|
+
return _loop.loop;
|
|
80
|
+
},
|
|
81
|
+
lower2camel: function() {
|
|
82
|
+
return _str.lower2camel;
|
|
83
|
+
},
|
|
84
|
+
orderByDistance: function() {
|
|
85
|
+
return _geometry.orderByDistance;
|
|
86
|
+
},
|
|
87
|
+
radians: function() {
|
|
88
|
+
return _geometry.radians;
|
|
89
|
+
},
|
|
90
|
+
random: function() {
|
|
91
|
+
return _random.random;
|
|
92
|
+
},
|
|
93
|
+
randomRangeNum: function() {
|
|
94
|
+
return _random.randomRangeNum;
|
|
95
|
+
},
|
|
96
|
+
sleep: function() {
|
|
97
|
+
return _sleep.sleep;
|
|
98
|
+
},
|
|
99
|
+
superFactory: function() {
|
|
100
|
+
return _factory.superFactory;
|
|
101
|
+
},
|
|
102
|
+
throttle: function() {
|
|
103
|
+
return _throttle.throttle;
|
|
104
|
+
},
|
|
105
|
+
waitFor: function() {
|
|
106
|
+
return _loop.waitFor;
|
|
7
107
|
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
108
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Object.defineProperty
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Object.defineProperty(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
109
|
+
const _debounce = require("./debounce");
|
|
110
|
+
const _utils = require("./color/utils");
|
|
111
|
+
const _emitter = require("./emitter");
|
|
112
|
+
const _factory = require("./factory");
|
|
113
|
+
const _loop = require("./loop");
|
|
114
|
+
const _queue = require("./queue");
|
|
115
|
+
const _random = require("./random");
|
|
116
|
+
const _sleep = require("./sleep");
|
|
117
|
+
const _throttle = require("./throttle");
|
|
118
|
+
const _trigger = require("./trigger");
|
|
119
|
+
const _base64 = /*#__PURE__*/ _interop_require_wildcard(require("./base64"));
|
|
120
|
+
const _stack = require("./stack");
|
|
121
|
+
const _watchdog = require("./watch-dog");
|
|
122
|
+
const _level = require("./level");
|
|
123
|
+
const _promise = require("./promise");
|
|
124
|
+
const _geometry = require("./math/geometry");
|
|
125
|
+
const _str = require("./str");
|
|
126
|
+
const _regexplist = require("./regexp-list");
|
|
127
|
+
const _sensor = require("./filter/sensor");
|
|
128
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
129
|
+
if (typeof WeakMap !== "function") return null;
|
|
130
|
+
var cacheBabelInterop = new WeakMap();
|
|
131
|
+
var cacheNodeInterop = new WeakMap();
|
|
132
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
133
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
134
|
+
})(nodeInterop);
|
|
135
|
+
}
|
|
136
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
137
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
138
|
+
return obj;
|
|
139
|
+
}
|
|
140
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
141
|
+
return {
|
|
142
|
+
default: obj
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
146
|
+
if (cache && cache.has(obj)) {
|
|
147
|
+
return cache.get(obj);
|
|
148
|
+
}
|
|
149
|
+
var newObj = {
|
|
150
|
+
__proto__: null
|
|
151
|
+
};
|
|
152
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
153
|
+
for(var key in obj){
|
|
154
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
155
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
156
|
+
if (desc && (desc.get || desc.set)) {
|
|
157
|
+
Object.defineProperty(newObj, key, desc);
|
|
158
|
+
} else {
|
|
159
|
+
newObj[key] = obj[key];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
newObj.default = obj;
|
|
164
|
+
if (cache) {
|
|
165
|
+
cache.set(obj, newObj);
|
|
166
|
+
}
|
|
167
|
+
return newObj;
|
|
168
|
+
}
|
package/lib/level/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Level", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Level;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class Level {
|
|
5
12
|
config;
|
|
6
13
|
step;
|
|
7
|
-
constructor(props)
|
|
14
|
+
constructor(props){
|
|
8
15
|
this.config = props;
|
|
9
16
|
this.step = (this.config.max - this.config.min) / (this.config.count - 2);
|
|
10
17
|
}
|
|
@@ -15,7 +22,7 @@ class Level {
|
|
|
15
22
|
if (value >= this.config.max) {
|
|
16
23
|
return this.config.count;
|
|
17
24
|
}
|
|
18
|
-
for
|
|
25
|
+
for(let i = 2, v = this.config.min + this.step; v < this.config.max + this.step; v += this.step, i += 1){
|
|
19
26
|
if (value < v) {
|
|
20
27
|
return i;
|
|
21
28
|
}
|
|
@@ -23,4 +30,3 @@ class Level {
|
|
|
23
30
|
return this.config.count;
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
|
-
exports.Level = Level;
|
package/lib/loop/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ type WaitForBool = () => boolean | Promise<boolean>;
|
|
|
17
17
|
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
18
18
|
*/
|
|
19
19
|
export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
|
|
20
|
-
checkTime?: number
|
|
21
|
-
timeout?: number
|
|
20
|
+
checkTime?: number;
|
|
21
|
+
timeout?: number;
|
|
22
22
|
}) => Promise<unknown>;
|
|
23
23
|
export {};
|
package/lib/loop/index.js
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
loop: function() {
|
|
13
|
+
return loop;
|
|
14
|
+
},
|
|
15
|
+
waitFor: function() {
|
|
16
|
+
return waitFor;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _sleep = require("../sleep");
|
|
20
|
+
const loop = (cb, time)=>{
|
|
13
21
|
let onOff = true;
|
|
14
|
-
let stop = ()
|
|
22
|
+
let stop = ()=>{
|
|
15
23
|
onOff = false;
|
|
16
24
|
};
|
|
17
|
-
let fn = async ()
|
|
25
|
+
let fn = async ()=>{
|
|
18
26
|
try {
|
|
19
27
|
await cb();
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
28
|
+
} catch (err) {
|
|
22
29
|
console.log(err);
|
|
23
30
|
}
|
|
24
|
-
await (0,
|
|
31
|
+
await (0, _sleep.sleep)(time);
|
|
25
32
|
if (onOff) {
|
|
26
33
|
fn();
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
34
|
+
} else {
|
|
29
35
|
fn = null;
|
|
30
36
|
cb = null;
|
|
31
37
|
stop = null;
|
|
@@ -36,20 +42,10 @@ const loop = (cb, time) => {
|
|
|
36
42
|
fn();
|
|
37
43
|
return stop;
|
|
38
44
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
42
|
-
*
|
|
43
|
-
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
44
|
-
* @param {Object} options - optional parameters for checkTime and timeout
|
|
45
|
-
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
46
|
-
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
47
|
-
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
48
|
-
*/
|
|
49
|
-
const waitFor = (bool, { checkTime, timeout } = {}) => {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
45
|
+
const waitFor = (bool, { checkTime, timeout } = {})=>{
|
|
46
|
+
return new Promise((resolve, reject)=>{
|
|
51
47
|
let _timeout;
|
|
52
|
-
let stop =
|
|
48
|
+
let stop = loop(async ()=>{
|
|
53
49
|
const res = await bool();
|
|
54
50
|
if (res) {
|
|
55
51
|
if (typeof stop === 'function') {
|
|
@@ -66,7 +62,7 @@ const waitFor = (bool, { checkTime, timeout } = {}) => {
|
|
|
66
62
|
}
|
|
67
63
|
}, checkTime || 100);
|
|
68
64
|
if (timeout) {
|
|
69
|
-
_timeout = setTimeout(()
|
|
65
|
+
_timeout = setTimeout(()=>{
|
|
70
66
|
if (typeof stop === 'function') {
|
|
71
67
|
stop();
|
|
72
68
|
}
|
|
@@ -82,4 +78,3 @@ const waitFor = (bool, { checkTime, timeout } = {}) => {
|
|
|
82
78
|
}
|
|
83
79
|
});
|
|
84
80
|
};
|
|
85
|
-
exports.waitFor = waitFor;
|
package/lib/math/geometry.js
CHANGED
|
@@ -1,109 +1,149 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
degrees: function() {
|
|
13
|
+
return degrees;
|
|
14
|
+
},
|
|
15
|
+
filterKeyPoints: function() {
|
|
16
|
+
return filterKeyPoints;
|
|
17
|
+
},
|
|
18
|
+
getAngle: function() {
|
|
19
|
+
return getAngle;
|
|
20
|
+
},
|
|
21
|
+
getBestPointIndex: function() {
|
|
22
|
+
return getBestPointIndex;
|
|
23
|
+
},
|
|
24
|
+
getCenter: function() {
|
|
25
|
+
return getCenter;
|
|
26
|
+
},
|
|
27
|
+
getDistance: function() {
|
|
28
|
+
return getDistance;
|
|
29
|
+
},
|
|
30
|
+
getPositionTheta: function() {
|
|
31
|
+
return getPositionTheta;
|
|
32
|
+
},
|
|
33
|
+
getRotate: function() {
|
|
34
|
+
return getRotate;
|
|
35
|
+
},
|
|
36
|
+
getVectorTheta: function() {
|
|
37
|
+
return getVectorTheta;
|
|
38
|
+
},
|
|
39
|
+
orderByDistance: function() {
|
|
40
|
+
return orderByDistance;
|
|
41
|
+
},
|
|
42
|
+
radians: function() {
|
|
43
|
+
return radians;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const getDistance = (a, b)=>{
|
|
6
47
|
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
7
48
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const degrees = (rad) => {
|
|
11
|
-
return (rad * 180) / Math.PI;
|
|
49
|
+
const degrees = (rad)=>{
|
|
50
|
+
return rad * 180 / Math.PI;
|
|
12
51
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const radians = (deg) => {
|
|
16
|
-
return (deg * Math.PI) / 180;
|
|
52
|
+
const radians = (deg)=>{
|
|
53
|
+
return deg * Math.PI / 180;
|
|
17
54
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getAngle = ({ w, h }) => {
|
|
21
|
-
return (0, exports.degrees)(Math.atan2(h, w));
|
|
55
|
+
const getAngle = ({ w, h })=>{
|
|
56
|
+
return degrees(Math.atan2(h, w));
|
|
22
57
|
};
|
|
23
|
-
exports.getAngle = getAngle;
|
|
24
|
-
// 关键点过滤
|
|
25
58
|
function filterKeyPoints(list, len = 0.5) {
|
|
26
59
|
if (list.length < 3 || len <= 0) {
|
|
27
60
|
return list;
|
|
28
61
|
}
|
|
29
62
|
let last;
|
|
30
|
-
return list.filter((item, i)
|
|
31
|
-
if (i > 0 &&
|
|
63
|
+
return list.filter((item, i)=>{
|
|
64
|
+
if (i > 0 && getDistance(last, item) < len) {
|
|
32
65
|
return false;
|
|
33
66
|
}
|
|
34
67
|
last = list[i];
|
|
35
68
|
return true;
|
|
36
69
|
});
|
|
37
70
|
}
|
|
38
|
-
exports.filterKeyPoints = filterKeyPoints;
|
|
39
|
-
// 获取中心点坐标
|
|
40
71
|
function getCenter(list) {
|
|
41
|
-
const tmp = [
|
|
42
|
-
|
|
72
|
+
const tmp = [
|
|
73
|
+
0,
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
for (const item of list){
|
|
43
77
|
if (Array.isArray(item)) {
|
|
44
78
|
tmp[0] += item[0];
|
|
45
79
|
tmp[1] += item[1];
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
80
|
+
} else {
|
|
48
81
|
tmp[0] += item.x;
|
|
49
82
|
tmp[1] += item.y;
|
|
50
83
|
}
|
|
51
84
|
}
|
|
52
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
x: tmp[0] / list.length,
|
|
87
|
+
y: tmp[1] / list.length
|
|
88
|
+
};
|
|
53
89
|
}
|
|
54
|
-
exports.getCenter = getCenter;
|
|
55
|
-
// 2D旋转
|
|
56
90
|
function getRotate(data, theta) {
|
|
57
91
|
const x = Math.cos(theta) * data[0] - Math.sin(theta) * data[1];
|
|
58
92
|
const y = Math.sin(theta) * data[0] + Math.cos(theta) * data[1];
|
|
59
|
-
return [
|
|
93
|
+
return [
|
|
94
|
+
x,
|
|
95
|
+
y
|
|
96
|
+
];
|
|
60
97
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
98
|
+
const getPositionTheta = (a, b)=>{
|
|
99
|
+
const vector = {
|
|
100
|
+
x: b.x - a.x,
|
|
101
|
+
y: b.y - a.y
|
|
102
|
+
};
|
|
65
103
|
return Math.atan2(vector.y, vector.x);
|
|
66
104
|
};
|
|
67
|
-
|
|
68
|
-
// 获取距离和方向最佳的位置点
|
|
69
|
-
const getBestPointIndex = (points, pose) => {
|
|
105
|
+
const getBestPointIndex = (points, pose)=>{
|
|
70
106
|
if (points.length < 2) {
|
|
71
107
|
return 0;
|
|
72
108
|
}
|
|
73
109
|
const temp = [];
|
|
74
110
|
let minDistance = Infinity;
|
|
75
111
|
let index = 0;
|
|
76
|
-
for (const item of points)
|
|
77
|
-
const distance =
|
|
78
|
-
const theta =
|
|
112
|
+
for (const item of points){
|
|
113
|
+
const distance = getDistance(item, pose);
|
|
114
|
+
const theta = getPositionTheta(pose, item) - pose.theta;
|
|
79
115
|
if (minDistance > distance) {
|
|
80
116
|
minDistance = distance;
|
|
81
117
|
}
|
|
82
|
-
temp.push({
|
|
118
|
+
temp.push({
|
|
119
|
+
...item,
|
|
120
|
+
index,
|
|
121
|
+
distance,
|
|
122
|
+
theta
|
|
123
|
+
});
|
|
83
124
|
index += 1;
|
|
84
125
|
}
|
|
85
|
-
const results = temp
|
|
86
|
-
.filter((item) => item.distance - minDistance < 0.1)
|
|
87
|
-
.sort((a, b) => a.theta - b.theta);
|
|
126
|
+
const results = temp.filter((item)=>item.distance - minDistance < 0.1).sort((a, b)=>a.theta - b.theta);
|
|
88
127
|
return results[0].index;
|
|
89
128
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
129
|
+
const orderByDistance = (points, pose = {
|
|
130
|
+
x: 0,
|
|
131
|
+
y: 0,
|
|
132
|
+
theta: 0
|
|
133
|
+
})=>{
|
|
93
134
|
let current = pose;
|
|
94
135
|
const results = [];
|
|
95
|
-
const arr = [
|
|
96
|
-
|
|
97
|
-
|
|
136
|
+
const arr = [
|
|
137
|
+
...points
|
|
138
|
+
];
|
|
139
|
+
while(arr.length > 0){
|
|
140
|
+
const index = getBestPointIndex(arr, current);
|
|
98
141
|
results.push(arr[index]);
|
|
99
142
|
current = arr[index];
|
|
100
143
|
arr.splice(index, 1);
|
|
101
144
|
}
|
|
102
145
|
return results;
|
|
103
146
|
};
|
|
104
|
-
|
|
105
|
-
// 获取向量a到向量b的夹角
|
|
106
|
-
const getVectorTheta = (a, b) => {
|
|
147
|
+
const getVectorTheta = (a, b)=>{
|
|
107
148
|
return Math.atan2(b.y, b.x) - Math.atan2(a.y, a.x);
|
|
108
149
|
};
|
|
109
|
-
exports.getVectorTheta = getVectorTheta;
|
package/lib/promise/index.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callbackToPromise = void 0;
|
|
4
1
|
// 回调函数转异步函数
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "callbackToPromise", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return callbackToPromise;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const callbackToPromise = (fn)=>{
|
|
13
|
+
return (...args)=>new Promise((resolve, reject)=>{
|
|
14
|
+
fn(...args, (err, ...rest)=>{
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(err);
|
|
17
|
+
}
|
|
18
|
+
if (rest.length < 2) {
|
|
19
|
+
resolve(rest[0]);
|
|
20
|
+
} else {
|
|
21
|
+
resolve([
|
|
22
|
+
...rest
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
fn = null;
|
|
17
27
|
});
|
|
18
|
-
fn = null;
|
|
19
|
-
});
|
|
20
28
|
};
|
|
21
|
-
exports.callbackToPromise = callbackToPromise;
|