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.
Files changed (238) hide show
  1. package/dist/_interfaces/index.d.ts +2 -2
  2. package/dist/_interfaces/index.js +2 -3
  3. package/dist/game-entities/attachable/attachable.d.ts +6 -6
  4. package/dist/game-entities/attachable/attachable.js +28 -30
  5. package/dist/game-entities/attachable/attachable.spec.js +129 -128
  6. package/dist/game-entities/attachable/attachable.store.d.ts +5 -5
  7. package/dist/game-entities/attachable/attachable.store.js +34 -32
  8. package/dist/game-entities/attachable/attachable.test.js +132 -131
  9. package/dist/game-entities/attachable/destroyable.d.ts +13 -13
  10. package/dist/game-entities/attachable/destroyable.js +64 -69
  11. package/dist/game-entities/attachable/helpers/decorate-actions-lib.d.ts +15 -15
  12. package/dist/game-entities/attachable/helpers/decorate-actions-lib.js +125 -116
  13. package/dist/game-entities/attachable/helpers/referance-variable.d.ts +15 -15
  14. package/dist/game-entities/attachable/helpers/referance-variable.js +47 -48
  15. package/dist/game-entities/attachable/interfaces.d.ts +6 -6
  16. package/dist/game-entities/attachable/interfaces.js +2 -3
  17. package/dist/game-entities/base/helpers/decorate-actions-lib.js +0 -1
  18. package/dist/game-entities/controller/controller.js +0 -1
  19. package/dist/game-entities/controller/controller.spec.js +128 -125
  20. package/dist/game-entities/entity/entity.spec.js +263 -293
  21. package/dist/game-entities/entity/helpers/view-creation.helper.d.ts +7 -7
  22. package/dist/game-entities/entity/helpers/view-creation.helper.js +48 -48
  23. package/dist/game-entities/scene/scene.spec.js +219 -223
  24. package/dist/game-entities/service/service.js +0 -4
  25. package/dist/game-entities/service/service.spec.js +265 -237
  26. package/dist/game-entities/service/service.test.js +4 -2
  27. package/dist/game-entities/update-loop.d.ts +18 -18
  28. package/dist/game-entities/update-loop.js +46 -28
  29. package/dist/game-entities/view/view.spec.js +490 -506
  30. package/dist/game-entities/view/view.test.js +1 -1
  31. package/dist/lib/animator/animations.d.ts +13 -13
  32. package/dist/lib/animator/animations.js +43 -40
  33. package/dist/lib/animator/animator.d.ts +41 -41
  34. package/dist/lib/animator/animator.js +194 -197
  35. package/dist/lib/animator/animator.spec.js +699 -612
  36. package/dist/lib/animator/index.js +24 -19
  37. package/dist/lib/libraries/animator/animations.d.ts +13 -13
  38. package/dist/lib/libraries/animator/animations.js +43 -40
  39. package/dist/lib/libraries/animator/animator.d.ts +41 -41
  40. package/dist/lib/libraries/animator/animator.js +194 -197
  41. package/dist/lib/libraries/animator/animator.spec.js +699 -612
  42. package/dist/lib/libraries/animator/index.js +24 -19
  43. package/dist/lib/libraries/path-finder/path-finder.d.ts +2 -2
  44. package/dist/lib/libraries/path-finder/path-finder.js +19 -20
  45. package/dist/lib/path-finder/path-finder.d.ts +2 -2
  46. package/dist/lib/path-finder/path-finder.js +19 -20
  47. package/dist/lib/services/keyboard/keyboard.d.ts +4 -4
  48. package/dist/lib/services/keyboard/keyboard.js +39 -31
  49. package/dist/lib/services/mouse/mouse.service.d.ts +8 -8
  50. package/dist/lib/services/mouse/mouse.service.js +65 -53
  51. package/dist/lib/services/mouse/mouser-target-focus.service.d.ts +11 -11
  52. package/dist/lib/services/mouse/mouser-target-focus.service.js +83 -81
  53. package/dist/lib/update-loop.d.ts +10 -10
  54. package/dist/lib/update-loop.js +35 -27
  55. package/dist/physics/entitity-types/immovable-physics-entity.d.ts +6 -6
  56. package/dist/physics/entitity-types/immovable-physics-entity.js +23 -24
  57. package/dist/physics/entitity-types/movable-entity.d.ts +6 -6
  58. package/dist/physics/entitity-types/movable-entity.js +21 -22
  59. package/dist/physics/entitity-types/movable-physics-entity.d.ts +14 -14
  60. package/dist/physics/entitity-types/movable-physics-entity.js +83 -88
  61. package/dist/physics/entitity-types/physics-entity.d.ts +23 -23
  62. package/dist/physics/entitity-types/physics-entity.js +97 -88
  63. package/dist/physics/helpers/closest-available-space.helper.d.ts +16 -16
  64. package/dist/physics/helpers/closest-available-space.helper.js +98 -96
  65. package/dist/physics/helpers/closest-available-space.helper.spec.js +115 -68
  66. package/dist/physics/helpers/p2js.helper.d.ts +3 -3
  67. package/dist/physics/helpers/p2js.helper.js +21 -22
  68. package/dist/physics/helpers/shape-factory.d.ts +9 -4
  69. package/dist/physics/helpers/shape-factory.js +99 -75
  70. package/dist/physics/libs/p2js.helper.js +1 -1
  71. package/dist/physics/libs/position-to-grid-position-converter.d.ts +3 -3
  72. package/dist/physics/libs/position-to-grid-position-converter.js +15 -13
  73. package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +10 -5
  74. package/dist/physics/module//360/237/223/220services/availability-grid.service.js +77 -57
  75. package/dist/physics/module//360/237/223/220services/border.service.d.ts +2 -2
  76. package/dist/physics/module//360/237/223/220services/border.service.js +57 -37
  77. package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +1 -1
  78. package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +7 -7
  79. package/dist/physics/module//360/237/223/220services/collisions.service.js +110 -98
  80. package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +28 -6
  81. package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +121 -89
  82. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +15 -7
  83. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +117 -93
  84. package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -7
  85. package/dist/physics/module//360/237/223/220services/explosion.service.js +102 -77
  86. package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +15 -7
  87. package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +117 -93
  88. package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -7
  89. package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +102 -77
  90. package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +3 -3
  91. package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +71 -67
  92. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +3 -3
  93. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -67
  94. package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +1 -1
  95. package/dist/physics/module//360/237/223/220services/materials.service.d.ts +16 -11
  96. package/dist/physics/module//360/237/223/220services/materials.service.js +118 -108
  97. package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +19 -8
  98. package/dist/physics/module//360/237/223/220services/path-finder.service.js +121 -82
  99. package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +30 -15
  100. package/dist/physics/module//360/237/223/220services/physics-world.service.js +122 -100
  101. package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +3 -3
  102. package/dist/physics/module//360/237/223/220services/ray-casting.service.js +87 -86
  103. package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -4
  104. package/dist/physics/module//360/237/223/220services/shape-creation.service.js +113 -84
  105. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +2 -1
  106. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +8 -8
  107. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +32 -33
  108. package/dist/physics/physics-world.d.ts +50 -34
  109. package/dist/physics/physics-world.js +142 -133
  110. package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.d.ts +3 -3
  111. package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.js +15 -13
  112. package/dist/physics/sub-elements/available-spaces/physics-availability-grid.d.ts +9 -9
  113. package/dist/physics/sub-elements/available-spaces/physics-availability-grid.js +82 -77
  114. package/dist/physics/sub-elements/available-spaces/physics-available-spaces.d.ts +18 -14
  115. package/dist/physics/sub-elements/available-spaces/physics-available-spaces.js +91 -79
  116. package/dist/physics/sub-elements/collisions/contact-equation-orginiser.d.ts +11 -11
  117. package/dist/physics/sub-elements/collisions/contact-equation-orginiser.js +84 -76
  118. package/dist/physics/sub-elements/collisions/physics-collision.d.ts +7 -7
  119. package/dist/physics/sub-elements/collisions/physics-collision.js +43 -44
  120. package/dist/physics/sub-elements/elements/physics-body-groups.d.ts +11 -11
  121. package/dist/physics/sub-elements/elements/physics-body-groups.js +54 -54
  122. package/dist/physics/sub-elements/elements/physics-materials.d.ts +15 -10
  123. package/dist/physics/sub-elements/elements/physics-materials.js +101 -100
  124. package/dist/physics/sub-elements/elements/physics-world-borders.d.ts +3 -3
  125. package/dist/physics/sub-elements/elements/physics-world-borders.js +69 -45
  126. package/dist/physics/sub-elements/physics-body-groups.d.ts +8 -8
  127. package/dist/physics/sub-elements/physics-body-groups.js +41 -42
  128. package/dist/physics/sub-elements/physics-collision.d.ts +16 -16
  129. package/dist/physics/sub-elements/physics-collision.js +141 -121
  130. package/dist/physics/sub-elements/physics-materials.d.ts +15 -10
  131. package/dist/physics/sub-elements/physics-materials.js +101 -100
  132. package/dist/physics/sub-elements/physics-world-borders.d.ts +2 -2
  133. package/dist/physics/sub-elements/physics-world-borders.js +25 -26
  134. package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.d.ts +15 -11
  135. package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.js +59 -59
  136. package/dist/physics/sub-elements/raycasting/physics-explosion.d.ts +13 -6
  137. package/dist/physics/sub-elements/raycasting/physics-explosion.js +108 -73
  138. package/dist/physics/sub-elements/raycasting/ray-cast.d.ts +19 -19
  139. package/dist/physics/sub-elements/raycasting/ray-cast.js +93 -98
  140. package/dist/pixi/display-object/components/filters.d.ts +18 -18
  141. package/dist/pixi/display-object/components/filters.js +106 -81
  142. package/dist/pixi/display-object/components/glow-effect.d.ts +8 -8
  143. package/dist/pixi/display-object/components/glow-effect.js +33 -36
  144. package/dist/pixi/display-object/components/glow-filter.d.ts +8 -8
  145. package/dist/pixi/display-object/components/glow-filter.js +33 -36
  146. package/dist/pixi/display-object/container-attributes.js +1 -1
  147. package/dist/pixi/display-object/display-object-attributes.d.ts +41 -41
  148. package/dist/pixi/display-object/display-object-attributes.js +148 -150
  149. package/dist/pixi/display-object/display-object.d.ts +17 -17
  150. package/dist/pixi/display-object/display-object.js +79 -75
  151. package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.d.ts +9 -4
  152. package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.js +89 -77
  153. package/dist/pixi/display-object/filters/base-filters/blur.filter.js +30 -30
  154. package/dist/pixi/display-object/filters/base-filters/contrast-filter.d.ts +9 -4
  155. package/dist/pixi/display-object/filters/base-filters/contrast-filter.js +62 -53
  156. package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.d.ts +10 -5
  157. package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.js +93 -81
  158. package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.d.ts +12 -7
  159. package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.js +120 -109
  160. package/dist/pixi/display-object/filters/base-filters/expand-with-color.d.ts +10 -5
  161. package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +32 -32
  162. package/dist/pixi/display-object/filters/base-filters/expand-with-color.js +92 -85
  163. package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +28 -28
  164. package/dist/pixi/display-object/filters/templates/plane.template.js +20 -20
  165. package/dist/pixi/display-object/filters.js +20 -4
  166. package/dist/pixi/display-object/objects/components/filters.d.ts +18 -18
  167. package/dist/pixi/display-object/objects/components/filters.js +106 -81
  168. package/dist/pixi/display-object/objects/container.d.ts +2 -2
  169. package/dist/pixi/display-object/objects/container.js +39 -30
  170. package/dist/pixi/display-object/objects/graphics.d.ts +28 -28
  171. package/dist/pixi/display-object/objects/graphics.js +218 -202
  172. package/dist/pixi/display-object/objects/helpers/filters.d.ts +25 -25
  173. package/dist/pixi/display-object/objects/helpers/filters.js +150 -124
  174. package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.d.ts +7 -7
  175. package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.js +114 -95
  176. package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.d.ts +5 -5
  177. package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.js +81 -57
  178. package/dist/pixi/display-object/objects/sprite.d.ts +43 -43
  179. package/dist/pixi/display-object/objects/sprite.js +248 -233
  180. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +1 -1
  181. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +9 -9
  182. package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +1 -1
  183. package/dist/pixi/display-object/objects/text.d.ts +25 -25
  184. package/dist/pixi/display-object/objects/text.js +111 -102
  185. package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.d.ts +13 -9
  186. package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.js +96 -67
  187. package/dist/pixi/game.d.ts +1 -1
  188. package/dist/pixi/game.js +2 -2
  189. package/dist/pixi/helpers/glow-sprite-generator.d.ts +6 -6
  190. package/dist/pixi/helpers/glow-sprite-generator.js +99 -84
  191. package/dist/pixi/helpers/pixi-container.helper.d.ts +1 -1
  192. package/dist/pixi/helpers/pixi-container.helper.js +10 -8
  193. package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +1 -1
  194. package/dist/pixi/helpers/screen-position-to-stage.helper.js +12 -12
  195. package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +174 -79
  196. package/dist/pixi/modules/CAMERA/index.d.ts +1 -1
  197. package/dist/pixi/modules/CAMERA/index.js +3 -3
  198. package/dist/services/keyboard/keyboard.d.ts +4 -4
  199. package/dist/services/keyboard/keyboard.js +39 -31
  200. package/dist/services/mouse/mouse.service.d.ts +8 -8
  201. package/dist/services/mouse/mouse.service.js +65 -53
  202. package/dist/services/mouse/mouser-target-focus.service.d.ts +11 -11
  203. package/dist/services/mouse/mouser-target-focus.service.js +83 -81
  204. package/dist/utilities/libraries/animator/animating-content/state-animation.d.ts +29 -26
  205. package/dist/utilities/libraries/animator/animating-content/state-animation.js +159 -165
  206. package/dist/utilities/libraries/animator/animating-content/state-animation.test.js +386 -375
  207. package/dist/utilities/libraries/animator/animator.spec.js +765 -656
  208. package/dist/utilities/libraries/binary-heap/binary-heap.d.ts +11 -11
  209. package/dist/utilities/libraries/binary-heap/binary-heap.js +79 -81
  210. package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.d.ts +11 -11
  211. package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.js +79 -81
  212. package/dist/utilities/libraries/data-structures/grid/grid.d.ts +35 -31
  213. package/dist/utilities/libraries/data-structures/grid/grid.js +128 -117
  214. package/dist/utilities/libraries/data-structures/grid/grid.spec.js +176 -138
  215. package/dist/utilities/libraries/data-structures/grid/grid.test.js +218 -141
  216. package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.d.ts +3 -3
  217. package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.js +15 -13
  218. package/dist/utilities/libraries/data-structures/queue/queue.d.ts +21 -21
  219. package/dist/utilities/libraries/data-structures/queue/queue.js +63 -66
  220. package/dist/utilities/libraries/data-structures/queue/queue.test.js +54 -55
  221. package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.spec.js +122 -68
  222. package/dist/utilities/libraries/grid-algorithms/path-finder/path-finder.spec.js +140 -135
  223. package/dist/utilities/libraries/grid-algorithms/vector-field-path-finder/vector-field-path-finder.spec.js +293 -229
  224. package/dist/utilities/libraries/path-finder/path-finder.d.ts +7 -7
  225. package/dist/utilities/libraries/path-finder/path-finder.js +113 -109
  226. package/dist/utilities/libraries/path-finder/path-finder.spec.js +131 -106
  227. package/dist/utilities/services/keyboard/keyboard.d.ts +4 -4
  228. package/dist/utilities/services/keyboard/keyboard.js +42 -34
  229. package/dist/utilities/services/mouse/helpers/mouse-position.helper.d.ts +1 -1
  230. package/dist/utilities/services/mouse/helpers/mouse-position.helper.js +12 -12
  231. package/dist/utilities/services/mouse/helpers/mouse-position.helper.test.js +168 -73
  232. package/dist/utilities/services/mouse/mouse-target-focus.service.d.ts +15 -15
  233. package/dist/utilities/services/mouse/mouse-target-focus.service.js +79 -76
  234. package/dist/utilities/services/mouse/mouse.service.d.ts +9 -9
  235. package/dist/utilities/services/mouse/mouse.service.js +86 -72
  236. package/dist/utilities/services/mouse/mouser-target-focus.service.d.ts +11 -11
  237. package/dist/utilities/services/mouse/mouser-target-focus.service.js +83 -81
  238. package/package.json +4 -10
