@inglorious/engine 0.1.0 → 0.1.1

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 (92) hide show
  1. package/package.json +11 -12
  2. package/src/docs/ai/movement/dynamic/align.js +0 -131
  3. package/src/docs/ai/movement/dynamic/arrive.js +0 -88
  4. package/src/docs/ai/movement/dynamic/dynamic.mdx +0 -99
  5. package/src/docs/ai/movement/dynamic/dynamic.stories.js +0 -58
  6. package/src/docs/ai/movement/dynamic/evade.js +0 -72
  7. package/src/docs/ai/movement/dynamic/face.js +0 -90
  8. package/src/docs/ai/movement/dynamic/flee.js +0 -38
  9. package/src/docs/ai/movement/dynamic/look-where-youre-going.js +0 -114
  10. package/src/docs/ai/movement/dynamic/match-velocity.js +0 -92
  11. package/src/docs/ai/movement/dynamic/pursue.js +0 -72
  12. package/src/docs/ai/movement/dynamic/seek.js +0 -37
  13. package/src/docs/ai/movement/dynamic/wander.js +0 -71
  14. package/src/docs/ai/movement/kinematic/align.js +0 -122
  15. package/src/docs/ai/movement/kinematic/arrive.js +0 -78
  16. package/src/docs/ai/movement/kinematic/face.js +0 -82
  17. package/src/docs/ai/movement/kinematic/flee.js +0 -36
  18. package/src/docs/ai/movement/kinematic/kinematic.mdx +0 -67
  19. package/src/docs/ai/movement/kinematic/kinematic.stories.js +0 -42
  20. package/src/docs/ai/movement/kinematic/seek.js +0 -34
  21. package/src/docs/ai/movement/kinematic/wander-as-seek.js +0 -62
  22. package/src/docs/ai/movement/kinematic/wander.js +0 -28
  23. package/src/docs/bounds.js +0 -7
  24. package/src/docs/code-reuse.js +0 -35
  25. package/src/docs/collision/circles.js +0 -58
  26. package/src/docs/collision/collision.mdx +0 -27
  27. package/src/docs/collision/collision.stories.js +0 -22
  28. package/src/docs/collision/platform.js +0 -76
  29. package/src/docs/collision/tilemap.js +0 -181
  30. package/src/docs/empty.js +0 -1
  31. package/src/docs/engine.mdx +0 -81
  32. package/src/docs/engine.stories.js +0 -37
  33. package/src/docs/event-handlers.js +0 -68
  34. package/src/docs/framerate.js +0 -37
  35. package/src/docs/game.jsx +0 -15
  36. package/src/docs/image/image.js +0 -19
  37. package/src/docs/image/image.stories.js +0 -22
  38. package/src/docs/image/sprite.js +0 -39
  39. package/src/docs/image/tilemap.js +0 -84
  40. package/src/docs/input/controls.js +0 -67
  41. package/src/docs/input/gamepad.js +0 -67
  42. package/src/docs/input/input.mdx +0 -55
  43. package/src/docs/input/input.stories.js +0 -27
  44. package/src/docs/input/keyboard.js +0 -58
  45. package/src/docs/input/mouse.js +0 -32
  46. package/src/docs/instances.js +0 -49
  47. package/src/docs/player/dynamic/double-jump.js +0 -90
  48. package/src/docs/player/dynamic/dynamic.stories.js +0 -32
  49. package/src/docs/player/dynamic/jump.js +0 -83
  50. package/src/docs/player/dynamic/modern-controls.js +0 -57
  51. package/src/docs/player/dynamic/shooter-controls.js +0 -51
  52. package/src/docs/player/dynamic/tank-controls.js +0 -44
  53. package/src/docs/player/kinematic/double-jump.js +0 -90
  54. package/src/docs/player/kinematic/jump.js +0 -82
  55. package/src/docs/player/kinematic/kinematic.stories.js +0 -32
  56. package/src/docs/player/kinematic/modern-controls.js +0 -56
  57. package/src/docs/player/kinematic/shooter-controls.js +0 -48
  58. package/src/docs/player/kinematic/tank-controls.js +0 -42
  59. package/src/docs/quick-start/first-game.js +0 -49
  60. package/src/docs/quick-start/hello-world.js +0 -1
  61. package/src/docs/quick-start.mdx +0 -127
  62. package/src/docs/quick-start.stories.js +0 -17
  63. package/src/docs/recipes/add-and-remove.js +0 -71
  64. package/src/docs/recipes/add-instance.js +0 -42
  65. package/src/docs/recipes/decision-tree.js +0 -169
  66. package/src/docs/recipes/random-instances.js +0 -25
  67. package/src/docs/recipes/recipes.mdx +0 -81
  68. package/src/docs/recipes/recipes.stories.js +0 -37
  69. package/src/docs/recipes/remove-instance.js +0 -52
  70. package/src/docs/recipes/states.js +0 -64
  71. package/src/docs/ui/button.js +0 -28
  72. package/src/docs/ui/form.stories.js +0 -55
  73. package/src/docs/ui-chooser.jsx +0 -6
  74. package/src/docs/utils/data-structures/object.mdx +0 -47
  75. package/src/docs/utils/data-structures/objects.mdx +0 -30
  76. package/src/docs/utils/functions/functions.mdx +0 -34
  77. package/src/docs/utils/math/geometry/circle.mdx +0 -55
  78. package/src/docs/utils/math/geometry/point.mdx +0 -38
  79. package/src/docs/utils/math/geometry/rectangle.mdx +0 -24
  80. package/src/docs/utils/math/geometry/segment.mdx +0 -55
  81. package/src/docs/utils/math/geometry/triangle.mdx +0 -22
  82. package/src/docs/utils/math/linear-algebra/2d.mdx +0 -22
  83. package/src/docs/utils/math/linear-algebra/quaternion.mdx +0 -21
  84. package/src/docs/utils/math/linear-algebra/quaternions.mdx +0 -22
  85. package/src/docs/utils/math/linear-algebra/vector.mdx +0 -177
  86. package/src/docs/utils/math/linear-algebra/vectors.mdx +0 -58
  87. package/src/docs/utils/math/numbers.mdx +0 -76
  88. package/src/docs/utils/math/random.mdx +0 -35
  89. package/src/docs/utils/math/statistics.mdx +0 -38
  90. package/src/docs/utils/math/trigonometry.mdx +0 -85
  91. package/src/docs/utils/physics/friction.mdx +0 -20
  92. package/src/docs/utils/physics/gravity.mdx +0 -28
