bard-legends-framework 0.9.6 → 0.9.7
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/_interfaces/index.d.ts +2 -2
- package/dist/_interfaces/index.js +2 -3
- package/dist/game-entities/attachable/attachable.d.ts +6 -6
- package/dist/game-entities/attachable/attachable.js +28 -30
- package/dist/game-entities/attachable/attachable.spec.js +129 -128
- package/dist/game-entities/attachable/attachable.store.d.ts +5 -5
- package/dist/game-entities/attachable/attachable.store.js +34 -32
- package/dist/game-entities/attachable/attachable.test.js +132 -131
- package/dist/game-entities/attachable/destroyable.d.ts +13 -13
- package/dist/game-entities/attachable/destroyable.js +64 -69
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.js +125 -116
- package/dist/game-entities/attachable/helpers/referance-variable.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/referance-variable.js +47 -48
- package/dist/game-entities/attachable/interfaces.d.ts +6 -6
- package/dist/game-entities/attachable/interfaces.js +2 -3
- package/dist/game-entities/base/helpers/decorate-actions-lib.js +0 -1
- package/dist/game-entities/controller/controller.js +0 -1
- package/dist/game-entities/controller/controller.spec.js +128 -125
- package/dist/game-entities/entity/entity.spec.js +263 -293
- package/dist/game-entities/entity/helpers/view-creation.helper.d.ts +7 -7
- package/dist/game-entities/entity/helpers/view-creation.helper.js +48 -48
- package/dist/game-entities/scene/scene.spec.js +219 -223
- package/dist/game-entities/service/service.js +0 -4
- package/dist/game-entities/service/service.spec.js +265 -237
- package/dist/game-entities/service/service.test.js +4 -2
- package/dist/game-entities/update-loop.d.ts +18 -18
- package/dist/game-entities/update-loop.js +46 -28
- package/dist/game-entities/view/view.spec.js +490 -506
- package/dist/game-entities/view/view.test.js +1 -1
- package/dist/lib/animator/animations.d.ts +13 -13
- package/dist/lib/animator/animations.js +43 -40
- package/dist/lib/animator/animator.d.ts +41 -41
- package/dist/lib/animator/animator.js +194 -197
- package/dist/lib/animator/animator.spec.js +699 -612
- package/dist/lib/animator/index.js +24 -19
- package/dist/lib/libraries/animator/animations.d.ts +13 -13
- package/dist/lib/libraries/animator/animations.js +43 -40
- package/dist/lib/libraries/animator/animator.d.ts +41 -41
- package/dist/lib/libraries/animator/animator.js +194 -197
- package/dist/lib/libraries/animator/animator.spec.js +699 -612
- package/dist/lib/libraries/animator/index.js +24 -19
- package/dist/lib/libraries/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/libraries/path-finder/path-finder.js +19 -20
- package/dist/lib/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/path-finder/path-finder.js +19 -20
- package/dist/lib/services/keyboard/keyboard.d.ts +4 -4
- package/dist/lib/services/keyboard/keyboard.js +39 -31
- package/dist/lib/services/mouse/mouse.service.d.ts +8 -8
- package/dist/lib/services/mouse/mouse.service.js +65 -53
- package/dist/lib/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/lib/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/lib/update-loop.d.ts +10 -10
- package/dist/lib/update-loop.js +35 -27
- package/dist/physics/entitity-types/immovable-physics-entity.d.ts +6 -6
- package/dist/physics/entitity-types/immovable-physics-entity.js +23 -24
- package/dist/physics/entitity-types/movable-entity.d.ts +6 -6
- package/dist/physics/entitity-types/movable-entity.js +21 -22
- package/dist/physics/entitity-types/movable-physics-entity.d.ts +14 -14
- package/dist/physics/entitity-types/movable-physics-entity.js +83 -88
- package/dist/physics/entitity-types/physics-entity.d.ts +23 -23
- package/dist/physics/entitity-types/physics-entity.js +97 -88
- package/dist/physics/helpers/closest-available-space.helper.d.ts +16 -16
- package/dist/physics/helpers/closest-available-space.helper.js +98 -96
- package/dist/physics/helpers/closest-available-space.helper.spec.js +115 -68
- package/dist/physics/helpers/p2js.helper.d.ts +3 -3
- package/dist/physics/helpers/p2js.helper.js +21 -22
- package/dist/physics/helpers/shape-factory.d.ts +9 -4
- package/dist/physics/helpers/shape-factory.js +99 -75
- package/dist/physics/libs/p2js.helper.js +1 -1
- package/dist/physics/libs/position-to-grid-position-converter.d.ts +3 -3
- package/dist/physics/libs/position-to-grid-position-converter.js +15 -13
- package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +10 -5
- package/dist/physics/module//360/237/223/220services/availability-grid.service.js +77 -57
- package/dist/physics/module//360/237/223/220services/border.service.d.ts +2 -2
- package/dist/physics/module//360/237/223/220services/border.service.js +57 -37
- package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +7 -7
- package/dist/physics/module//360/237/223/220services/collisions.service.js +110 -98
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +28 -6
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +121 -89
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/materials.service.d.ts +16 -11
- package/dist/physics/module//360/237/223/220services/materials.service.js +118 -108
- package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +19 -8
- package/dist/physics/module//360/237/223/220services/path-finder.service.js +121 -82
- package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +30 -15
- package/dist/physics/module//360/237/223/220services/physics-world.service.js +122 -100
- package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/ray-casting.service.js +87 -86
- package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -4
- package/dist/physics/module//360/237/223/220services/shape-creation.service.js +113 -84
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +2 -1
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +8 -8
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +32 -33
- package/dist/physics/physics-world.d.ts +50 -34
- package/dist/physics/physics-world.js +142 -133
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.d.ts +3 -3
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.js +15 -13
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.d.ts +9 -9
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.js +82 -77
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.d.ts +18 -14
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.js +91 -79
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.d.ts +11 -11
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.js +84 -76
- package/dist/physics/sub-elements/collisions/physics-collision.d.ts +7 -7
- package/dist/physics/sub-elements/collisions/physics-collision.js +43 -44
- package/dist/physics/sub-elements/elements/physics-body-groups.d.ts +11 -11
- package/dist/physics/sub-elements/elements/physics-body-groups.js +54 -54
- package/dist/physics/sub-elements/elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/elements/physics-world-borders.d.ts +3 -3
- package/dist/physics/sub-elements/elements/physics-world-borders.js +69 -45
- package/dist/physics/sub-elements/physics-body-groups.d.ts +8 -8
- package/dist/physics/sub-elements/physics-body-groups.js +41 -42
- package/dist/physics/sub-elements/physics-collision.d.ts +16 -16
- package/dist/physics/sub-elements/physics-collision.js +141 -121
- package/dist/physics/sub-elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/physics-world-borders.d.ts +2 -2
- package/dist/physics/sub-elements/physics-world-borders.js +25 -26
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.d.ts +15 -11
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.js +59 -59
- package/dist/physics/sub-elements/raycasting/physics-explosion.d.ts +13 -6
- package/dist/physics/sub-elements/raycasting/physics-explosion.js +108 -73
- package/dist/physics/sub-elements/raycasting/ray-cast.d.ts +19 -19
- package/dist/physics/sub-elements/raycasting/ray-cast.js +93 -98
- package/dist/pixi/display-object/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/components/filters.js +106 -81
- package/dist/pixi/display-object/components/glow-effect.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-effect.js +33 -36
- package/dist/pixi/display-object/components/glow-filter.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-filter.js +33 -36
- package/dist/pixi/display-object/container-attributes.js +1 -1
- package/dist/pixi/display-object/display-object-attributes.d.ts +41 -41
- package/dist/pixi/display-object/display-object-attributes.js +148 -150
- package/dist/pixi/display-object/display-object.d.ts +17 -17
- package/dist/pixi/display-object/display-object.js +79 -75
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.js +89 -77
- package/dist/pixi/display-object/filters/base-filters/blur.filter.js +30 -30
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.js +62 -53
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.js +93 -81
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.d.ts +12 -7
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.js +120 -109
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +32 -32
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.js +92 -85
- package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +28 -28
- package/dist/pixi/display-object/filters/templates/plane.template.js +20 -20
- package/dist/pixi/display-object/filters.js +20 -4
- package/dist/pixi/display-object/objects/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/objects/components/filters.js +106 -81
- package/dist/pixi/display-object/objects/container.d.ts +2 -2
- package/dist/pixi/display-object/objects/container.js +39 -30
- package/dist/pixi/display-object/objects/graphics.d.ts +28 -28
- package/dist/pixi/display-object/objects/graphics.js +218 -202
- package/dist/pixi/display-object/objects/helpers/filters.d.ts +25 -25
- package/dist/pixi/display-object/objects/helpers/filters.js +150 -124
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.d.ts +7 -7
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.js +114 -95
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.d.ts +5 -5
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.js +81 -57
- package/dist/pixi/display-object/objects/sprite.d.ts +43 -43
- package/dist/pixi/display-object/objects/sprite.js +248 -233
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +1 -1
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +9 -9
- package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +1 -1
- package/dist/pixi/display-object/objects/text.d.ts +25 -25
- package/dist/pixi/display-object/objects/text.js +111 -102
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.d.ts +13 -9
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.js +96 -67
- package/dist/pixi/game.d.ts +1 -1
- package/dist/pixi/game.js +2 -2
- package/dist/pixi/helpers/glow-sprite-generator.d.ts +6 -6
- package/dist/pixi/helpers/glow-sprite-generator.js +99 -84
- package/dist/pixi/helpers/pixi-container.helper.d.ts +1 -1
- package/dist/pixi/helpers/pixi-container.helper.js +10 -8
- package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +1 -1
- package/dist/pixi/helpers/screen-position-to-stage.helper.js +12 -12
- package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +174 -79
- package/dist/pixi/modules/CAMERA/index.d.ts +1 -1
- package/dist/pixi/modules/CAMERA/index.js +3 -3
- package/dist/services/keyboard/keyboard.d.ts +4 -4
- package/dist/services/keyboard/keyboard.js +39 -31
- package/dist/services/mouse/mouse.service.d.ts +8 -8
- package/dist/services/mouse/mouse.service.js +65 -53
- package/dist/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/utilities/libraries/animator/animating-content/state-animation.d.ts +29 -26
- package/dist/utilities/libraries/animator/animating-content/state-animation.js +159 -165
- package/dist/utilities/libraries/animator/animating-content/state-animation.test.js +386 -375
- package/dist/utilities/libraries/animator/animator.spec.js +765 -656
- package/dist/utilities/libraries/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/grid/grid.d.ts +35 -31
- package/dist/utilities/libraries/data-structures/grid/grid.js +128 -117
- package/dist/utilities/libraries/data-structures/grid/grid.spec.js +176 -138
- package/dist/utilities/libraries/data-structures/grid/grid.test.js +218 -141
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.d.ts +3 -3
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.js +15 -13
- package/dist/utilities/libraries/data-structures/queue/queue.d.ts +21 -21
- package/dist/utilities/libraries/data-structures/queue/queue.js +63 -66
- package/dist/utilities/libraries/data-structures/queue/queue.test.js +54 -55
- package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.spec.js +122 -68
- package/dist/utilities/libraries/grid-algorithms/path-finder/path-finder.spec.js +140 -135
- package/dist/utilities/libraries/grid-algorithms/vector-field-path-finder/vector-field-path-finder.spec.js +293 -229
- package/dist/utilities/libraries/path-finder/path-finder.d.ts +7 -7
- package/dist/utilities/libraries/path-finder/path-finder.js +113 -109
- package/dist/utilities/libraries/path-finder/path-finder.spec.js +131 -106
- package/dist/utilities/services/keyboard/keyboard.d.ts +4 -4
- package/dist/utilities/services/keyboard/keyboard.js +42 -34
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.d.ts +1 -1
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.js +12 -12
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.test.js +168 -73
- package/dist/utilities/services/mouse/mouse-target-focus.service.d.ts +15 -15
- package/dist/utilities/services/mouse/mouse-target-focus.service.js +79 -76
- package/dist/utilities/services/mouse/mouse.service.d.ts +9 -9
- package/dist/utilities/services/mouse/mouse.service.js +86 -72
- package/dist/utilities/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/utilities/services/mouse/mouser-target-focus.service.js +83 -81
- package/package.json +4 -10
|
@@ -1,232 +1,296 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const vector_field_path_finder_1 = require("./vector-field-path-finder");
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const vitest_1 = require('vitest');
|
|
3
|
+
const helpers_lib_1 = require('helpers-lib');
|
|
4
|
+
const grid_1 = require('../../data-structures/grid/grid');
|
|
5
|
+
const vector_field_path_finder_1 = require('./vector-field-path-finder');
|
|
7
6
|
(0, vitest_1.describe)('VectorFieldPathFinder', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
18
|
-
[true, true],
|
|
19
|
-
[true, true]
|
|
20
|
-
]);
|
|
21
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
22
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
23
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 0 })).toBe(0);
|
|
24
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 1 })).toBe(0);
|
|
25
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 1 })).toBe(0);
|
|
26
|
-
});
|
|
27
|
-
(0, vitest_1.test)('sample 1', () => {
|
|
28
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
29
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
30
|
-
[true, true],
|
|
31
|
-
[true, true]
|
|
32
|
-
]);
|
|
33
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
34
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
35
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 0 })).toBe(10);
|
|
36
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 1 })).toBe(10);
|
|
37
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 1 })).toBe(14);
|
|
38
|
-
});
|
|
39
|
-
(0, vitest_1.test)('sample 2', () => {
|
|
40
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 1, y: 1 } };
|
|
41
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
42
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
43
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
44
|
-
[0, 0, 10],
|
|
45
|
-
[0, 0, 10],
|
|
46
|
-
[10, 10, 14]
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
(0, vitest_1.test)('sample 3', () => {
|
|
50
|
-
let targetArea = { topLeft: { x: 1, y: 1 }, bottomRight: { x: 2, y: 2 } };
|
|
51
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
52
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
53
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
54
|
-
[14, 10, 10],
|
|
55
|
-
[10, 0, 0],
|
|
56
|
-
[10, 0, 0]
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
59
|
-
(0, vitest_1.test)('complex 1', () => {
|
|
60
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
61
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
62
|
-
[true, false, true],
|
|
63
|
-
[true, true, true],
|
|
64
|
-
[false, false, true],
|
|
65
|
-
[false, false, true]
|
|
66
|
-
]);
|
|
67
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
68
|
-
let h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
69
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
70
|
-
[0, h, 28],
|
|
71
|
-
[10, 14, 24],
|
|
72
|
-
[h, h, 28],
|
|
73
|
-
[h, h, 38]
|
|
74
|
-
]);
|
|
75
|
-
});
|
|
76
|
-
(0, vitest_1.test)('complex 2', () => {
|
|
77
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 1, y: 1 } };
|
|
78
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
79
|
-
[true, true, false, true],
|
|
80
|
-
[true, true, false, true],
|
|
81
|
-
[false, false, true, true]
|
|
82
|
-
]);
|
|
83
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
84
|
-
let h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
85
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
86
|
-
[0, 0, h, 38],
|
|
87
|
-
[0, 0, h, 28],
|
|
88
|
-
[h, h, 14, 24]
|
|
89
|
-
]);
|
|
90
|
-
});
|
|
91
|
-
(0, vitest_1.test)('complex 3', () => {
|
|
92
|
-
let targetArea = { topLeft: { x: 2, y: 2 }, bottomRight: { x: 3, y: 3 } };
|
|
93
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
94
|
-
[true, true, false, true],
|
|
95
|
-
[true, true, false, true],
|
|
96
|
-
[false, false, true, true],
|
|
97
|
-
[false, false, true, true]
|
|
98
|
-
]);
|
|
99
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
100
|
-
let h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
101
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
102
|
-
[28, 24, h, 20],
|
|
103
|
-
[24, 14, h, 10],
|
|
104
|
-
[h, h, 0, 0],
|
|
105
|
-
[h, h, 0, 0]
|
|
106
|
-
]);
|
|
107
|
-
});
|
|
108
|
-
(0, vitest_1.test)('unreachable area 1', () => {
|
|
109
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
110
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
111
|
-
[true, false, true, false, true],
|
|
112
|
-
[true, false, true, false, true],
|
|
113
|
-
[true, false, false, false, true],
|
|
114
|
-
[true, false, false, false, true],
|
|
115
|
-
[true, true, true, true, true]
|
|
116
|
-
]);
|
|
117
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
118
|
-
let h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
119
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
120
|
-
[0, h, h, h, 108],
|
|
121
|
-
[10, h, h, h, 98],
|
|
122
|
-
[20, h, h, h, 88],
|
|
123
|
-
[30, h, h, h, 78],
|
|
124
|
-
[40, 44, 54, 64, 74]
|
|
125
|
-
]);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
(0, vitest_1.describe)('getDirectionToTarget', () => {
|
|
129
|
-
(0, vitest_1.test)('sample 1', () => {
|
|
130
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
131
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
132
|
-
[true, true],
|
|
133
|
-
[true, true]
|
|
134
|
-
]);
|
|
135
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
136
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 1, y: 1 })).toEqual(-helpers_lib_1.Radian.get45);
|
|
137
|
-
});
|
|
138
|
-
(0, vitest_1.test)('sample 2', () => {
|
|
139
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
140
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
141
|
-
[true, true, true],
|
|
142
|
-
[false, true, true]
|
|
143
|
-
]);
|
|
144
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
145
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toEqual(helpers_lib_1.Radian.vectorToRadian({ x: -2, y: -1 }));
|
|
146
|
-
});
|
|
147
|
-
(0, vitest_1.test)('sample 3', () => {
|
|
148
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
149
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
150
|
-
[true, false, true],
|
|
151
|
-
[true, false, true],
|
|
152
|
-
[true, true, true]
|
|
153
|
-
]);
|
|
154
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
155
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toEqual(helpers_lib_1.Radian.get180);
|
|
156
|
-
});
|
|
157
|
-
(0, vitest_1.test)('sample 4', () => {
|
|
158
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
159
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
160
|
-
[true, false, false],
|
|
161
|
-
[true, false, false]
|
|
162
|
-
]);
|
|
163
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
164
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toBeUndefined();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
(0, vitest_1.describe)('edge cases', () => {
|
|
168
|
-
(0, vitest_1.test)('should create an instance', () => {
|
|
169
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
170
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 1, y: 1 }, true);
|
|
171
|
-
(0, vitest_1.expect)(new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid)).toBeTruthy();
|
|
172
|
-
});
|
|
173
|
-
(0, vitest_1.test)('should activate unavailable target cells of the target area', () => {
|
|
174
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
175
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 1, y: 1 }, false);
|
|
176
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
177
|
-
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
178
|
-
});
|
|
179
|
-
(0, vitest_1.test)('should select closest grid cells if the target is outside of the grid', () => {
|
|
180
|
-
let targetArea = { topLeft: { x: 3, y: -1 }, bottomRight: { x: 3, y: 1 } };
|
|
181
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
182
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
183
|
-
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
184
|
-
[20, 10, 0],
|
|
185
|
-
[20, 10, 0],
|
|
186
|
-
[24, 14, 10]
|
|
187
|
-
]);
|
|
188
|
-
});
|
|
189
|
-
(0, vitest_1.test)('should return undefined if starting position and its neighbors are unreachable', () => {
|
|
190
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
191
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
192
|
-
[true, false, false],
|
|
193
|
-
[true, false, false]
|
|
194
|
-
]);
|
|
195
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
196
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toBeUndefined();
|
|
197
|
-
});
|
|
198
|
-
(0, vitest_1.test)('should find the direction if starting position is unreachable but there is a reachable neighbor', () => {
|
|
199
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
200
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
201
|
-
[true, true, false],
|
|
202
|
-
[true, false, false]
|
|
203
|
-
]);
|
|
204
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
205
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toEqual(-helpers_lib_1.Radian.get45);
|
|
206
|
-
});
|
|
207
|
-
(0, vitest_1.test)('should return undefined if starting point is inside target area', () => {
|
|
208
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 1, y: 1 } };
|
|
209
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 2, y: 2 }, true);
|
|
210
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
211
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 0, y: 0 })).toBeUndefined();
|
|
212
|
-
});
|
|
213
|
-
(0, vitest_1.test)('should return closest cell result if starting point is outside of the grid', () => {
|
|
214
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
215
|
-
let availabilityGrid = grid_1.Grid.createNew({ x: 2, y: 1 }, true);
|
|
216
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
217
|
-
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toEqual(-helpers_lib_1.Radian.get90);
|
|
218
|
-
});
|
|
219
|
-
(0, vitest_1.test)('if average direction is pointing blocked path, it should pick random available direction', () => {
|
|
220
|
-
let targetArea = { topLeft: { x: 0, y: 0 }, bottomRight: { x: 0, y: 0 } };
|
|
221
|
-
let availabilityGrid = grid_1.Grid.createByValues([
|
|
222
|
-
[true, true, true],
|
|
223
|
-
[true, false, true],
|
|
224
|
-
[true, true, true]
|
|
225
|
-
]);
|
|
226
|
-
let pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
227
|
-
let result = pathFinder.getDirectionToTarget({ x: 2, y: 2 });
|
|
228
|
-
(0, vitest_1.expect)(result === -helpers_lib_1.Radian.get90 || result === 0).toBeTruthy();
|
|
229
|
-
});
|
|
7
|
+
(0, vitest_1.describe)('weight grid', () => {
|
|
8
|
+
(0, vitest_1.test)('basic 1', () => {
|
|
9
|
+
const targetArea = {
|
|
10
|
+
topLeft: { x: 0, y: 0 },
|
|
11
|
+
bottomRight: { x: 0, y: 0 }
|
|
12
|
+
};
|
|
13
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 1, y: 1 }, true);
|
|
14
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
15
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
230
16
|
});
|
|
17
|
+
(0, vitest_1.test)('basic 2', () => {
|
|
18
|
+
const targetArea = {
|
|
19
|
+
topLeft: { x: 0, y: 0 },
|
|
20
|
+
bottomRight: { x: 1, y: 1 }
|
|
21
|
+
};
|
|
22
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
23
|
+
[true, true],
|
|
24
|
+
[true, true]
|
|
25
|
+
]);
|
|
26
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
27
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
28
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 0 })).toBe(0);
|
|
29
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 1 })).toBe(0);
|
|
30
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 1 })).toBe(0);
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.test)('sample 1', () => {
|
|
33
|
+
const targetArea = {
|
|
34
|
+
topLeft: { x: 0, y: 0 },
|
|
35
|
+
bottomRight: { x: 0, y: 0 }
|
|
36
|
+
};
|
|
37
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
38
|
+
[true, true],
|
|
39
|
+
[true, true]
|
|
40
|
+
]);
|
|
41
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
42
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
43
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 0 })).toBe(10);
|
|
44
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 1 })).toBe(10);
|
|
45
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 1, y: 1 })).toBe(14);
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.test)('sample 2', () => {
|
|
48
|
+
const targetArea = {
|
|
49
|
+
topLeft: { x: 0, y: 0 },
|
|
50
|
+
bottomRight: { x: 1, y: 1 }
|
|
51
|
+
};
|
|
52
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
53
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
54
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
55
|
+
[0, 0, 10],
|
|
56
|
+
[0, 0, 10],
|
|
57
|
+
[10, 10, 14]
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.test)('sample 3', () => {
|
|
61
|
+
const targetArea = {
|
|
62
|
+
topLeft: { x: 1, y: 1 },
|
|
63
|
+
bottomRight: { x: 2, y: 2 }
|
|
64
|
+
};
|
|
65
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
66
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
67
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
68
|
+
[14, 10, 10],
|
|
69
|
+
[10, 0, 0],
|
|
70
|
+
[10, 0, 0]
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.test)('complex 1', () => {
|
|
74
|
+
const targetArea = {
|
|
75
|
+
topLeft: { x: 0, y: 0 },
|
|
76
|
+
bottomRight: { x: 0, y: 0 }
|
|
77
|
+
};
|
|
78
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
79
|
+
[true, false, true],
|
|
80
|
+
[true, true, true],
|
|
81
|
+
[false, false, true],
|
|
82
|
+
[false, false, true]
|
|
83
|
+
]);
|
|
84
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
85
|
+
const h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
86
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
87
|
+
[0, h, 28],
|
|
88
|
+
[10, 14, 24],
|
|
89
|
+
[h, h, 28],
|
|
90
|
+
[h, h, 38]
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.test)('complex 2', () => {
|
|
94
|
+
const targetArea = {
|
|
95
|
+
topLeft: { x: 0, y: 0 },
|
|
96
|
+
bottomRight: { x: 1, y: 1 }
|
|
97
|
+
};
|
|
98
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
99
|
+
[true, true, false, true],
|
|
100
|
+
[true, true, false, true],
|
|
101
|
+
[false, false, true, true]
|
|
102
|
+
]);
|
|
103
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
104
|
+
const h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
105
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
106
|
+
[0, 0, h, 38],
|
|
107
|
+
[0, 0, h, 28],
|
|
108
|
+
[h, h, 14, 24]
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
(0, vitest_1.test)('complex 3', () => {
|
|
112
|
+
const targetArea = {
|
|
113
|
+
topLeft: { x: 2, y: 2 },
|
|
114
|
+
bottomRight: { x: 3, y: 3 }
|
|
115
|
+
};
|
|
116
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
117
|
+
[true, true, false, true],
|
|
118
|
+
[true, true, false, true],
|
|
119
|
+
[false, false, true, true],
|
|
120
|
+
[false, false, true, true]
|
|
121
|
+
]);
|
|
122
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
123
|
+
const h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
124
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
125
|
+
[28, 24, h, 20],
|
|
126
|
+
[24, 14, h, 10],
|
|
127
|
+
[h, h, 0, 0],
|
|
128
|
+
[h, h, 0, 0]
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
(0, vitest_1.test)('unreachable area 1', () => {
|
|
132
|
+
const targetArea = {
|
|
133
|
+
topLeft: { x: 0, y: 0 },
|
|
134
|
+
bottomRight: { x: 0, y: 0 }
|
|
135
|
+
};
|
|
136
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
137
|
+
[true, false, true, false, true],
|
|
138
|
+
[true, false, true, false, true],
|
|
139
|
+
[true, false, false, false, true],
|
|
140
|
+
[true, false, false, false, true],
|
|
141
|
+
[true, true, true, true, true]
|
|
142
|
+
]);
|
|
143
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
144
|
+
const h = pathFinder['getHighestWeight'](availabilityGrid.size);
|
|
145
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
146
|
+
[0, h, h, h, 108],
|
|
147
|
+
[10, h, h, h, 98],
|
|
148
|
+
[20, h, h, h, 88],
|
|
149
|
+
[30, h, h, h, 78],
|
|
150
|
+
[40, 44, 54, 64, 74]
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.describe)('getDirectionToTarget', () => {
|
|
155
|
+
(0, vitest_1.test)('sample 1', () => {
|
|
156
|
+
const targetArea = {
|
|
157
|
+
topLeft: { x: 0, y: 0 },
|
|
158
|
+
bottomRight: { x: 0, y: 0 }
|
|
159
|
+
};
|
|
160
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
161
|
+
[true, true],
|
|
162
|
+
[true, true]
|
|
163
|
+
]);
|
|
164
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
165
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 1, y: 1 })).toEqual(-helpers_lib_1.Radian.get45);
|
|
166
|
+
});
|
|
167
|
+
(0, vitest_1.test)('sample 2', () => {
|
|
168
|
+
const targetArea = {
|
|
169
|
+
topLeft: { x: 0, y: 0 },
|
|
170
|
+
bottomRight: { x: 0, y: 0 }
|
|
171
|
+
};
|
|
172
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
173
|
+
[true, true, true],
|
|
174
|
+
[false, true, true]
|
|
175
|
+
]);
|
|
176
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
177
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toEqual(
|
|
178
|
+
helpers_lib_1.Radian.vectorToRadian({ x: -2, y: -1 })
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
(0, vitest_1.test)('sample 3', () => {
|
|
182
|
+
const targetArea = {
|
|
183
|
+
topLeft: { x: 0, y: 0 },
|
|
184
|
+
bottomRight: { x: 0, y: 0 }
|
|
185
|
+
};
|
|
186
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
187
|
+
[true, false, true],
|
|
188
|
+
[true, false, true],
|
|
189
|
+
[true, true, true]
|
|
190
|
+
]);
|
|
191
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
192
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toEqual(helpers_lib_1.Radian.get180);
|
|
193
|
+
});
|
|
194
|
+
(0, vitest_1.test)('sample 4', () => {
|
|
195
|
+
const targetArea = {
|
|
196
|
+
topLeft: { x: 0, y: 0 },
|
|
197
|
+
bottomRight: { x: 0, y: 0 }
|
|
198
|
+
};
|
|
199
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
200
|
+
[true, false, false],
|
|
201
|
+
[true, false, false]
|
|
202
|
+
]);
|
|
203
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
204
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
(0, vitest_1.describe)('edge cases', () => {
|
|
208
|
+
(0, vitest_1.test)('should create an instance', () => {
|
|
209
|
+
const targetArea = {
|
|
210
|
+
topLeft: { x: 0, y: 0 },
|
|
211
|
+
bottomRight: { x: 0, y: 0 }
|
|
212
|
+
};
|
|
213
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 1, y: 1 }, true);
|
|
214
|
+
(0, vitest_1.expect)(new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid)).toBeTruthy();
|
|
215
|
+
});
|
|
216
|
+
(0, vitest_1.test)('should activate unavailable target cells of the target area', () => {
|
|
217
|
+
const targetArea = {
|
|
218
|
+
topLeft: { x: 0, y: 0 },
|
|
219
|
+
bottomRight: { x: 0, y: 0 }
|
|
220
|
+
};
|
|
221
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 1, y: 1 }, false);
|
|
222
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
223
|
+
(0, vitest_1.expect)(pathFinder['weightGrid'].get({ x: 0, y: 0 })).toBe(0);
|
|
224
|
+
});
|
|
225
|
+
(0, vitest_1.test)('should select closest grid cells if the target is outside of the grid', () => {
|
|
226
|
+
const targetArea = {
|
|
227
|
+
topLeft: { x: 3, y: -1 },
|
|
228
|
+
bottomRight: { x: 3, y: 1 }
|
|
229
|
+
};
|
|
230
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
231
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
232
|
+
(0, vitest_1.expect)(pathFinder['weightGrid']['_grid']).toEqual([
|
|
233
|
+
[20, 10, 0],
|
|
234
|
+
[20, 10, 0],
|
|
235
|
+
[24, 14, 10]
|
|
236
|
+
]);
|
|
237
|
+
});
|
|
238
|
+
(0, vitest_1.test)('should return undefined if starting position and its neighbors are unreachable', () => {
|
|
239
|
+
const targetArea = {
|
|
240
|
+
topLeft: { x: 0, y: 0 },
|
|
241
|
+
bottomRight: { x: 0, y: 0 }
|
|
242
|
+
};
|
|
243
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
244
|
+
[true, false, false],
|
|
245
|
+
[true, false, false]
|
|
246
|
+
]);
|
|
247
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
248
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toBeUndefined();
|
|
249
|
+
});
|
|
250
|
+
(0, vitest_1.test)('should find the direction if starting position is unreachable but there is a reachable neighbor', () => {
|
|
251
|
+
const targetArea = {
|
|
252
|
+
topLeft: { x: 0, y: 0 },
|
|
253
|
+
bottomRight: { x: 0, y: 0 }
|
|
254
|
+
};
|
|
255
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
256
|
+
[true, true, false],
|
|
257
|
+
[true, false, false]
|
|
258
|
+
]);
|
|
259
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
260
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 1 })).toEqual(-helpers_lib_1.Radian.get45);
|
|
261
|
+
});
|
|
262
|
+
(0, vitest_1.test)('should return undefined if starting point is inside target area', () => {
|
|
263
|
+
const targetArea = {
|
|
264
|
+
topLeft: { x: 0, y: 0 },
|
|
265
|
+
bottomRight: { x: 1, y: 1 }
|
|
266
|
+
};
|
|
267
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 2, y: 2 }, true);
|
|
268
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
269
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 0, y: 0 })).toBeUndefined();
|
|
270
|
+
});
|
|
271
|
+
(0, vitest_1.test)('should return closest cell result if starting point is outside of the grid', () => {
|
|
272
|
+
const targetArea = {
|
|
273
|
+
topLeft: { x: 0, y: 0 },
|
|
274
|
+
bottomRight: { x: 0, y: 0 }
|
|
275
|
+
};
|
|
276
|
+
const availabilityGrid = grid_1.Grid.createNew({ x: 2, y: 1 }, true);
|
|
277
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
278
|
+
(0, vitest_1.expect)(pathFinder.getDirectionToTarget({ x: 2, y: 0 })).toEqual(-helpers_lib_1.Radian.get90);
|
|
279
|
+
});
|
|
280
|
+
(0, vitest_1.test)('if average direction is pointing blocked path, it should pick random available direction', () => {
|
|
281
|
+
const targetArea = {
|
|
282
|
+
topLeft: { x: 0, y: 0 },
|
|
283
|
+
bottomRight: { x: 0, y: 0 }
|
|
284
|
+
};
|
|
285
|
+
const availabilityGrid = grid_1.Grid.createByValues([
|
|
286
|
+
[true, true, true],
|
|
287
|
+
[true, false, true],
|
|
288
|
+
[true, true, true]
|
|
289
|
+
]);
|
|
290
|
+
const pathFinder = new vector_field_path_finder_1.VectorFieldPathFinder(targetArea, availabilityGrid);
|
|
291
|
+
const result = pathFinder.getDirectionToTarget({ x: 2, y: 2 });
|
|
292
|
+
(0, vitest_1.expect)(result === -helpers_lib_1.Radian.get90 || result === 0).toBeTruthy();
|
|
293
|
+
});
|
|
294
|
+
});
|
|
231
295
|
});
|
|
232
|
-
//# sourceMappingURL=vector-field-path-finder.spec.js.map
|
|
296
|
+
//# sourceMappingURL=vector-field-path-finder.spec.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Vec2 } from 'helpers-lib';
|
|
2
2
|
export interface PathFinderResult {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
directPathAvailable: boolean;
|
|
4
|
+
path: Vec2[];
|
|
5
5
|
}
|
|
6
6
|
export declare class PathFinder {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Time Complexity: O(grid.height * grid.width)
|
|
9
|
+
* Space Complexity: O(grid.height * grid.width)
|
|
10
|
+
*/
|
|
11
|
+
static findPath(gridValues: boolean[][], startingPosition: Vec2, targetPosition: Vec2): PathFinderResult;
|
|
12
12
|
}
|