@@ -1,143 +1,220 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const helpers_lib_1 = require("helpers-lib");
4
- const vitest_1 = require("vitest");
5
- const grid_1 = require("./grid");
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const helpers_lib_1 = require('helpers-lib');
3
+ const vitest_1 = require('vitest');
4
+ const grid_1 = require('./grid');
6
5
  (0, vitest_1.describe)('Grid', () => {
7
- let grid;
8
- (0, vitest_1.beforeEach)(() => {
9
- grid = grid_1.Grid.createNew(new helpers_lib_1.Vector(3, 3), true);
10
- });
11
- (0, vitest_1.test)('should be defined', () => {
12
- (0, vitest_1.expect)(grid).toBeDefined();
13
- });
14
- (0, vitest_1.test)('should set and get values', () => {
15
- grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(1, 1)), false);
16
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 0))).toBeFalsy();
17
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 1))).toBeFalsy();
18
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 0))).toBeFalsy();
19
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 1))).toBeFalsy();
20
- });
21
- (0, vitest_1.test)('should throw an error if area is outside of the grid', () => {
22
- (0, vitest_1.expect)(() => grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)), false)).toThrow();
23
- });
24
- (0, vitest_1.test)('should crop area outside of the grid 1', () => {
25
- (0, vitest_1.expect)(grid.cropPartsOutsideOfTheGrid(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(-1, -1), new helpers_lib_1.Vector(3, 3))).toRect()).toStrictEqual({
26
- topLeft: { x: 0, y: 0 },
27
- bottomRight: { x: 2, y: 2 }
28
- });
29
- });
30
- (0, vitest_1.test)('should crop area outside of the grid 2', () => {
31
- (0, vitest_1.expect)(grid.cropPartsOutsideOfTheGrid(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(3, 3), new helpers_lib_1.Vector(4, 4))).toRect()).toStrictEqual({
32
- topLeft: { x: 2, y: 2 },
33
- bottomRight: { x: 2, y: 2 }
34
- });
35
- });
36
- (0, vitest_1.test)('should crop area outside of the grid 2', () => {
37
- (0, vitest_1.expect)(grid.cropPartsOutsideOfTheGrid(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(-1, -1), new helpers_lib_1.Vector(-1, -1))).toRect()).toStrictEqual({
38
- topLeft: { x: 0, y: 0 },
39
- bottomRight: { x: 0, y: 0 }
40
- });
41
- });
42
- (0, vitest_1.test)('should check if area is within bounds', () => {
43
- (0, vitest_1.expect)(grid.isAreaWithinBounds(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(1, 1)))).toBeTruthy();
44
- (0, vitest_1.expect)(grid.isAreaWithinBounds(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)))).toBeFalsy();
45
- });
46
- (0, vitest_1.test)('should check if point is within bounds', () => {
47
- (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(0, 0))).toBeTruthy();
48
- (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(1, 1))).toBeTruthy();
49
- (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(3, 3))).toBeFalsy();
50
- });
51
- (0, vitest_1.test)('should set area within bounds', () => {
52
- grid.safeSetArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)), false);
53
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 0))).toBeFalsy();
54
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 1))).toBeFalsy();
55
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 0))).toBeFalsy();
56
- (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 1))).toBeFalsy();
57
- });
58
- (0, vitest_1.test)('should return neighbor positions only adjacent', () => {
59
- (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(1, 1)).map(item => item.toVec2())).toStrictEqual([
60
- { x: 0, y: 1 },
61
- { x: 1, y: 0 },
62
- { x: 1, y: 2 },
63
- { x: 2, y: 1 }
64
- ]);
65
- });
66
- (0, vitest_1.test)('should return neighbor positions with diagonals', () => {
67
- (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(1, 1), { includeDiagonals: true }).map(item => item.toVec2())).toStrictEqual([
68
- { x: 0, y: 1 },
69
- { x: 1, y: 0 },
70
- { x: 1, y: 2 },
71
- { x: 2, y: 1 },
72
- { x: 0, y: 0 },
73
- { x: 0, y: 2 },
74
- { x: 2, y: 0 },
75
- { x: 2, y: 2 }
76
- ]);
77
- });
78
- (0, vitest_1.test)('should return neighbor positions only adjacent at the edge', () => {
79
- (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(2, 2)).map(item => item.toVec2())).toStrictEqual([
80
- { x: 1, y: 2 },
81
- { x: 2, y: 1 }
82
- ]);
83
- });
84
- (0, vitest_1.test)('should return neighbor positions at the edge with diagonals', () => {
85
- (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(0, 0), { includeDiagonals: true }).map(item => item.toVec2())).toStrictEqual([
86
- { x: 0, y: 1 },
87
- { x: 1, y: 0 },
88
- { x: 1, y: 1 }
89
- ]);
90
- });
91
- (0, vitest_1.test)('should iterate over all values', () => {
92
- grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(1, 0), new helpers_lib_1.Vector(1, 1)), false);
93
- let values = [];
94
- grid.forEach((value, position) => values.push({ value, position }));
95
- (0, vitest_1.expect)(values.map(item => ({ value: item.value, position: item.position.toVec2() }))).toStrictEqual([
96
- { value: true, position: { x: 0, y: 0 } },
97
- { value: false, position: { x: 1, y: 0 } },
98
- { value: true, position: { x: 2, y: 0 } },
99
- { value: true, position: { x: 0, y: 1 } },
100
- { value: false, position: { x: 1, y: 1 } },
101
- { value: true, position: { x: 2, y: 1 } },
102
- { value: true, position: { x: 0, y: 2 } },
103
- { value: true, position: { x: 1, y: 2 } },
104
- { value: true, position: { x: 2, y: 2 } }
105
- ]);
106
- });
107
- (0, vitest_1.test)('should map over all values', () => {
108
- grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(1, 0), new helpers_lib_1.Vector(1, 1)), false);
109
- let newGrid = grid.map((value, position) => (position.x + position.y) * (value ? 1 : -1));
110
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 0))).toBe(0);
111
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 0))).toBe(-1);
112
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 0))).toBe(2);
113
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 1))).toBe(1);
114
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 1))).toBe(-2);
115
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 1))).toBe(3);
116
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 2))).toBe(2);
117
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 2))).toBe(3);
118
- (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 2))).toBe(4);
119
- (0, vitest_1.expect)(newGrid.size.toVec2()).toStrictEqual({ x: 3, y: 3 });
120
- });
121
- (0, vitest_1.test)('should find the neighbor direction from a vector', () => {
122
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, 1)).toVec2()).toStrictEqual({ x: 0, y: 1 });
123
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 0)).toVec2()).toStrictEqual({ x: 1, y: 0 });
124
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, -1)).toVec2()).toStrictEqual({ x: 0, y: -1 });
125
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-1, 0)).toVec2()).toStrictEqual({ x: -1, y: 0 });
126
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0.5, 2)).toVec2()).toStrictEqual({ x: 0, y: 1 });
127
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(2, -0.5)).toVec2()).toStrictEqual({ x: 1, y: -0 });
128
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0.5, -2)).toVec2()).toStrictEqual({ x: 0, y: -1 });
129
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-2, -0.5)).toVec2()).toStrictEqual({ x: -1, y: -0 });
130
- let middle = grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 1));
131
- (0, vitest_1.expect)(helpers_lib_1.Vector.isEqual(middle, new helpers_lib_1.Vector(0, 1)) || helpers_lib_1.Vector.isEqual(middle, new helpers_lib_1.Vector(1, 0))).toBeTruthy();
132
- });
133
- (0, vitest_1.test)('should find the neighbor direction with diagonals from a vector', () => {
134
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, 1), { includeDiagonals: true }).toVec2()).toStrictEqual({ x: 0, y: 1 });
135
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 1), { includeDiagonals: true }).toVec2()).toStrictEqual({ x: 1, y: 1 });
136
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-1, -1), { includeDiagonals: true }).toVec2()).toStrictEqual({
137
- x: -1,
138
- y: -1
139
- });
140
- (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(2, 1), { includeDiagonals: true }).toVec2()).toStrictEqual({ x: 1, y: 0 });
141
- });
6
+ let grid;
7
+ (0, vitest_1.beforeEach)(() => {
8
+ grid = grid_1.Grid.createNew(new helpers_lib_1.Vector(3, 3), true);
9
+ });
10
+ (0, vitest_1.test)('should be defined', () => {
11
+ (0, vitest_1.expect)(grid).toBeDefined();
12
+ });
13
+ (0, vitest_1.test)('should set and get values', () => {
14
+ grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(1, 1)), false);
15
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 0))).toBeFalsy();
16
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 1))).toBeFalsy();
17
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 0))).toBeFalsy();
18
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 1))).toBeFalsy();
19
+ });
20
+ (0, vitest_1.test)('should throw an error if area is outside of the grid', () => {
21
+ (0, vitest_1.expect)(() =>
22
+ grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)), false)
23
+ ).toThrow();
24
+ });
25
+ (0, vitest_1.test)('should crop area outside of the grid 1', () => {
26
+ (0, vitest_1.expect)(
27
+ grid
28
+ .cropPartsOutsideOfTheGrid(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(-1, -1), new helpers_lib_1.Vector(3, 3)))
29
+ .toRect()
30
+ ).toStrictEqual({
31
+ topLeft: { x: 0, y: 0 },
32
+ bottomRight: { x: 2, y: 2 }
33
+ });
34
+ });
35
+ (0, vitest_1.test)('should crop area outside of the grid 2', () => {
36
+ (0, vitest_1.expect)(
37
+ grid
38
+ .cropPartsOutsideOfTheGrid(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(3, 3), new helpers_lib_1.Vector(4, 4)))
39
+ .toRect()
40
+ ).toStrictEqual({
41
+ topLeft: { x: 2, y: 2 },
42
+ bottomRight: { x: 2, y: 2 }
43
+ });
44
+ });
45
+ (0, vitest_1.test)('should crop area outside of the grid 2', () => {
46
+ (0, vitest_1.expect)(
47
+ grid
48
+ .cropPartsOutsideOfTheGrid(
49
+ new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(-1, -1), new helpers_lib_1.Vector(-1, -1))
50
+ )
51
+ .toRect()
52
+ ).toStrictEqual({
53
+ topLeft: { x: 0, y: 0 },
54
+ bottomRight: { x: 0, y: 0 }
55
+ });
56
+ });
57
+ (0, vitest_1.test)('should check if area is within bounds', () => {
58
+ (0, vitest_1.expect)(
59
+ grid.isAreaWithinBounds(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(1, 1)))
60
+ ).toBeTruthy();
61
+ (0, vitest_1.expect)(
62
+ grid.isAreaWithinBounds(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)))
63
+ ).toBeFalsy();
64
+ });
65
+ (0, vitest_1.test)('should check if point is within bounds', () => {
66
+ (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(0, 0))).toBeTruthy();
67
+ (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(1, 1))).toBeTruthy();
68
+ (0, vitest_1.expect)(grid.isPointWithinBounds(new helpers_lib_1.Vector(3, 3))).toBeFalsy();
69
+ });
70
+ (0, vitest_1.test)('should set area within bounds', () => {
71
+ grid.safeSetArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(0, 0), new helpers_lib_1.Vector(3, 3)), false);
72
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 0))).toBeFalsy();
73
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(0, 1))).toBeFalsy();
74
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 0))).toBeFalsy();
75
+ (0, vitest_1.expect)(grid.get(new helpers_lib_1.Vector(1, 1))).toBeFalsy();
76
+ });
77
+ (0, vitest_1.test)('should return neighbor positions only adjacent', () => {
78
+ (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(1, 1)).map(item => item.toVec2())).toStrictEqual([
79
+ { x: 0, y: 1 },
80
+ { x: 1, y: 0 },
81
+ { x: 1, y: 2 },
82
+ { x: 2, y: 1 }
83
+ ]);
84
+ });
85
+ (0, vitest_1.test)('should return neighbor positions with diagonals', () => {
86
+ (0, vitest_1.expect)(
87
+ grid
88
+ .getNeighborPositions(new helpers_lib_1.Vector(1, 1), {
89
+ includeDiagonals: true
90
+ })
91
+ .map(item => item.toVec2())
92
+ ).toStrictEqual([
93
+ { x: 0, y: 1 },
94
+ { x: 1, y: 0 },
95
+ { x: 1, y: 2 },
96
+ { x: 2, y: 1 },
97
+ { x: 0, y: 0 },
98
+ { x: 0, y: 2 },
99
+ { x: 2, y: 0 },
100
+ { x: 2, y: 2 }
101
+ ]);
102
+ });
103
+ (0, vitest_1.test)('should return neighbor positions only adjacent at the edge', () => {
104
+ (0, vitest_1.expect)(grid.getNeighborPositions(new helpers_lib_1.Vector(2, 2)).map(item => item.toVec2())).toStrictEqual([
105
+ { x: 1, y: 2 },
106
+ { x: 2, y: 1 }
107
+ ]);
108
+ });
109
+ (0, vitest_1.test)('should return neighbor positions at the edge with diagonals', () => {
110
+ (0, vitest_1.expect)(
111
+ grid
112
+ .getNeighborPositions(new helpers_lib_1.Vector(0, 0), {
113
+ includeDiagonals: true
114
+ })
115
+ .map(item => item.toVec2())
116
+ ).toStrictEqual([
117
+ { x: 0, y: 1 },
118
+ { x: 1, y: 0 },
119
+ { x: 1, y: 1 }
120
+ ]);
121
+ });
122
+ (0, vitest_1.test)('should iterate over all values', () => {
123
+ grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(1, 0), new helpers_lib_1.Vector(1, 1)), false);
124
+ const values = [];
125
+ grid.forEach((value, position) => values.push({ value, position }));
126
+ (0, vitest_1.expect)(
127
+ values.map(item => ({
128
+ value: item.value,
129
+ position: item.position.toVec2()
130
+ }))
131
+ ).toStrictEqual([
132
+ { value: true, position: { x: 0, y: 0 } },
133
+ { value: false, position: { x: 1, y: 0 } },
134
+ { value: true, position: { x: 2, y: 0 } },
135
+ { value: true, position: { x: 0, y: 1 } },
136
+ { value: false, position: { x: 1, y: 1 } },
137
+ { value: true, position: { x: 2, y: 1 } },
138
+ { value: true, position: { x: 0, y: 2 } },
139
+ { value: true, position: { x: 1, y: 2 } },
140
+ { value: true, position: { x: 2, y: 2 } }
141
+ ]);
142
+ });
143
+ (0, vitest_1.test)('should map over all values', () => {
144
+ grid.setArea(new helpers_lib_1.Rectangle(new helpers_lib_1.Vector(1, 0), new helpers_lib_1.Vector(1, 1)), false);
145
+ const newGrid = grid.map((value, position) => (position.x + position.y) * (value ? 1 : -1));
146
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 0))).toBe(0);
147
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 0))).toBe(-1);
148
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 0))).toBe(2);
149
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 1))).toBe(1);
150
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 1))).toBe(-2);
151
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 1))).toBe(3);
152
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(0, 2))).toBe(2);
153
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(1, 2))).toBe(3);
154
+ (0, vitest_1.expect)(newGrid.get(new helpers_lib_1.Vector(2, 2))).toBe(4);
155
+ (0, vitest_1.expect)(newGrid.size.toVec2()).toStrictEqual({ x: 3, y: 3 });
156
+ });
157
+ (0, vitest_1.test)('should find the neighbor direction from a vector', () => {
158
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, 1)).toVec2()).toStrictEqual({
159
+ x: 0,
160
+ y: 1
161
+ });
162
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 0)).toVec2()).toStrictEqual({
163
+ x: 1,
164
+ y: 0
165
+ });
166
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, -1)).toVec2()).toStrictEqual({
167
+ x: 0,
168
+ y: -1
169
+ });
170
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-1, 0)).toVec2()).toStrictEqual({
171
+ x: -1,
172
+ y: 0
173
+ });
174
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0.5, 2)).toVec2()).toStrictEqual({
175
+ x: 0,
176
+ y: 1
177
+ });
178
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(2, -0.5)).toVec2()).toStrictEqual({
179
+ x: 1,
180
+ y: -0
181
+ });
182
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0.5, -2)).toVec2()).toStrictEqual({
183
+ x: 0,
184
+ y: -1
185
+ });
186
+ (0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-2, -0.5)).toVec2()).toStrictEqual({
187
+ x: -1,
188
+ y: -0
189
+ });
190
+ const middle = grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 1));
191
+ (0, vitest_1.expect)(
192
+ helpers_lib_1.Vector.isEqual(middle, new helpers_lib_1.Vector(0, 1)) ||
193
+ helpers_lib_1.Vector.isEqual(middle, new helpers_lib_1.Vector(1, 0))
194
+ ).toBeTruthy();
195
+ });
196
+ (0, vitest_1.test)('should find the neighbor direction with diagonals from a vector', () => {
197
+ (0, vitest_1.expect)(
198
+ grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(0, 1), {
199
+ includeDiagonals: true
200
+ }).toVec2()
201
+ ).toStrictEqual({ x: 0, y: 1 });
202
+ (0, vitest_1.expect)(
203
+ grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(1, 1), {
204
+ includeDiagonals: true
205
+ }).toVec2()
206
+ ).toStrictEqual({ x: 1, y: 1 });
207
+ (0, vitest_1.expect)(
208
+ grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(-1, -1), { includeDiagonals: true }).toVec2()
209
+ ).toStrictEqual({
210
+ x: -1,
211
+ y: -1
212
+ });
213
+ (0, vitest_1.expect)(
214
+ grid_1.Grid.vectorToNeighborDirection(new helpers_lib_1.Vector(2, 1), {
215
+ includeDiagonals: true
216
+ }).toVec2()
217
+ ).toStrictEqual({ x: 1, y: 0 });
218
+ });
142
219
  });