@@ -1,37 +0,0 @@
1
- import UiChooser from "@inglorious/docs/ui-chooser.jsx"
2
-
3
- import addAndRemove from "./add-and-remove.js"
4
- import addInstance from "./add-instance.js"
5
- import decisionTree from "./decision-tree.js"
6
- import randomInstances from "./random-instances.js"
7
- import removeInstance from "./remove-instance.js"
8
- import states from "./states.js"
9
-
10
- export default {
11
- title: "Engine/Recipes",
12
- component: UiChooser,
13
- }
14
-
15
- export const RandomInstances = {
16
- args: { config: randomInstances },
17
- }
18
-
19
- export const AddInstance = {
20
- args: { config: addInstance },
21
- }
22
-
23
- export const RemoveInstance = {
24
- args: { config: removeInstance },
25
- }
26
-
27
- export const AddAndRemove = {
28
- args: { config: addAndRemove },
29
- }
30
-
31
- export const States = {
32
- args: { config: states },
33
- }
34
-
35
- export const DecisionTree = {
36
- args: { config: decisionTree },
37
- }
@@ -1,52 +0,0 @@
1
- import { enableCharacter } from "@inglorious/game/decorators/character.js"
2
- import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
3
- import { random } from "@inglorious/utils/math/rng.js"
4
- import { pi } from "@inglorious/utils/math/trigonometry.js"
5
-
6
- export default {
7
- types: {
8
- mouse: [enableMouse()],
9
-
10
- character: [
11
- enableCharacter(),
12
- {
13
- // this event handler is needed in React
14
- "instance:click"(instance, event, { notify }) {
15
- notify({ id: "instance:remove", payload: event.payload })
16
- },
17
- },
18
- ],
19
- },
20
-
21
- instances: {
22
- mouse: {
23
- type: "mouse",
24
- position: [400, 0, 300],
25
- collisions: {
26
- hitbox: {
27
- shape: "circle",
28
- radius: 1,
29
- },
30
- },
31
- },
32
-
33
- ...Object.fromEntries(
34
- Array(5)
35
- .fill(null)
36
- .map((_, index) => [
37
- `character${index + 1}`,
38
- {
39
- type: "character",
40
- position: [random(0, 800), 0, random(0, 600)],
41
- orientation: random(0, 2 * pi(), 0.01),
42
- collisions: {
43
- hitbox: {
44
- shape: "circle",
45
- radius: 12,
46
- },
47
- },
48
- },
49
- ]),
50
- ),
51
- },
52
- }
@@ -1,64 +0,0 @@
1
- import arrive from "@inglorious/engine/ai/movement/kinematic/arrive.js"
2
- import wander from "@inglorious/engine/ai/movement/kinematic/wander.js"
3
- import { clampToBounds, flip } from "@inglorious/game/bounds.js"
4
- import { enableCharacter } from "@inglorious/game/decorators/character.js"
5
- import { enableFsm } from "@inglorious/game/decorators/fsm.js"
6
- import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
7
- import { merge } from "@inglorious/utils/data-structures/objects.js"
8
- import { length } from "@inglorious/utils/math/linear-algebra/vector.js"
9
- import { subtract } from "@inglorious/utils/math/linear-algebra/vectors.js"
10
- import { pi } from "@inglorious/utils/math/trigonometry.js"
11
-
12
- export default {
13
- types: {
14
- mouse: [enableMouse()],
15
-
16
- character: [
17
- enableCharacter(),
18
- enableFsm({
19
- meandering: {
20
- "game:update"(instance, event, options) {
21
- const { instances } = options
22
- const target = instances.mouse
23
-
24
- merge(instance, wander(instance, options))
25
- flip(instance, instances.game.bounds)
26
-
27
- if (length(subtract(instance.position, target.position)) < 200) {
28
- instance.state = "hunting"
29
- }
30
- },
31
- },
32
-
33
- hunting: {
34
- "game:update"(instance, event, options) {
35
- const { instances } = options
36
- const target = instances.mouse
37
-
38
- merge(instance, arrive(instance, target, options))
39
- clampToBounds(instance, instances.game.bounds)
40
-
41
- if (length(subtract(instance.position, target.position)) >= 200) {
42
- instance.state = "meandering"
43
- }
44
- },
45
- },
46
- }),
47
- ],
48
- },
49
-
50
- instances: {
51
- mouse: {
52
- type: "mouse",
53
- position: [0, 0, 0],
54
- },
55
-
56
- character: {
57
- type: "character",
58
- state: "meandering",
59
- maxSpeed: 250,
60
- maxAngularSpeed: pi() / 4,
61
- position: [400, 0, 300],
62
- },
63
- },
64
- }
@@ -1,28 +0,0 @@
1
- import { enableMouse } from "@inglorious/game/decorators/input/mouse.js"
2
- import { enableButton } from "@inglorious/game/decorators/ui/button.js"
3
-
4
- export default {
5
- types: {
6
- mouse: [enableMouse()],
7
-
8
- button: [
9
- enableButton(),
10
- {
11
- size: [100, 50, 0],
12
- color: "black",
13
- backgroundColor: "darkgrey",
14
- },
15
- ],
16
- },
17
-
18
- instances: {
19
- mouse: {
20
- type: "mouse",
21
- },
22
-
23
- rect1: {
24
- type: "button",
25
- position: [400, 0, 300],
26
- },
27
- },
28
- }
@@ -1,55 +0,0 @@
1
- import UiChooser from "@inglorious/docs/ui-chooser.jsx"
2
-
3
- export default {
4
- title: "UI/Form",
5
- component: UiChooser,
6
- args: { ui: "react" },
7
- }
8
-
9
- export const Default = {
10
- args: {
11
- config: {
12
- types: {
13
- form: {},
14
- },
15
-
16
- instances: {
17
- login: {
18
- type: "form",
19
- position: [150, 0, 600 - 160],
20
- fields: {
21
- username: {
22
- label: "Username",
23
- },
24
- password: {
25
- label: "Password",
26
- inputType: "password",
27
- },
28
- },
29
- groups: {
30
- extraInfo: {
31
- title: "Extra Info",
32
- fields: {
33
- kids: {
34
- label: "How many kids do you have?",
35
- inputType: "number",
36
- defaultValue: 0,
37
- },
38
- dogs: {
39
- label: "Do you like dogs?",
40
- inputType: "checkbox",
41
- defaultValue: true,
42
- },
43
- cats: {
44
- label: "Do you like cats?",
45
- inputType: "checkbox",
46
- defaultValue: true,
47
- },
48
- },
49
- },
50
- },
51
- },
52
- },
53
- },
54
- },
55
- }
@@ -1,6 +0,0 @@
1
- import CanvasGame from "@inglorious/docs/game.jsx"
2
- import ReactGame from "@inglorious/ui/react/game/index.jsx"
3
-
4
- export default function UiChooser({ ui = "canvas", ...props }) {
5
- return ui === "canvas" ? <CanvasGame {...props} /> : <ReactGame {...props} />
6
- }
@@ -1,47 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { filter, find, map, toString } from '@inglorious/utils/data-structures/object'
4
-
5
- <Meta title="Utils/Data Structures/Object" />
6
-
7
- # Object
8
-
9
- Functions that deal with a single object.
10
-
11
- ## Filter
12
-
13
- Behaves similar to `Array.prototype.filter`, returning an object that contains only properties that satisfy the given predicate.
14
-
15
- <code>const predicate = (key) =&gt; ['key2', 'key3'].includes(key)</code>&nbsp;
16
-
17
- <code>const obj = \{ key1: 'value1', key2: 'value2', key3: 'value3' \}</code>&nbsp;
18
-
19
- <code>filter(obj, predicate) == {toString(filter({ key1: 'value1', key2: 'value2', key3: 'value3' }, (key) => ['key2', 'key3'].includes(key)))}</code>&nbsp;
20
-
21
- ## Find
22
-
23
- Behaves similar to `Array.prototype.find`, returning an object that contains only the first property that satisfies the given predicate.
24
-
25
- <code>const predicate = (key) =&gt; ['key2', 'key3'].includes(key)</code>&nbsp;
26
-
27
- <code>const obj = \{ key1: 'value1', key2: 'value2', key3: 'value3' \}</code>&nbsp;
28
-
29
- <code>find(obj, predicate) == {toString(find({ key1: 'value1', key2: 'value2', key3: 'value3' }, (key) => ['key2', 'key3'].includes(key)))}</code>&nbsp;
30
-
31
- ## Map
32
-
33
- Behaves similar to `Array.prototype.map`, returning an object that has values transformed according to the given callback.
34
-
35
- <code>const callback = (key, value) =&gt; value.toUpperCase()</code>&nbsp;
36
-
37
- <code>const obj = \{ key1: 'value1', key2: 'value2', key3: 'value3' \}</code>&nbsp;
38
-
39
- <code>map(obj, callback) == {toString(map({ key1: 'value1', key2: 'value2', key3: 'value3' }, (key, value) => value.toUpperCase()))}</code>&nbsp;
40
-
41
- ## To String
42
-
43
- Returns a string representation of a given object.
44
-
45
- <code>const obj = \{ key1: 'value1', key2: 'value2', key3: 'value3' \}</code>&nbsp;
46
-
47
- <code>toString(obj) == "{toString({ key1: 'value1', key2: 'value2', key3: 'value3' })}"</code>&nbsp;
@@ -1,30 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { extend, merge } from '@inglorious/utils/data-structures/objects'
4
- import { toString } from '@inglorious/utils/data-structures/object'
5
-
6
- <Meta title="Utils/Data Structures/Objects" />
7
-
8
- # Objects
9
-
10
- Functions that deal with multiple object.
11
-
12
- ## Extend
13
-
14
- Extends an object with another, producing a new object as a result.
15
-
16
- <code>const obj1 = \{ a: 1, b: [2, 3], c: \{ d: 4 \}, e: [\{ f: 5 \}] \}</code>&nbsp;
17
-
18
- <code>const obj2 = \{ g: 6, b: [7], c: \{ h: 8 \}, e: [\{ i: 9 \}] \}</code>&nbsp;
19
-
20
- <code>extend(obj1, obj2) == {toString(extend({ a: 1, b: [2, 3], c: { d: 4 }, e: [{ f: 5 }] }, { g: 6, b: [7], c: { h: 8 }, e: [{ i: 9 }] }))}</code>&nbsp;
21
-
22
- ## Merge
23
-
24
- Performs a deep merge between multiple objects, changing the first object in place.
25
-
26
- <code>const obj1 = \{ a: 1, b: [2, 3], c: \{ d: 4 \}, e: [\{ f: 5 \}] \}</code>&nbsp;
27
-
28
- <code>const obj2 = \{ g: 6, b: [7], c: \{ h: 8 \}, e: [\{ i: 9 \}] \}</code>&nbsp;
29
-
30
- <code>merge(obj1, obj2) == {toString(merge({ a: 1, b: [2, 3], c: { d: 4 }, e: [{ f: 5 }] }, { g: 6, b: [7], c: { h: 8 }, e: [{ i: 9 }] }))}</code>&nbsp;
@@ -1,34 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { compose, pipe } from '@inglorious/utils/functions/functions'
4
- import { toString } from '@inglorious/utils/data-structures/object'
5
-
6
- <Meta title="Utils/Functions/Functions" />
7
-
8
- # Functions
9
-
10
- Basic functions that deal with ...functions.
11
-
12
- ## Compose
13
-
14
- Implements function composition, which expects functions to wrap each other.
15
-
16
- <code>const shout = (x) => x.toUpperCase()</code>&nbsp;
17
-
18
- <code>const punctuate = (mark) => (x) => \`$\{x\}$\{mark\}\`</code>&nbsp;
19
-
20
- <code>const html = (tag) => (x) => \`\<$\{tag\}>$\{x\}\</$\{tag\}>\`</code>&nbsp;
21
-
22
- <code>compose(html('p'), punctuate('!'), shout)("Hello world") == {toString(compose((x) => `<${"p"}>${x}</${"p"}>`, (x) => `${x}${"!"}`, (x) => x.toUpperCase())("Hello world"))}</code>&nbsp;
23
-
24
- ## Pipe
25
-
26
- Implements function piping, which functions to be processed one after the other in order.
27
-
28
- <code>const shout = (x) => x.toUpperCase()</code>&nbsp;
29
-
30
- <code>const punctuate = (mark) => (x) => \`$\{x\}$\{mark\}\`</code>&nbsp;
31
-
32
- <code>const html = (tag) => (x) => \`\<$\{tag\}>$\{x\}\</$\{tag\}>\`</code>&nbsp;
33
-
34
- <code>pipe(shout, punctuate('!'), html('p'))("Hello world") == {toString(pipe((x) => x.toUpperCase(), ((mark) => (x) => `${x}${mark}`)("!"), ((tag) => (x) => `<${tag}>${x}</${tag}>`)("p"))("Hello world"))}</code>&nbsp;
@@ -1,55 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { toString } from '@inglorious/utils/data-structures/boolean.js'
4
- import { intersectsCircle, intersectsPlatform, intersectsPoint, intersectsRectangle } from '@inglorious/utils/math/geometry/circle.js'
5
-
6
- <Meta title="Utils/Math/Geometry/Circle" />
7
-
8
- # Circle
9
-
10
- Intersection functions for a circle.
11
-
12
- ## Intersects Point
13
-
14
- Checks if a circle intersects with a point.
15
-
16
- <code>intersectsPoint(\{ position: [1, 1, 0], radius: 1 }, [1.5, 1.5, 0]) == {toString(intersectsPoint({ position: [1, 1, 0], radius: 1 }, [1.5, 1.5, 0]))}</code>&nbsp;
17
-
18
-
19
- ## Intersects Circle
20
-
21
- Checks if a circle intersects with another circle.
22
-
23
- <code>intersectsCircle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [1, 1, 0], radius: 1 \}) == {toString(intersectsCircle({ position: [1, 1, 0], radius: 1 }, { position: [1, 1, 0], radius: 1 }))}</code>&nbsp;
24
-
25
- <code>intersectsCircle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [2, 1, 0], radius: 1 \}) == {toString(intersectsCircle({ position: [1, 1, 0], radius: 1 }, { position: [2, 1, 0], radius: 1 }))}</code>&nbsp;
26
-
27
- <code>intersectsCircle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [3, 1, 0], radius: 1 \}) == {toString(intersectsCircle({ position: [1, 1, 0], radius: 1 }, { position: [3, 1, 0], radius: 1 }))}</code>&nbsp;
28
-
29
- <code>intersectsCircle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [4, 1, 0], radius: 1 \}) == {toString(intersectsCircle({ position: [1, 1, 0], radius: 1 }, { position: [4, 1, 0], radius: 1 }))}</code>&nbsp;
30
-
31
- ## Intersects Rectangle
32
-
33
- Checks if a circle intersects with a rectangle.
34
-
35
- <code>intersectsRectangle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [-1, -1, 0], size: [4, 4, 0] \}) == {toString(intersectsRectangle({ position: [1, 1, 0], radius: 1 }, { position: [-1, -1, 0], size: [4, 4, 0] }))}</code>&nbsp;
36
-
37
- <code>intersectsRectangle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [-2, 0, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle({ position: [1, 1, 0], radius: 1 }, { position: [-2, 0, 0], size: [2, 2, 0] }))}</code>&nbsp;
38
-
39
- <code>intersectsRectangle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [-1, -1, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle({ position: [1, 1, 0], radius: 1 }, { position: [-1, -1, 0], size: [2, 2, 0] }))}</code>&nbsp;
40
-
41
- <code>intersectsRectangle(\{ position: [1, 1, 0], radius: 1 }, \{ position: [-3, 0, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle({ position: [1, 1, 0], radius: 1 }, { position: [-3, 0, 0], size: [2, 2, 0] }))}</code>&nbsp;
42
-
43
- ## Intersects Platform
44
-
45
- Checks if a circle intersects with a platform.
46
-
47
- <code>intersectsPlatform(\{ position: [1, 0, 1], radius: 1 }, \{ position: [-1, 0, 0], size: [2, 1] \}) == {toString(intersectsPlatform({ position: [1, 1, 0], radius: 1 }, { position: [-1, 0, 0], size: [2, 1, 0] }))}</code>&nbsp;
48
-
49
- <code>intersectsPlatform(\{ position: [1, 0, 1], radius: 1 }, \{ position: [0, 0, -2], size: [2, 1] \}) == {toString(intersectsPlatform({ position: [1, 1, 0], radius: 1 }, { position: [0, -1, ], size: [2, 1, 0] }))}</code>&nbsp;
50
-
51
- <code>intersectsPlatform(\{ position: [1, 0, 1], radius: 1 }, \{ position: [-1, 0, -1], size: [2, 2] \}) == {toString(intersectsPlatform({ position: [1, 1, 0], radius: 1 }, { position: [-1, -1, 0], size: [2, 2, 0] }))}</code>&nbsp;
52
-
53
- <code>intersectsPlatform(\{ position: [1, 0, 1], radius: 1 }, \{ position: [0, 0, 2], size: [2, 1] \}) == {toString(intersectsPlatform({ position: [1, 1, 0], radius: 1 }, { position: [0, 2, 0], size: [2, 1, 0] }))}</code>&nbsp;
54
-
55
- <code>intersectsPlatform(\{ position: [1, 0, 1], radius: 1 }, \{ position: [-3, 0, -1], size: [2, 1] \}) == {toString(intersectsPlatform({ position: [1, 1, 0], radius: 1 }, { position: [-3, -1, 0], size: [2, 1, 0] }))}</code>&nbsp;
@@ -1,38 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { toString } from '@inglorious/utils/data-structures/boolean.js'
4
- import { intersectsPoint, intersectsCircle, intersectsRectangle } from '@inglorious/utils/math/geometry/point.js'
5
-
6
- <Meta title="Utils/Math/Geometry/Point" />
7
-
8
- # Point
9
-
10
- Intersection functions for a point.
11
-
12
- ## Intersects Point
13
-
14
- Checks if a point is in the same place as another.
15
-
16
- <code>intersectsPoint([1.5, 1.5, 0], [1.5, 1.5, 0]) == {toString(intersectsPoint([1.5, 1.5, 0], [1.5, 1.5, 0]))}</code>&nbsp;
17
-
18
- <code>intersectsPoint([1.5, 1.5, 0], [2, 1, 0]) == {toString(intersectsPoint([1.5, 1.5, 0], [2, 1, 0]))}</code>&nbsp;
19
-
20
- ## Intersects Circle
21
-
22
- Checks if a point is inside of a circle.
23
-
24
- <code>intersectsCircle([1.5, 1.5, 0], \{ position: [1, 1, 0], radius: 1 \}) == {toString(intersectsCircle([1.5, 1.5, 0], { position: [1, 1, 0], radius: 1 }))}</code>&nbsp;
25
-
26
- <code>intersectsCircle([2, 1, 0], \{ position: [1, 1, 0], radius: 1 \}) == {toString(intersectsCircle([2, 1, 0], { position: [1, 1, 0], radius: 1 }))}</code>&nbsp;
27
-
28
- <code>intersectsCircle([2, 2, 0], \{ position: [1, 1, 0], radius: 1 \}) == {toString(intersectsCircle([2, 2, 0], { position: [1, 1, 0], radius: 1 }))}</code>&nbsp;
29
-
30
- ## Intersects Rectangle
31
-
32
- Checks if a point is inside of a rectangle.
33
-
34
- <code>intersectsRectangle([1.5, 1.5, 0], \{ position: [1, 1, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle([1.5, 1.5, 0], { position: [1, 1, 0], size: [2, 2, 0] }))}</code>&nbsp;
35
-
36
- <code>intersectsRectangle([2, 1, 0], \{ position: [1, 1, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle([2, 1, 0], { position: [1, 1, 0], size: [2, 2, 0] }))}</code>&nbsp;
37
-
38
- <code>intersectsRectangle([2.5, 2.5, 0], \{ position: [1, 1, 0], size: [2, 2, 0] \}) == {toString(intersectsRectangle([2.5, 2.5, 0], { position: [1, 1, 0], size: [2, 2, 0] }))}</code>&nbsp;
@@ -1,24 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { toString } from '@inglorious/utils/data-structures/boolean.js'
4
- import { intersectsPlatform } from '@inglorious/utils/math/geometry/rectangle.js'
5
-
6
- <Meta title="Utils/Math/Geometry/Rectangle" />
7
-
8
- # Rectangle
9
-
10
- Intersection functions for a rectangle.
11
-
12
- ## Intersects Platform
13
-
14
- Checks if a rectangle intersects with a platform.
15
-
16
- <code>intersectsPlatform(\{ position: [0, 0, 0], size: [2, 2, 0] }, \{ position: [0, -1, 0], size: [2, 2, 0] \}) == {toString(intersectsPlatform({ position: [0, 0, 0], size: [2, 2, 0] }, { position: [0, -1, 0], size: [2, 2, 0] }))}</code>&nbsp;
17
-
18
- <code>intersectsPlatform(\{ position: [0, 0, 0], size: [2, 2, 0] }, \{ position: [0, -2, 0], size: [2, 2, 0] \}) == {toString(intersectsPlatform({ position: [0, 0, 0], size: [2, 2, 0] }, { position: [0, -2, 0], size: [2, 2, 0] }))}</code>&nbsp;
19
-
20
- <code>intersectsPlatform(\{ position: [0, 0, 0], size: [2, 2, 0] }, \{ position: [0, 1, 0], size: [2, 2, 0] \}) == {toString(intersectsPlatform({ position: [0, 0, 0], size: [2, 2, 0] }, { position: [0, 1, 0], size: [2, 2, 0] }))}</code>&nbsp;
21
-
22
- <code>intersectsPlatform(\{ position: [0, 0, 0], size: [2, 2, 0] }, \{ position: [0, -3, 0], size: [2, 2, 0] \}) == {toString(intersectsPlatform({ position: [0, 0, 0], size: [2, 2, 0] }, { position: [0, -3, 0], size: [2, 2, 0] }))}</code>&nbsp;
23
-
24
- <code>intersectsPlatform(\{ position: [0, 0, 0], size: [2, 2, 0] }, \{ position: [-3, 0, 0], size: [2, 2, 0] \}) == {toString(intersectsPlatform({ position: [0, 0, 0], size: [2, 2, 0] }, { position: [-3, 0, 0], size: [2, 2, 0] }))}</code>&nbsp;
@@ -1,55 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { toString } from '@inglorious/utils/data-structures/boolean.js'
4
- import { toString as vToString } from '@inglorious/utils/math/linear-algebra/vector.js'
5
- import { coefficients, distanceFromPoint, intersectsCircle } from '@inglorious/utils/math/geometry/segment.js'
6
-
7
- <Meta title="Utils/Math/Geometry/Segment" />
8
-
9
- # Segment
10
-
11
- Utility functions for line segments.
12
-
13
- ## Coefficients
14
-
15
- Retrieves values of *a*, *b*, and *c* from a segment, so it looks like a line in the form *ax + by + c = 0*.
16
-
17
- <code>coefficients(\{ from: [0, 0, 0], to: [2, 0, 1] \}) == {vToString(coefficients({ from: [0, 0, 0], to: [2, 0, 1] }))}</code>&nbsp;
18
-
19
- ## Distance from point
20
-
21
- Computes the distance between a segment and a point.
22
-
23
- <code>distanceFromPoint(\{ from: [0, 0, 0], to: [3, 0, 4] \}, [5, 0, 0]) == {distanceFromPoint({ from: [0, 0, 0], to: [3, 0, 4] }, [5, 0, 0])}</code>&nbsp;
24
-
25
- If the point rests on the segment, it will return zero.
26
-
27
- <code>distanceFromPoint(\{ from: [0, 0, 0], to: [2, 0, 2] \}, [1, 0, 1]) == {distanceFromPoint({ from: [0, 0, 0], to: [2, 0, 2] }, [1, 0, 1]).toFixed(0)}</code>&nbsp;
28
-
29
- If the point does not project on the segment, returns the distance between the point and the closest end of the segment.
30
-
31
- <code>distanceFromPoint(\{ from: [0, 0, 0], to: [3, 0, 4] \}, [-2, 0, 0]) == {distanceFromPoint({ from: [0, 0, 0], to: [3, 0, 4] }, [-2, 0, 0])}</code>&nbsp;
32
-
33
- <code>distanceFromPoint(\{ from: [0, 0, 0], to: [3, 0, 4] \}, [5, 0, 4]) == {distanceFromPoint({ from: [0, 0, 0], to: [3, 0, 4] }, [5, 0, 4])}</code>&nbsp;
34
-
35
- ## Intersects circle
36
-
37
- Checks if a segment overlaps with a circle.
38
-
39
- <code>intersectsCircle(\{ from: [0, 0, 0], to: [2, 0, 2] \}, \{ position: [1, 0, 1], radius: 1 \}) == {toString(intersectsCircle({ from: [0, 0, 0], to: [2, 0, 2] }, { position: [1, 0, 1], radius: 1 }))}</code>&nbsp;
40
-
41
- A segment tangent to the circle is considered to be intersecting with it.
42
-
43
- <code>intersectsCircle(\{ from: [0, 0, 0], to: [0, 0, 2] \}, \{ position: [1, 0, 1], radius: 1 \}) == {toString(intersectsCircle({ from: [0, 0, 0], to: [0, 0, 2] }, { position: [1, 0, 1], radius: 1 }))}</code>&nbsp;
44
-
45
- A segment resting inside of the circle is considered to be intersecting with it.
46
-
47
- <code>intersectsCircle(\{ from: [0.5, 0, 0.5], to: [1.5, 0, 1.5] \}, \{ position: [1, 0, 1], radius: 1 \}) == {toString(intersectsCircle({ from: [0.5, 0, 0.5], to: [1.5, 0, 1.5] }, { position: [1, 0, 1], radius: 1 }))}</code>&nbsp;
48
-
49
- A segment that does not cross a circle does not intersect with it.
50
-
51
- <code>intersectsCircle(\{ from: [0, 0, 0], to: [-2, 0, -2] \}, \{ position: [1, 0, 1], radius: 1 \}) == {toString(intersectsCircle({ from: [0, 0, 0], to: [-2, 0, 2] }, { position: [1, 0, 1], radius: 1 }))}</code>&nbsp;
52
-
53
- A segment is different from a line: even if its continuation would cross the circle, the segment itself does not.
54
-
55
- <code>intersectsCircle(\{ from: [0, 0, 0], to: [-1, 0, -2] \}, \{ position: [1, 0, 1], radius: 1 \}) == {toString(intersectsCircle({ from: [0, 0, 0], to: [-1, 0, 2] }, { position: [1, 0, 1], radius: 1 }))}</code>&nbsp;
@@ -1,22 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { toString } from '@inglorious/utils/data-structures/boolean.js'
4
- import { hypothenuse, pythagoras } from '@inglorious/utils/math/geometry/triangle.js'
5
-
6
- <Meta title="Utils/Math/Geometry/Triangle" />
7
-
8
- # Triangle
9
-
10
- Basic triangle geometry functions.
11
-
12
- ## Hypothenuse
13
-
14
- Uses Pythagora's theorem to calculate the hypothenuse of a right triangle (alias `pythagoras`).
15
-
16
- <code>hypothenuse(3, 4) == {hypothenuse(3, 4)}</code>&nbsp;
17
-
18
- ## Pythagoras
19
-
20
- Alias of `hypothenuse`.
21
-
22
- <code>pythagoras(3, 4) == {pythagoras(3, 4)}</code>&nbsp;
@@ -1,22 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { from2D, to2D } from '@inglorious/utils/math/linear-algebra/2d'
4
- import { toString } from '@inglorious/utils/math/linear-algebra/vector'
5
-
6
- <Meta title="Utils/Math/Linear Algebra/2D" />
7
-
8
- # 2D
9
-
10
- Functions to convert any vector to 2D and viceversa.
11
-
12
- ## From 2D
13
-
14
- Builds a 3D vector from a 2D one.
15
-
16
- <code>from2D([3, 4]) == {toString(from2D([3, 4]))}</code>&nbsp;
17
-
18
- ## To 2D
19
-
20
- Builds a 2D vector from a 3D one.
21
-
22
- <code>to2D([3, 0, 4]) == {toString(to2D([3, 0, 4]))}</code>&nbsp;
@@ -1,21 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { quaternion } from '@inglorious/utils/math/linear-algebra/quaternion'
4
- import { toString } from '@inglorious/utils/math/linear-algebra/vector'
5
- import { pi } from '@inglorious/utils/math/trigonometry'
6
-
7
- <Meta title="Utils/Math/Linear Algebra/Quaternion" />
8
-
9
- # Quaternion
10
-
11
- Functions to deal with a single quaternion.
12
-
13
- ## Quaternion
14
-
15
- Creates a quaternion from any angle.
16
-
17
- <code>quaternion(0) == {toString(quaternion(0))}</code>&nbsp;
18
-
19
- <code>quaternion(pi() / 2) == {toString(quaternion(pi() / 2), 3)}</code> (&asymp;[cos(&pi;/4), 0, sin(&pi;/4), 0])
20
-
21
- <code>quaternion(-pi() / 2) == {toString(quaternion(-pi() / 2), 3)}</code> (&asymp;[cos(-&pi;/4), 0, sin(-&pi;/4), 0])
@@ -1,22 +0,0 @@
1
- import { Meta } from '@storybook/blocks'
2
-
3
- import { combine } from '@inglorious/utils/math/linear-algebra/quaternions'
4
- import { quaternion } from '@inglorious/utils/math/linear-algebra/quaternion'
5
- import { toString } from '@inglorious/utils/math/linear-algebra/vector'
6
- import { pi } from '@inglorious/utils/math/trigonometry'
7
-
8
- <Meta title="Utils/Math/Linear Algebra/Quaternions" />
9
-
10
- # Quaternions
11
-
12
- Functions that deal with multiple quaternions.
13
-
14
- ## Combine
15
-
16
- Multiplies two quaternions together. The algorithm used is the second approach described in [Wikipedia](https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Used_methods).
17
-
18
- <code>combine(quaternion(0), quaternion(0)) == {toString(combine(quaternion(0), quaternion(0)))}</code>&nbsp;
19
-
20
- <code>combine(quaternion(0), quaternion(pi() / 2)) == {toString(combine(quaternion(0), quaternion(pi() / 2)), 3)}</code> (&asymp;[cos(&pi;/4), 0, sin(&pi;/4), 0])
21
-
22
- <code>combine(quaternion(pi() / 2), quaternion(pi() / 2)) == {toString(combine(quaternion(pi() / 2), quaternion(pi() / 2)))}</code>&nbsp;