fast-astar 1.0.5 → 2.0.0

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/wasm.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class AstarGrid {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ batchFindPaths(requests: Int32Array): Int32Array;
8
+ clearObstacles(): void;
9
+ findPath(start_x: number, start_y: number, end_x: number, end_y: number, optimal_result: boolean): Int32Array;
10
+ getHeight(): number;
11
+ getObstacleCount(): number;
12
+ getWidth(): number;
13
+ isWalkable(x: number, y: number): boolean;
14
+ constructor(width: number, height: number);
15
+ setObstacle(x: number, y: number, is_obstacle: boolean): void;
16
+ setObstaclesBatch(obstacles_data: Uint8Array): void;
17
+ setObstaclesFromCoords(coords: Int32Array): void;
18
+ }
19
+
20
+ export class AstarGridSparse {
21
+ free(): void;
22
+ [Symbol.dispose](): void;
23
+ clearObstacles(): void;
24
+ findPath(start_x: bigint, start_y: bigint, end_x: bigint, end_y: bigint, optimal_result: boolean): Int32Array;
25
+ getHeight(): bigint;
26
+ getObstacleCount(): number;
27
+ getWidth(): bigint;
28
+ constructor(width: bigint, height: bigint);
29
+ setObstacle(x: bigint, y: bigint, is_obstacle: boolean): void;
30
+ setObstaclesFromCoords(coords: Int32Array): void;
31
+ }
32
+
33
+ export function getVersion(): string;
34
+
35
+ export function recommendedImpl(width: bigint, height: bigint): number;
36
+
37
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
38
+
39
+ export interface InitOutput {
40
+ readonly memory: WebAssembly.Memory;
41
+ readonly __wbg_astargrid_free: (a: number, b: number) => void;
42
+ readonly __wbg_astargridsparse_free: (a: number, b: number) => void;
43
+ readonly astargrid_batchFindPaths: (a: number, b: number, c: number, d: number) => void;
44
+ readonly astargrid_clearObstacles: (a: number) => void;
45
+ readonly astargrid_findPath: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
46
+ readonly astargrid_getHeight: (a: number) => number;
47
+ readonly astargrid_getObstacleCount: (a: number) => number;
48
+ readonly astargrid_getWidth: (a: number) => number;
49
+ readonly astargrid_isWalkable: (a: number, b: number, c: number) => number;
50
+ readonly astargrid_new: (a: number, b: number) => number;
51
+ readonly astargrid_setObstacle: (a: number, b: number, c: number, d: number) => void;
52
+ readonly astargrid_setObstaclesBatch: (a: number, b: number, c: number) => void;
53
+ readonly astargrid_setObstaclesFromCoords: (a: number, b: number, c: number) => void;
54
+ readonly astargridsparse_clearObstacles: (a: number) => void;
55
+ readonly astargridsparse_findPath: (a: number, b: number, c: bigint, d: bigint, e: bigint, f: bigint, g: number) => void;
56
+ readonly astargridsparse_getHeight: (a: number) => bigint;
57
+ readonly astargridsparse_getObstacleCount: (a: number) => number;
58
+ readonly astargridsparse_getWidth: (a: number) => bigint;
59
+ readonly astargridsparse_new: (a: bigint, b: bigint) => number;
60
+ readonly astargridsparse_setObstacle: (a: number, b: bigint, c: bigint, d: number) => void;
61
+ readonly astargridsparse_setObstaclesFromCoords: (a: number, b: number, c: number) => void;
62
+ readonly getVersion: (a: number) => void;
63
+ readonly recommendedImpl: (a: bigint, b: bigint) => number;
64
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
65
+ readonly __wbindgen_export: (a: number, b: number) => number;
66
+ readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
67
+ }
68
+
69
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
70
+
71
+ /**
72
+ * Instantiates the given `module`, which can either be bytes or
73
+ * a precompiled `WebAssembly.Module`.
74
+ *
75
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
76
+ *
77
+ * @returns {InitOutput}
78
+ */
79
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
80
+
81
+ /**
82
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
83
+ * for everything else, calls `WebAssembly.instantiate` directly.
84
+ *
85
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
86
+ *
87
+ * @returns {Promise<InitOutput>}
88
+ */
89
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/wasm.js ADDED
@@ -0,0 +1,388 @@
1
+ /* @ts-self-types="./astar_wasm.d.ts" */
2
+ export class AstarGrid {
3
+ __destroy_into_raw() {
4
+ const ptr = this.__wbg_ptr;
5
+ this.__wbg_ptr = 0;
6
+ AstarGridFinalization.unregister(this);
7
+ return ptr;
8
+ }
9
+ free() {
10
+ const ptr = this.__destroy_into_raw();
11
+ wasm.__wbg_astargrid_free(ptr, 0);
12
+ }
13
+ /**
14
+ * @param {Int32Array} requests
15
+ * @returns {Int32Array}
16
+ */
17
+ batchFindPaths(requests) {
18
+ try {
19
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
20
+ const ptr0 = passArray32ToWasm0(requests, wasm.__wbindgen_export);
21
+ const len0 = WASM_VECTOR_LEN;
22
+ wasm.astargrid_batchFindPaths(retptr, this.__wbg_ptr, ptr0, len0);
23
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
24
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
25
+ var v2 = getArrayI32FromWasm0(r0, r1).slice();
26
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
27
+ return v2;
28
+ } finally {
29
+ wasm.__wbindgen_add_to_stack_pointer(16);
30
+ }
31
+ }
32
+ clearObstacles() {
33
+ wasm.astargrid_clearObstacles(this.__wbg_ptr);
34
+ }
35
+ /**
36
+ * @param {number} start_x
37
+ * @param {number} start_y
38
+ * @param {number} end_x
39
+ * @param {number} end_y
40
+ * @param {boolean} optimal_result
41
+ * @returns {Int32Array}
42
+ */
43
+ findPath(start_x, start_y, end_x, end_y, optimal_result) {
44
+ try {
45
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
46
+ wasm.astargrid_findPath(retptr, this.__wbg_ptr, start_x, start_y, end_x, end_y, optimal_result);
47
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
48
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
49
+ var v1 = getArrayI32FromWasm0(r0, r1).slice();
50
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
51
+ return v1;
52
+ } finally {
53
+ wasm.__wbindgen_add_to_stack_pointer(16);
54
+ }
55
+ }
56
+ /**
57
+ * @returns {number}
58
+ */
59
+ getHeight() {
60
+ const ret = wasm.astargrid_getHeight(this.__wbg_ptr);
61
+ return ret;
62
+ }
63
+ /**
64
+ * @returns {number}
65
+ */
66
+ getObstacleCount() {
67
+ const ret = wasm.astargrid_getObstacleCount(this.__wbg_ptr);
68
+ return ret >>> 0;
69
+ }
70
+ /**
71
+ * @returns {number}
72
+ */
73
+ getWidth() {
74
+ const ret = wasm.astargrid_getWidth(this.__wbg_ptr);
75
+ return ret;
76
+ }
77
+ /**
78
+ * @param {number} x
79
+ * @param {number} y
80
+ * @returns {boolean}
81
+ */
82
+ isWalkable(x, y) {
83
+ const ret = wasm.astargrid_isWalkable(this.__wbg_ptr, x, y);
84
+ return ret !== 0;
85
+ }
86
+ /**
87
+ * @param {number} width
88
+ * @param {number} height
89
+ */
90
+ constructor(width, height) {
91
+ const ret = wasm.astargrid_new(width, height);
92
+ this.__wbg_ptr = ret >>> 0;
93
+ AstarGridFinalization.register(this, this.__wbg_ptr, this);
94
+ return this;
95
+ }
96
+ /**
97
+ * @param {number} x
98
+ * @param {number} y
99
+ * @param {boolean} is_obstacle
100
+ */
101
+ setObstacle(x, y, is_obstacle) {
102
+ wasm.astargrid_setObstacle(this.__wbg_ptr, x, y, is_obstacle);
103
+ }
104
+ /**
105
+ * @param {Uint8Array} obstacles_data
106
+ */
107
+ setObstaclesBatch(obstacles_data) {
108
+ const ptr0 = passArray8ToWasm0(obstacles_data, wasm.__wbindgen_export);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ wasm.astargrid_setObstaclesBatch(this.__wbg_ptr, ptr0, len0);
111
+ }
112
+ /**
113
+ * @param {Int32Array} coords
114
+ */
115
+ setObstaclesFromCoords(coords) {
116
+ const ptr0 = passArray32ToWasm0(coords, wasm.__wbindgen_export);
117
+ const len0 = WASM_VECTOR_LEN;
118
+ wasm.astargrid_setObstaclesFromCoords(this.__wbg_ptr, ptr0, len0);
119
+ }
120
+ }
121
+ if (Symbol.dispose) AstarGrid.prototype[Symbol.dispose] = AstarGrid.prototype.free;
122
+ export class AstarGridSparse {
123
+ __destroy_into_raw() {
124
+ const ptr = this.__wbg_ptr;
125
+ this.__wbg_ptr = 0;
126
+ AstarGridSparseFinalization.unregister(this);
127
+ return ptr;
128
+ }
129
+ free() {
130
+ const ptr = this.__destroy_into_raw();
131
+ wasm.__wbg_astargridsparse_free(ptr, 0);
132
+ }
133
+ clearObstacles() {
134
+ wasm.astargridsparse_clearObstacles(this.__wbg_ptr);
135
+ }
136
+ /**
137
+ * @param {bigint} start_x
138
+ * @param {bigint} start_y
139
+ * @param {bigint} end_x
140
+ * @param {bigint} end_y
141
+ * @param {boolean} optimal_result
142
+ * @returns {Int32Array}
143
+ */
144
+ findPath(start_x, start_y, end_x, end_y, optimal_result) {
145
+ try {
146
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
147
+ wasm.astargridsparse_findPath(retptr, this.__wbg_ptr, start_x, start_y, end_x, end_y, optimal_result);
148
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
149
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
150
+ var v1 = getArrayI32FromWasm0(r0, r1).slice();
151
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
152
+ return v1;
153
+ } finally {
154
+ wasm.__wbindgen_add_to_stack_pointer(16);
155
+ }
156
+ }
157
+ /**
158
+ * @returns {bigint}
159
+ */
160
+ getHeight() {
161
+ const ret = wasm.astargridsparse_getHeight(this.__wbg_ptr);
162
+ return ret;
163
+ }
164
+ /**
165
+ * @returns {number}
166
+ */
167
+ getObstacleCount() {
168
+ const ret = wasm.astargridsparse_getObstacleCount(this.__wbg_ptr);
169
+ return ret >>> 0;
170
+ }
171
+ /**
172
+ * @returns {bigint}
173
+ */
174
+ getWidth() {
175
+ const ret = wasm.astargridsparse_getWidth(this.__wbg_ptr);
176
+ return ret;
177
+ }
178
+ /**
179
+ * @param {bigint} width
180
+ * @param {bigint} height
181
+ */
182
+ constructor(width, height) {
183
+ const ret = wasm.astargridsparse_new(width, height);
184
+ this.__wbg_ptr = ret >>> 0;
185
+ AstarGridSparseFinalization.register(this, this.__wbg_ptr, this);
186
+ return this;
187
+ }
188
+ /**
189
+ * @param {bigint} x
190
+ * @param {bigint} y
191
+ * @param {boolean} is_obstacle
192
+ */
193
+ setObstacle(x, y, is_obstacle) {
194
+ wasm.astargridsparse_setObstacle(this.__wbg_ptr, x, y, is_obstacle);
195
+ }
196
+ /**
197
+ * @param {Int32Array} coords
198
+ */
199
+ setObstaclesFromCoords(coords) {
200
+ const ptr0 = passArray32ToWasm0(coords, wasm.__wbindgen_export);
201
+ const len0 = WASM_VECTOR_LEN;
202
+ wasm.astargridsparse_setObstaclesFromCoords(this.__wbg_ptr, ptr0, len0);
203
+ }
204
+ }
205
+ if (Symbol.dispose) AstarGridSparse.prototype[Symbol.dispose] = AstarGridSparse.prototype.free;
206
+ /**
207
+ * @returns {string}
208
+ */
209
+ export function getVersion() {
210
+ let deferred1_0;
211
+ let deferred1_1;
212
+ try {
213
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
214
+ wasm.getVersion(retptr);
215
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
216
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
217
+ deferred1_0 = r0;
218
+ deferred1_1 = r1;
219
+ return getStringFromWasm0(r0, r1);
220
+ } finally {
221
+ wasm.__wbindgen_add_to_stack_pointer(16);
222
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
223
+ }
224
+ }
225
+ /**
226
+ * @param {bigint} width
227
+ * @param {bigint} height
228
+ * @returns {number}
229
+ */
230
+ export function recommendedImpl(width, height) {
231
+ const ret = wasm.recommendedImpl(width, height);
232
+ return ret;
233
+ }
234
+ function __wbg_get_imports() {
235
+ const import0 = {
236
+ __proto__: null,
237
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
238
+ throw new Error(getStringFromWasm0(arg0, arg1));
239
+ },
240
+ };
241
+ return {
242
+ __proto__: null,
243
+ "./astar_wasm_bg.js": import0,
244
+ };
245
+ }
246
+ const AstarGridFinalization = (typeof FinalizationRegistry === 'undefined')
247
+ ? { register: () => {}, unregister: () => {} }
248
+ : new FinalizationRegistry(ptr => wasm.__wbg_astargrid_free(ptr >>> 0, 1));
249
+ const AstarGridSparseFinalization = (typeof FinalizationRegistry === 'undefined')
250
+ ? { register: () => {}, unregister: () => {} }
251
+ : new FinalizationRegistry(ptr => wasm.__wbg_astargridsparse_free(ptr >>> 0, 1));
252
+ function getArrayI32FromWasm0(ptr, len) {
253
+ ptr = ptr >>> 0;
254
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
255
+ }
256
+ let cachedDataViewMemory0 = null;
257
+ function getDataViewMemory0() {
258
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
259
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
260
+ }
261
+ return cachedDataViewMemory0;
262
+ }
263
+ let cachedInt32ArrayMemory0 = null;
264
+ function getInt32ArrayMemory0() {
265
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
266
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
267
+ }
268
+ return cachedInt32ArrayMemory0;
269
+ }
270
+ function getStringFromWasm0(ptr, len) {
271
+ ptr = ptr >>> 0;
272
+ return decodeText(ptr, len);
273
+ }
274
+ let cachedUint32ArrayMemory0 = null;
275
+ function getUint32ArrayMemory0() {
276
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
277
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
278
+ }
279
+ return cachedUint32ArrayMemory0;
280
+ }
281
+ let cachedUint8ArrayMemory0 = null;
282
+ function getUint8ArrayMemory0() {
283
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
284
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
285
+ }
286
+ return cachedUint8ArrayMemory0;
287
+ }
288
+ function passArray32ToWasm0(arg, malloc) {
289
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
290
+ getUint32ArrayMemory0().set(arg, ptr / 4);
291
+ WASM_VECTOR_LEN = arg.length;
292
+ return ptr;
293
+ }
294
+ function passArray8ToWasm0(arg, malloc) {
295
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
296
+ getUint8ArrayMemory0().set(arg, ptr / 1);
297
+ WASM_VECTOR_LEN = arg.length;
298
+ return ptr;
299
+ }
300
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
301
+ cachedTextDecoder.decode();
302
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
303
+ let numBytesDecoded = 0;
304
+ function decodeText(ptr, len) {
305
+ numBytesDecoded += len;
306
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
307
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
308
+ cachedTextDecoder.decode();
309
+ numBytesDecoded = len;
310
+ }
311
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
312
+ }
313
+ let WASM_VECTOR_LEN = 0;
314
+ let wasmModule, wasm;
315
+ function __wbg_finalize_init(instance, module) {
316
+ wasm = instance.exports;
317
+ wasmModule = module;
318
+ cachedDataViewMemory0 = null;
319
+ cachedInt32ArrayMemory0 = null;
320
+ cachedUint32ArrayMemory0 = null;
321
+ cachedUint8ArrayMemory0 = null;
322
+ return wasm;
323
+ }
324
+ async function __wbg_load(module, imports) {
325
+ if (typeof Response === 'function' && module instanceof Response) {
326
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
327
+ try {
328
+ return await WebAssembly.instantiateStreaming(module, imports);
329
+ } catch (e) {
330
+ const validResponse = module.ok && expectedResponseType(module.type);
331
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
332
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
333
+ } else { throw e; }
334
+ }
335
+ }
336
+ const bytes = await module.arrayBuffer();
337
+ return await WebAssembly.instantiate(bytes, imports);
338
+ } else {
339
+ const instance = await WebAssembly.instantiate(module, imports);
340
+ if (instance instanceof WebAssembly.Instance) {
341
+ return { instance, module };
342
+ } else {
343
+ return instance;
344
+ }
345
+ }
346
+ function expectedResponseType(type) {
347
+ switch (type) {
348
+ case 'basic': case 'cors': case 'default': return true;
349
+ }
350
+ return false;
351
+ }
352
+ }
353
+ function initSync(module) {
354
+ if (wasm !== undefined) return wasm;
355
+ if (module !== undefined) {
356
+ if (Object.getPrototypeOf(module) === Object.prototype) {
357
+ ({module} = module)
358
+ } else {
359
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
360
+ }
361
+ }
362
+ const imports = __wbg_get_imports();
363
+ if (!(module instanceof WebAssembly.Module)) {
364
+ module = new WebAssembly.Module(module);
365
+ }
366
+ const instance = new WebAssembly.Instance(module, imports);
367
+ return __wbg_finalize_init(instance, module);
368
+ }
369
+ async function __wbg_init(module_or_path) {
370
+ if (wasm !== undefined) return wasm;
371
+ if (module_or_path !== undefined) {
372
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
373
+ ({module_or_path} = module_or_path)
374
+ } else {
375
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
376
+ }
377
+ }
378
+ if (module_or_path === undefined) {
379
+ module_or_path = new URL('astar.wasm', import.meta.url);
380
+ }
381
+ const imports = __wbg_get_imports();
382
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
383
+ module_or_path = fetch(module_or_path);
384
+ }
385
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
386
+ return __wbg_finalize_init(instance, module);
387
+ }
388
+ export { initSync, __wbg_init as default };
package/dist/Astar.js DELETED
@@ -1,2 +0,0 @@
1
- /*! Project:astar, Create:FWS 2019.10.29 15:21, Update:FWS 2019.10.30 10:16 */
2
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"function"==typeof define&&(define.cmd||define.hjs)?define(function(require,exports,e){e.exports=t()}):e.Astar=t()}(this,function(){"use strict";var e=function(e){return e.split(",").map(Number)};return function(){function t(e){var t=this;t.grid=e,t.openList={},t.closeList={},t.current}return t.prototype.search=function(e,t,r){var n=this,i={rightAngle:!1,optimalResult:!0};r=n.searchOption=r||{};for(var o in i)r[o]===undefined&&(r[o]=i[o]);n.start=e,n.end=t,n.grid.get(e).value=0,n.grid.set(e,"type","start"),n.grid.get(t).value=0,n.grid.set(t,"type","end");var d,u;return n.openList[e]=null,n.grid.set(e,"type","open"),(u=function(e){if(n.grid.set(e,"type","highlight"),n.grid.get(e)===n.grid.get(n.end))d=n.getBackPath(e);else{for(var t=n.getAround(e),r=0,i=t.length;r<i;r++){var o=t[r],l=n.grid.get(o);if(null!==n.openList[o])n.openList[o]=null,l.parent=e,l.g=n.g(o,e),l.h=n.h(o,n.end),l.f=n.f(o),n.grid.set(o,"type","open");else{var s=l.g,g=n.g(o,e);g<s&&(l.parent=e,l.g=g,l.f=n.f(o),n.grid.set(o,"type","update"))}}delete n.openList[e],n.closeList[e]=null,n.grid.set(e,"type","close");var f=n.getOpenListMin();f&&u(f.key)}})(e),d},t.prototype.getBackPath=function(e){var t,r=this,n=[e];return(t=function(e){var i=r.grid.get(e).parent;i&&(n.unshift(i),t(i))})(e),n},t.prototype.getOpenListMin=function(){var t,r=this;for(var n in r.openList){var i=e(n),o=r.grid.get(i);(t===undefined||o.f<t.f)&&(t=r.grid.get(i))}return t},t.prototype.getOffsetGrid=function(e,t){return[e[0]+t[0],e[1]+t[1]]},t.prototype.getAround=function(e){var t=this,r=t.searchOption,n=[],i=t.grid,o={lt:[-1,-1],t:[0,-1],rt:[1,-1],r:[1,0],rb:[1,1],b:[0,1],lb:[-1,1],l:[-1,0]},d=function(e,r){var n=i.get(t.getOffsetGrid(e,r));return n!==undefined&&n.value>0};r.rightAngle?(delete o.lt,delete o.rt,delete o.rb,delete o.lb):(d(e,o.l)&&(delete o.lt,delete o.lb),d(e,o.r)&&(delete o.rt,delete o.rb),d(e,o.t)&&(delete o.lt,delete o.rt),d(e,o.b)&&(delete o.lb,delete o.rb));for(var u in o){var l=o[u],s=[e[0]+l[0],e[1]+l[1]],g=null===t.closeList[s];s[0]>-1&&s[0]<i.col&&s[1]>-1&&s[1]<i.row&&!g&&i.get(s).value<1&&n.push(s)}return n},t.prototype.f=function(e){var t=this,r=t.grid.get(e);return r.g+r.h},t.prototype.g=function(e,t){return this.searchOption.optimalResult?(t[0]===e[0]||t[1]===e[1]?10:14)+this.grid.get(t).g:0},t.prototype.h=function(e,t){return 10*(Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]))},t}()});
package/dist/Grid.js DELETED
@@ -1,2 +0,0 @@
1
- /*! Project:astar, Create:FWS 2019.10.29 15:21, Update:FWS 2019.10.30 10:16 */
2
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):"function"==typeof define&&(define.cmd||define.hjs)?define(function(require,exports,e){e.exports=n()}):e.Grid=n()}(this,function(){"use strict";var e=function(e,n){return~~(Math.random()*(n-e+1))+e},n=function(e,n){var t=this;t.x=e,t.y=n,t.g=0,t.h=0,t.f=0,t.value=0,t.key=[e,n]};return function(){function t(e){var n=this;n.col=e.col,n.row=e.row,n.grid=n.createGrid(e.col,e.row,e.render)}return t.prototype.obstacle=function(n,t){for(var r,o=this,i=~~(o.col*o.row*n/100),u=[],f={},c=0;c<i;c++)(r=function(){u[0]=e(0,o.col-1),u[1]=e(0,o.row-1);var n=o.get(u);0===n.value?(n.value=t,f[[u[0],u[1]]]=null):r()})();return f},t.prototype.get=function(e){var n=this.grid[e[1]];return n?n[e[0]]:undefined},t.prototype.set=function(e,n,t){var r=this.get(e);r[n]=t,"function"==typeof r.render&&r.render({key:n,val:t})},t.prototype.createGrid=function(e,t,r){for(var o=[],i=0;i<t;i++)!function(t){var i=function(){for(var o=[],i=0;i<e;i++){var u=new n(i,t);"function"==typeof r&&(u.render=r),o[i]=u}return o}();o.push(i)}(i);return o},t.prototype.getData=function(){for(var e=this,n=e.grid,t=[],r=0,o=n.length;r<o;r++)!function(e,r){var o=n[e];t.push(function(){for(var e=[],n=0,t=o.length;n<t;n++)e.push(o[n].value);return e}())}(r);return t},t}()});
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- const Grid = require('./Grid'),
2
- Astar = require('./Astar');
3
- module.exports = {Grid,Astar};