143
- //# sourceMappingURL=grid.test.js.map
220
+ //# sourceMappingURL=grid.test.js.map
@@ -1,6 +1,6 @@
1
1
  import { Rectangle, Vector } from 'helpers-lib';
2
2
  export declare class PositionToGridPositionConverter {
3
- static areaToGridArea(boundingBox: Rectangle, cellSize: number): Rectangle;
4
- static positionToGridPosition(point: Vector, cellSize: number): Vector;
5
- static gridPositionToPosition(gridPosition: Vector, cellSize: number): Vector;
3
+ static areaToGridArea(boundingBox: Rectangle, cellSize: number): Rectangle;
4
+ static positionToGridPosition(point: Vector, cellSize: number): Vector;
5
+ static gridPositionToPosition(gridPosition: Vector, cellSize: number): Vector;
6
6
  }
@@ -1,17 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ Object.defineProperty(exports, '__esModule', { value: true });
3
2
  exports.PositionToGridPositionConverter = void 0;
4
- const helpers_lib_1 = require("helpers-lib");
3
+ const helpers_lib_1 = require('helpers-lib');
5
4
  class PositionToGridPositionConverter {
6
- static areaToGridArea(boundingBox, cellSize) {
7
- return new helpers_lib_1.Rectangle(this.positionToGridPosition(boundingBox.topLeft, cellSize), this.positionToGridPosition(boundingBox.bottomRight, cellSize));
8
- }
9
- static positionToGridPosition(point, cellSize) {
10
- return point.divideNumber(cellSize).floor();
11
- }
12
- static gridPositionToPosition(gridPosition, cellSize) {
13
- return gridPosition.add(new helpers_lib_1.Vector(0.5, 0.5)).multiplyNumber(cellSize);
14
- }
5
+ static areaToGridArea(boundingBox, cellSize) {
6
+ return new helpers_lib_1.Rectangle(
7
+ PositionToGridPositionConverter.positionToGridPosition(boundingBox.topLeft, cellSize),
8
+ PositionToGridPositionConverter.positionToGridPosition(boundingBox.bottomRight, cellSize)
9
+ );
10
+ }
11
+ static positionToGridPosition(point, cellSize) {
12
+ return point.divideNumber(cellSize).floor();
13
+ }
14
+ static gridPositionToPosition(gridPosition, cellSize) {
15
+ return gridPosition.add(new helpers_lib_1.Vector(0.5, 0.5)).multiplyNumber(cellSize);
16
+ }
15
17
  }
16
18
  exports.PositionToGridPositionConverter = PositionToGridPositionConverter;
17
- //# sourceMappingURL=position-to-grid-position-converter.js.map
19
+ //# sourceMappingURL=position-to-grid-position-converter.js.map
@@ -1,23 +1,23 @@
1
1
  export declare class Queue<T> {
2
- private start;
3
- private end;
4
- get isEmpty(): boolean;
5
- constructor(firstNode?: T | undefined);
6
- /**
7
- * @param args The values to add to end of the queue
8
- */
9
- add(...args: T[]): void;
10
- /**
11
- * @returns The value of the first element in the queue
12
- */
13
- pop(): T | undefined;
14
- /**
15
- * @returns The value of the first element in the queue without removing it
16
- */
17
- peek(): T | undefined;
18
- /**
19
- * @param deepCopyItem An optional function that takes an item and returns a deep copy of it
20
- * @returns The duplicated queue
21
- */
22
- duplicate(deepCopyItem?: (item: T) => T): Queue<T>;
2
+ private start;
3
+ private end;
4
+ get isEmpty(): boolean;
5
+ constructor(firstNode?: T | undefined);
6
+ /**
7
+ * @param args The values to add to end of the queue
8
+ */
9
+ add(...args: T[]): void;
10
+ /**
11
+ * @returns The value of the first element in the queue
12
+ */
13
+ pop(): T | undefined;
14
+ /**
15
+ * @returns The value of the first element in the queue without removing it
16
+ */
17
+ peek(): T | undefined;
18
+ /**
19
+ * @param deepCopyItem An optional function that takes an item and returns a deep copy of it
20
+ * @returns The duplicated queue
21
+ */
22
+ duplicate(deepCopyItem?: (item: T) => T): Queue<T>;
23
23
  }
@@ -1,75 +1,72 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ Object.defineProperty(exports, '__esModule', { value: true });
3
2
  exports.Queue = void 0;
4
3
  class DoublyLinkedListNode {
5
- constructor(value) {
6
- this.value = value;
7
- }
4
+ constructor(value) {
5
+ this.value = value;
6
+ }
8
7
  }
9
8
  class Queue {
10
- get isEmpty() {
11
- return this.start === undefined;
12
- }
13
- constructor(firstNode) {
14
- if (firstNode) {
15
- let firstNodeInstance = new DoublyLinkedListNode(firstNode);
16
- this.start = firstNodeInstance;
17
- this.end = firstNodeInstance;
18
- }
19
- }
20
- /**
21
- * @param args The values to add to end of the queue
22
- */
23
- add(...args) {
24
- args.forEach(value => {
25
- let newNode = new DoublyLinkedListNode(value);
26
- if (this.start) {
27
- newNode.previous = this.end;
28
- this.end.next = newNode;
29
- this.end = newNode;
30
- }
31
- else {
32
- this.start = newNode;
33
- this.end = newNode;
34
- }
35
- });
36
- }
37
- /**
38
- * @returns The value of the first element in the queue
39
- */
40
- pop() {
41
- if (this.start) {
42
- let value = this.start.value;
43
- this.start = this.start.next;
44
- if (this.start) {
45
- this.start.previous = undefined;
46
- }
47
- else {
48
- this.end = undefined;
49
- }
50
- return value;
51
- }
9
+ get isEmpty() {
10
+ return this.start === undefined;
11
+ }
12
+ constructor(firstNode) {
13
+ if (firstNode) {
14
+ const firstNodeInstance = new DoublyLinkedListNode(firstNode);
15
+ this.start = firstNodeInstance;
16
+ this.end = firstNodeInstance;
52
17
  }
53
- /**
54
- * @returns The value of the first element in the queue without removing it
55
- */
56
- peek() {
57
- return this.start?.value;
18
+ }
19
+ /**
20
+ * @param args The values to add to end of the queue
21
+ */
22
+ add(...args) {
23
+ args.forEach(value => {
24
+ const newNode = new DoublyLinkedListNode(value);
25
+ if (this.start) {
26
+ newNode.previous = this.end;
27
+ this.end.next = newNode;
28
+ this.end = newNode;
29
+ } else {
30
+ this.start = newNode;
31
+ this.end = newNode;
32
+ }
33
+ });
34
+ }
35
+ /**
36
+ * @returns The value of the first element in the queue
37
+ */
38
+ pop() {
39
+ if (this.start) {
40
+ const value = this.start.value;
41
+ this.start = this.start.next;
42
+ if (this.start) {
43
+ this.start.previous = undefined;
44
+ } else {
45
+ this.end = undefined;
46
+ }
47
+ return value;
58
48
  }
59
- /**
60
- * @param deepCopyItem An optional function that takes an item and returns a deep copy of it
61
- * @returns The duplicated queue
62
- */
63
- duplicate(deepCopyItem) {
64
- let newQueue = new Queue();
65
- let current = this.start;
66
- while (current) {
67
- let value = deepCopyItem ? deepCopyItem(current.value) : current.value;
68
- newQueue.add(value);
69
- current = current.next;
70
- }
71
- return newQueue;
49
+ }
50
+ /**
51
+ * @returns The value of the first element in the queue without removing it
52
+ */
53
+ peek() {
54
+ return this.start?.value;
55
+ }
56
+ /**
57
+ * @param deepCopyItem An optional function that takes an item and returns a deep copy of it
58
+ * @returns The duplicated queue
59
+ */
60
+ duplicate(deepCopyItem) {
61
+ const newQueue = new Queue();
62
+ let current = this.start;
63
+ while (current) {
64
+ const value = deepCopyItem ? deepCopyItem(current.value) : current.value;
65
+ newQueue.add(value);
66
+ current = current.next;
72
67
  }
68
+ return newQueue;
69
+ }
73
70
  }
74
71
  exports.Queue = Queue;
75
- //# sourceMappingURL=queue.js.map
72
+ //# sourceMappingURL=queue.js.map