@typeonce/ritmo-math 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/README.md +17 -12
- package/dist/Angle.d.ts +44 -0
- package/dist/Angle.d.ts.map +1 -0
- package/dist/Angle.js +62 -0
- package/dist/Angle.js.map +1 -0
- package/dist/Box2.d.ts +16 -4
- package/dist/Box2.d.ts.map +1 -1
- package/dist/Box2.js +16 -1
- package/dist/Box2.js.map +1 -1
- package/dist/Collide2.d.ts +11 -1
- package/dist/Collide2.d.ts.map +1 -1
- package/dist/Collide2.js +16 -1
- package/dist/Collide2.js.map +1 -1
- package/dist/FlowField.d.ts +24 -38
- package/dist/FlowField.d.ts.map +1 -1
- package/dist/FlowField.js +18 -5
- package/dist/FlowField.js.map +1 -1
- package/dist/Scalar.d.ts +19 -166
- package/dist/Scalar.d.ts.map +1 -1
- package/dist/Scalar.js +51 -51
- package/dist/Scalar.js.map +1 -1
- package/dist/Vec2.d.ts +47 -7
- package/dist/Vec2.d.ts.map +1 -1
- package/dist/Vec2.js +56 -8
- package/dist/Vec2.js.map +1 -1
- package/dist/index.d.ts +9 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Angle.ts +60 -0
- package/src/Box2.ts +20 -4
- package/src/Collide2.ts +18 -2
- package/src/FlowField.ts +34 -10
- package/src/Scalar.ts +43 -165
- package/src/Vec2.ts +58 -8
- package/src/index.ts +9 -22
- package/dist/Aabb.d.ts +0 -182
- package/dist/Aabb.d.ts.map +0 -1
- package/dist/Aabb.js +0 -109
- package/dist/Aabb.js.map +0 -1
- package/dist/InputAxis.d.ts +0 -44
- package/dist/InputAxis.d.ts.map +0 -1
- package/dist/InputAxis.js +0 -71
- package/dist/InputAxis.js.map +0 -1
- package/dist/Ops.d.ts +0 -209
- package/dist/Ops.d.ts.map +0 -1
- package/dist/Ops.js +0 -210
- package/dist/Ops.js.map +0 -1
- package/dist/Random.d.ts +0 -124
- package/dist/Random.d.ts.map +0 -1
- package/dist/Random.js +0 -126
- package/dist/Random.js.map +0 -1
- package/dist/Size2.d.ts +0 -118
- package/dist/Size2.d.ts.map +0 -1
- package/dist/Size2.js +0 -54
- package/dist/Size2.js.map +0 -1
- package/dist/SpatialGrid.d.ts +0 -68
- package/dist/SpatialGrid.d.ts.map +0 -1
- package/dist/SpatialGrid.js +0 -112
- package/dist/SpatialGrid.js.map +0 -1
- package/dist/Vector2.d.ts +0 -214
- package/dist/Vector2.d.ts.map +0 -1
- package/dist/Vector2.js +0 -134
- package/dist/Vector2.js.map +0 -1
- package/dist/internal/aabb.d.ts +0 -27
- package/dist/internal/aabb.d.ts.map +0 -1
- package/dist/internal/aabb.js +0 -52
- package/dist/internal/aabb.js.map +0 -1
- package/dist/internal/codec.d.ts +0 -9
- package/dist/internal/codec.d.ts.map +0 -1
- package/dist/internal/codec.js +0 -16
- package/dist/internal/codec.js.map +0 -1
- package/dist/internal/fdlibm.d.ts +0 -43
- package/dist/internal/fdlibm.d.ts.map +0 -1
- package/dist/internal/fdlibm.js +0 -1291
- package/dist/internal/fdlibm.js.map +0 -1
- package/dist/internal/inputAxis.d.ts +0 -11
- package/dist/internal/inputAxis.d.ts.map +0 -1
- package/dist/internal/inputAxis.js +0 -13
- package/dist/internal/inputAxis.js.map +0 -1
- package/dist/internal/scalar.d.ts +0 -11
- package/dist/internal/scalar.d.ts.map +0 -1
- package/dist/internal/scalar.js +0 -68
- package/dist/internal/scalar.js.map +0 -1
- package/dist/internal/size2.d.ts +0 -22
- package/dist/internal/size2.d.ts.map +0 -1
- package/dist/internal/size2.js +0 -38
- package/dist/internal/size2.js.map +0 -1
- package/dist/internal/vector2.d.ts +0 -39
- package/dist/internal/vector2.d.ts.map +0 -1
- package/dist/internal/vector2.js +0 -78
- package/dist/internal/vector2.js.map +0 -1
- package/src/Aabb.ts +0 -180
- package/src/InputAxis.ts +0 -81
- package/src/Ops.ts +0 -232
- package/src/Random.ts +0 -225
- package/src/Size2.ts +0 -122
- package/src/SpatialGrid.ts +0 -172
- package/src/Vector2.ts +0 -216
- package/src/internal/aabb.ts +0 -81
- package/src/internal/codec.ts +0 -21
- package/src/internal/fdlibm.ts +0 -1256
- package/src/internal/inputAxis.ts +0 -21
- package/src/internal/scalar.ts +0 -104
- package/src/internal/size2.ts +0 -54
- package/src/internal/vector2.ts +0 -121
package/src/Vec2.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plain two-dimensional vector arithmetic for hot paths.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* these helpers without conversion.
|
|
4
|
+
* Values are immutable `{ x, y }` records and every helper returns a new
|
|
5
|
+
* one, so a component's value (validated once by the game's schema when it
|
|
6
|
+
* entered the world) passes straight in. Lengths and angles go through
|
|
7
|
+
* `Ops`, so the results replay the same on every engine.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```ts
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
* Immutable arithmetic, measurement, and steering helpers.
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
|
-
import * as Ops from "
|
|
26
|
+
import * as Ops from "@typeonce/ritmo/Ops"
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* A two-dimensional vector in world units.
|
|
@@ -65,7 +64,8 @@ export const subtract = (a: Vec2, b: Vec2): Vec2 => ({ x: a.x - b.x, y: a.y - b.
|
|
|
65
64
|
export const scale = (a: Vec2, factor: number): Vec2 => ({ x: a.x * factor, y: a.y * factor })
|
|
66
65
|
|
|
67
66
|
/**
|
|
68
|
-
* `a` turned by `angle` radians (counter-clockwise for a y-up frame).
|
|
67
|
+
* `a` turned by `angle` radians (counter-clockwise for a y-up frame). For a
|
|
68
|
+
* quarter turn use {@link perpendicular}, which is exact.
|
|
69
69
|
*
|
|
70
70
|
* @category Operations
|
|
71
71
|
*/
|
|
@@ -76,12 +76,43 @@ export const rotate = (a: Vec2, angle: number): Vec2 => {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* `a` turned a quarter turn counter-clockwise (for a y-up frame):
|
|
80
|
+
* `{ x: -a.y, y: a.x }`. Exact. For the normal of a wall or a direction, a
|
|
81
|
+
* sideways push, and the signed side of a point: `dot(perpendicular(forward),
|
|
82
|
+
* offset)` is positive on the left of `forward`, negative on its right.
|
|
83
|
+
*
|
|
84
|
+
* @category Operations
|
|
85
|
+
*/
|
|
86
|
+
export const perpendicular = (a: Vec2): Vec2 => ({ x: -a.y, y: a.x })
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Dot product. With {@link perpendicular} it is also the 2D cross product:
|
|
90
|
+
* `dot(perpendicular(a), b)`.
|
|
80
91
|
*
|
|
81
92
|
* @category Operations
|
|
82
93
|
*/
|
|
83
94
|
export const dot = (a: Vec2, b: Vec2): number => a.x * b.x + a.y * b.y
|
|
84
95
|
|
|
96
|
+
/**
|
|
97
|
+
* The unit vector at `angle` radians from the x axis (counter-clockwise for a
|
|
98
|
+
* y-up frame), through `Ops.cos` and `Ops.sin`. Multiply by a length with
|
|
99
|
+
* {@link scale}. The inverse of {@link angle}.
|
|
100
|
+
*
|
|
101
|
+
* @category Operations
|
|
102
|
+
*/
|
|
103
|
+
export const fromAngle = (angle: number): Vec2 => ({ x: Ops.cos(angle), y: Ops.sin(angle) })
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The angle of `a` from the x axis in radians, in (-π, π], through
|
|
107
|
+
* `Ops.atan2` (so no `y, x` argument order to get wrong). The zero vector
|
|
108
|
+
* gives 0, and so does `-0` in either coordinate where `Ops.atan2` would give
|
|
109
|
+
* `-0` or flip to -π. To keep it in `Angle`'s range [-π, π), use
|
|
110
|
+
* `Angle.wrap`; to turn toward it, `Angle.turnToward`.
|
|
111
|
+
*
|
|
112
|
+
* @category Operations
|
|
113
|
+
*/
|
|
114
|
+
export const angle = (a: Vec2): number => Ops.atan2(a.y + 0, a.x + 0)
|
|
115
|
+
|
|
85
116
|
/**
|
|
86
117
|
* Length of `a`.
|
|
87
118
|
*
|
|
@@ -155,3 +186,22 @@ export const clampLength = (a: Vec2, max: number): Vec2 => {
|
|
|
155
186
|
const len = Ops.hypot(a.x, a.y)
|
|
156
187
|
return len <= max ? a : { x: (a.x / len) * max, y: (a.y / len) * max }
|
|
157
188
|
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Moves `current` toward `target` by the share `rate` closes per second, over
|
|
192
|
+
* `dt` seconds, with one shared factor `exp(-rate * dt)` so the point moves
|
|
193
|
+
* along the straight line: the same total time gives the same result at any
|
|
194
|
+
* step rate. `current` unchanged when `rate * dt` is 0 or less, `target`
|
|
195
|
+
* itself when `rate` is `Infinity` (and `dt` positive). It nears `target`
|
|
196
|
+
* without reaching it; when it must arrive, use {@link moveToward}. For
|
|
197
|
+
* plain numbers use `Scalar.decayToward`.
|
|
198
|
+
*
|
|
199
|
+
* @category Operations
|
|
200
|
+
*/
|
|
201
|
+
export const decayToward = (current: Vec2, target: Vec2, rate: number, dt: number): Vec2 => {
|
|
202
|
+
const k = rate * dt
|
|
203
|
+
if (!(k > 0)) return current
|
|
204
|
+
if (k === Infinity) return target
|
|
205
|
+
const factor = Ops.exp(-k)
|
|
206
|
+
return { x: target.x + (current.x - target.x) * factor, y: target.y + (current.y - target.y) * factor }
|
|
207
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The 2D helpers most games would otherwise rewrite, as plain data in and
|
|
3
|
+
* plain data out, built on `Ops` so they replay the same on every engine.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `Box2` edges, `Segment2` walls at any angle, `Collide2` swept circle
|
|
11
|
-
* collision against both, a `SpatialGrid` broad
|
|
12
|
-
* phase, a `FlowField` for finding the way around walls, and a deterministic
|
|
13
|
-
* `Random` whose state is one integer.
|
|
14
|
-
*
|
|
15
|
-
* `Ops` holds the math functions engines are allowed to approximate (`sin`,
|
|
16
|
-
* `cos`, `atan2`, `exp`, `pow`, `hypot`, ...) as ports that return the same
|
|
17
|
-
* bits everywhere: use them in simulation code instead of `Math`'s.
|
|
5
|
+
* `Vec2` arithmetic and angles of vectors, `Angle` for headings, `Scalar` for
|
|
6
|
+
* numbers moving toward a target, `Box2` edge boxes and `Segment2` walls at
|
|
7
|
+
* any angle, `Collide2` swept circle collision against both that slides
|
|
8
|
+
* along walls and never tunnels, and a `FlowField` that leads bodies around
|
|
9
|
+
* walls. Values are validated by the game's own schema when they enter the
|
|
10
|
+
* world; `Ops` and `Random` are in `@typeonce/ritmo`.
|
|
18
11
|
*/
|
|
19
|
-
export * as
|
|
12
|
+
export * as Angle from "./Angle.ts"
|
|
20
13
|
export * as Box2 from "./Box2.ts"
|
|
21
14
|
export * as Collide2 from "./Collide2.ts"
|
|
22
15
|
export * as FlowField from "./FlowField.ts"
|
|
23
|
-
export * as InputAxis from "./InputAxis.ts"
|
|
24
|
-
export * as Ops from "./Ops.ts"
|
|
25
|
-
export * as Random from "./Random.ts"
|
|
26
16
|
export * as Scalar from "./Scalar.ts"
|
|
27
17
|
export * as Segment2 from "./Segment2.ts"
|
|
28
|
-
export * as Size2 from "./Size2.ts"
|
|
29
|
-
export * as SpatialGrid from "./SpatialGrid.ts"
|
|
30
18
|
export * as Vec2 from "./Vec2.ts"
|
|
31
|
-
export * as Vector2 from "./Vector2.ts"
|
package/dist/Aabb.d.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Branded axis-aligned bounding boxes built from validated vectors and sizes.
|
|
3
|
-
*
|
|
4
|
-
* The public shape is centered: each AABB is described by a center position and
|
|
5
|
-
* a non-negative size. Geometry helpers derive edges and overlap relationships
|
|
6
|
-
* without mutating the original value.
|
|
7
|
-
*
|
|
8
|
-
* In game code this is the natural helper for collision volumes, trigger
|
|
9
|
-
* regions, camera bounds, and spatial authored data that should stay validated
|
|
10
|
-
* and immutable after construction. For the per-frame collision tests of
|
|
11
|
-
* `Collide2` and `FlowField`, build a plain `Box2` (edge form) from it once.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Build a collision volume from raw authored data.
|
|
16
|
-
* const player = Aabb.result({
|
|
17
|
-
* position: { x: 0, y: 0 },
|
|
18
|
-
* size: { width: 16, height: 16 }
|
|
19
|
-
* })
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @module Aabb
|
|
23
|
-
* @docGroup data-structures
|
|
24
|
-
*
|
|
25
|
-
* @categoryDescription AABB Types
|
|
26
|
-
* Raw, branded, and error shapes for centered axis-aligned bounding boxes.
|
|
27
|
-
*
|
|
28
|
-
* @categoryDescription Construction
|
|
29
|
-
* Non-throwing constructor boundaries for converting raw position and size input into branded AABBs.
|
|
30
|
-
*
|
|
31
|
-
* @categoryDescription Accessors
|
|
32
|
-
* Pure readers that expose center, size, and derived edge positions.
|
|
33
|
-
*
|
|
34
|
-
* @categoryDescription Operations
|
|
35
|
-
* Immutable geometry helpers for translation and overlap checks.
|
|
36
|
-
*/
|
|
37
|
-
import type * as Brand from "@typeonce/ritmo/Brand";
|
|
38
|
-
import type { StandardSchema } from "@typeonce/ritmo/Descriptor";
|
|
39
|
-
import type * as Result from "@typeonce/ritmo/Result";
|
|
40
|
-
import type * as Scalar from "./Scalar.ts";
|
|
41
|
-
import type * as Size2 from "./Size2.ts";
|
|
42
|
-
import type * as Vector2 from "./Vector2.ts";
|
|
43
|
-
/**
|
|
44
|
-
* Raw AABB input accepted by the public constructors.
|
|
45
|
-
*
|
|
46
|
-
* @category AABB Types
|
|
47
|
-
*/
|
|
48
|
-
export type Raw = {
|
|
49
|
-
readonly position: Vector2.Raw;
|
|
50
|
-
readonly size: Size2.Raw;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Validated centered axis-aligned bounding box.
|
|
54
|
-
*
|
|
55
|
-
* @category AABB Types
|
|
56
|
-
*/
|
|
57
|
-
export type Aabb = Brand.Branded<{
|
|
58
|
-
readonly position: Vector2.Vector2;
|
|
59
|
-
readonly size: Size2.Size2;
|
|
60
|
-
}, "Aabb">;
|
|
61
|
-
/**
|
|
62
|
-
* Structured AABB-construction failure.
|
|
63
|
-
*
|
|
64
|
-
* @category AABB Types
|
|
65
|
-
*/
|
|
66
|
-
export type Error = {
|
|
67
|
-
readonly tag: "Aabb/InvalidPosition";
|
|
68
|
-
readonly error: Vector2.Error;
|
|
69
|
-
readonly input: Raw;
|
|
70
|
-
} | {
|
|
71
|
-
readonly tag: "Aabb/InvalidSize";
|
|
72
|
-
readonly error: Size2.Error;
|
|
73
|
-
readonly input: Raw;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Validates one raw AABB and returns an explicit result.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* const playerBox = Aabb.result({
|
|
81
|
-
* position: { x: 24, y: 24 },
|
|
82
|
-
* size: { width: 16, height: 16 }
|
|
83
|
-
* })
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @category Construction
|
|
87
|
-
*/
|
|
88
|
-
export declare const result: (raw: Raw) => Result.Result<Aabb, Error>;
|
|
89
|
-
/**
|
|
90
|
-
* The codec of `Aabb` (a Standard Schema, see `Descriptor.Codec`): give it to
|
|
91
|
-
* `Descriptor.ConstructedComponent(...)` so raw input and saves are validated.
|
|
92
|
-
* Its saved form is the raw shape, so it needs no `encode`. To put a `Aabb`
|
|
93
|
-
* inside your own object schema, use {@link is} with your library's guard
|
|
94
|
-
* schema (`Schema.declare`, `z.custom`).
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* const Position = Descriptor.ConstructedComponent(Aabb.codec)("Game/Position")
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* @category Construction
|
|
102
|
-
*/
|
|
103
|
-
export declare const codec: StandardSchema<Raw, Aabb>;
|
|
104
|
-
/**
|
|
105
|
-
* Validates one raw AABB and returns `null` on failure.
|
|
106
|
-
*
|
|
107
|
-
* @category Construction
|
|
108
|
-
*/
|
|
109
|
-
export declare const option: (raw: Raw) => Aabb | null;
|
|
110
|
-
/**
|
|
111
|
-
* Whether any value is a valid `Aabb`: a guard, also for building a
|
|
112
|
-
* `Aabb` field in your own schema (`Schema.declare(Aabb.is)`).
|
|
113
|
-
*
|
|
114
|
-
* @category Construction
|
|
115
|
-
*/
|
|
116
|
-
export declare const is: (raw: unknown) => raw is Aabb;
|
|
117
|
-
/**
|
|
118
|
-
* Reads the center position of one AABB.
|
|
119
|
-
*
|
|
120
|
-
* @category Accessors
|
|
121
|
-
*/
|
|
122
|
-
export declare const position: (aabb: Aabb) => Vector2.Vector2;
|
|
123
|
-
/**
|
|
124
|
-
* Reads the size of one AABB.
|
|
125
|
-
*
|
|
126
|
-
* @category Accessors
|
|
127
|
-
*/
|
|
128
|
-
export declare const size: (aabb: Aabb) => Size2.Size2;
|
|
129
|
-
/**
|
|
130
|
-
* Returns the left edge of one centered AABB.
|
|
131
|
-
*
|
|
132
|
-
* @category Accessors
|
|
133
|
-
*/
|
|
134
|
-
export declare const left: (aabb: Aabb) => Scalar.Finite;
|
|
135
|
-
/**
|
|
136
|
-
* Returns the right edge of one centered AABB.
|
|
137
|
-
*
|
|
138
|
-
* @category Accessors
|
|
139
|
-
*/
|
|
140
|
-
export declare const right: (aabb: Aabb) => Scalar.Finite;
|
|
141
|
-
/**
|
|
142
|
-
* Returns the top edge of one centered AABB.
|
|
143
|
-
*
|
|
144
|
-
* @category Accessors
|
|
145
|
-
*/
|
|
146
|
-
export declare const top: (aabb: Aabb) => Scalar.Finite;
|
|
147
|
-
/**
|
|
148
|
-
* Returns the bottom edge of one centered AABB.
|
|
149
|
-
*
|
|
150
|
-
* @category Accessors
|
|
151
|
-
*/
|
|
152
|
-
export declare const bottom: (aabb: Aabb) => Scalar.Finite;
|
|
153
|
-
/**
|
|
154
|
-
* Checks whether two AABBs overlap on both axes.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* const overlaps = Aabb.intersects(playerBox, wallBox)
|
|
159
|
-
* ```
|
|
160
|
-
*
|
|
161
|
-
* @category Operations
|
|
162
|
-
*/
|
|
163
|
-
export declare const intersects: (first: Aabb, second: Aabb) => boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Checks whether two AABBs overlap on the horizontal axis.
|
|
166
|
-
*
|
|
167
|
-
* @category Operations
|
|
168
|
-
*/
|
|
169
|
-
export declare const overlapsHorizontally: (first: Aabb, second: Aabb) => boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Checks whether two AABBs overlap on the vertical axis.
|
|
172
|
-
*
|
|
173
|
-
* @category Operations
|
|
174
|
-
*/
|
|
175
|
-
export declare const overlapsVertically: (first: Aabb, second: Aabb) => boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Returns a translated copy of one AABB.
|
|
178
|
-
*
|
|
179
|
-
* @category Operations
|
|
180
|
-
*/
|
|
181
|
-
export declare const translate: (aabb: Aabb, delta: Vector2.Vector2) => Aabb;
|
|
182
|
-
//# sourceMappingURL=Aabb.d.ts.map
|
package/dist/Aabb.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Aabb.d.ts","sourceRoot":"","sources":["../src/Aabb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,KAAK,KAAK,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,cA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,KAAK,IAAyB,CAAA"}
|
package/dist/Aabb.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as internal from "./internal/aabb.js";
|
|
2
|
-
/**
|
|
3
|
-
* Validates one raw AABB and returns an explicit result.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const playerBox = Aabb.result({
|
|
8
|
-
* position: { x: 24, y: 24 },
|
|
9
|
-
* size: { width: 16, height: 16 }
|
|
10
|
-
* })
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @category Construction
|
|
14
|
-
*/
|
|
15
|
-
export const result = internal.result;
|
|
16
|
-
/**
|
|
17
|
-
* The codec of `Aabb` (a Standard Schema, see `Descriptor.Codec`): give it to
|
|
18
|
-
* `Descriptor.ConstructedComponent(...)` so raw input and saves are validated.
|
|
19
|
-
* Its saved form is the raw shape, so it needs no `encode`. To put a `Aabb`
|
|
20
|
-
* inside your own object schema, use {@link is} with your library's guard
|
|
21
|
-
* schema (`Schema.declare`, `z.custom`).
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const Position = Descriptor.ConstructedComponent(Aabb.codec)("Game/Position")
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @category Construction
|
|
29
|
-
*/
|
|
30
|
-
export const codec = internal.codec;
|
|
31
|
-
/**
|
|
32
|
-
* Validates one raw AABB and returns `null` on failure.
|
|
33
|
-
*
|
|
34
|
-
* @category Construction
|
|
35
|
-
*/
|
|
36
|
-
export const option = internal.option;
|
|
37
|
-
/**
|
|
38
|
-
* Whether any value is a valid `Aabb`: a guard, also for building a
|
|
39
|
-
* `Aabb` field in your own schema (`Schema.declare(Aabb.is)`).
|
|
40
|
-
*
|
|
41
|
-
* @category Construction
|
|
42
|
-
*/
|
|
43
|
-
export const is = internal.is;
|
|
44
|
-
/**
|
|
45
|
-
* Reads the center position of one AABB.
|
|
46
|
-
*
|
|
47
|
-
* @category Accessors
|
|
48
|
-
*/
|
|
49
|
-
export const position = internal.position;
|
|
50
|
-
/**
|
|
51
|
-
* Reads the size of one AABB.
|
|
52
|
-
*
|
|
53
|
-
* @category Accessors
|
|
54
|
-
*/
|
|
55
|
-
export const size = internal.size;
|
|
56
|
-
/**
|
|
57
|
-
* Returns the left edge of one centered AABB.
|
|
58
|
-
*
|
|
59
|
-
* @category Accessors
|
|
60
|
-
*/
|
|
61
|
-
export const left = internal.left;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the right edge of one centered AABB.
|
|
64
|
-
*
|
|
65
|
-
* @category Accessors
|
|
66
|
-
*/
|
|
67
|
-
export const right = internal.right;
|
|
68
|
-
/**
|
|
69
|
-
* Returns the top edge of one centered AABB.
|
|
70
|
-
*
|
|
71
|
-
* @category Accessors
|
|
72
|
-
*/
|
|
73
|
-
export const top = internal.top;
|
|
74
|
-
/**
|
|
75
|
-
* Returns the bottom edge of one centered AABB.
|
|
76
|
-
*
|
|
77
|
-
* @category Accessors
|
|
78
|
-
*/
|
|
79
|
-
export const bottom = internal.bottom;
|
|
80
|
-
/**
|
|
81
|
-
* Checks whether two AABBs overlap on both axes.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const overlaps = Aabb.intersects(playerBox, wallBox)
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @category Operations
|
|
89
|
-
*/
|
|
90
|
-
export const intersects = internal.intersects;
|
|
91
|
-
/**
|
|
92
|
-
* Checks whether two AABBs overlap on the horizontal axis.
|
|
93
|
-
*
|
|
94
|
-
* @category Operations
|
|
95
|
-
*/
|
|
96
|
-
export const overlapsHorizontally = internal.overlapsHorizontally;
|
|
97
|
-
/**
|
|
98
|
-
* Checks whether two AABBs overlap on the vertical axis.
|
|
99
|
-
*
|
|
100
|
-
* @category Operations
|
|
101
|
-
*/
|
|
102
|
-
export const overlapsVertically = internal.overlapsVertically;
|
|
103
|
-
/**
|
|
104
|
-
* Returns a translated copy of one AABB.
|
|
105
|
-
*
|
|
106
|
-
* @category Operations
|
|
107
|
-
*/
|
|
108
|
-
export const translate = internal.translate;
|
|
109
|
-
//# sourceMappingURL=Aabb.js.map
|
package/dist/Aabb.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Aabb.js","sourceRoot":"","sources":["../src/Aabb.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAA;AAmC9C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,MAAM,GAA6C,QAAQ,CAAC,MAAM,CAAA;AAC/E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,KAAK,GAA8B,QAAQ,CAAC,KAAK,CAAA;AAC9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAA8B,QAAQ,CAAC,MAAM,CAAA;AAChE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,EAAE,GAAkC,QAAQ,CAAC,EAAE,CAAA;AAC5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAoC,QAAQ,CAAC,QAAQ,CAAA;AAC1E;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAgC,QAAQ,CAAC,IAAI,CAAA;AAC9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAkC,QAAQ,CAAC,IAAI,CAAA;AAChE;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAkC,QAAQ,CAAC,KAAK,CAAA;AAClE;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAkC,QAAQ,CAAC,GAAG,CAAA;AAC9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAkC,QAAQ,CAAC,MAAM,CAAA;AACpE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAA2C,QAAQ,CAAC,UAAU,CAAA;AACrF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA2C,QAAQ,CAAC,oBAAoB,CAAA;AACzG;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA2C,QAAQ,CAAC,kBAAkB,CAAA;AACrG;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAiD,QAAQ,CAAC,SAAS,CAAA"}
|
package/dist/InputAxis.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type * as Vector2 from "./Vector2.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Canonical one-dimensional movement axis.
|
|
4
|
-
*
|
|
5
|
-
* @category Input Types
|
|
6
|
-
*/
|
|
7
|
-
export type Axis = -1 | 0 | 1;
|
|
8
|
-
/**
|
|
9
|
-
* Derives one signed axis from two opposing booleans.
|
|
10
|
-
*
|
|
11
|
-
* @category Axis Helpers
|
|
12
|
-
*/
|
|
13
|
-
export declare const axis: (negativePressed: boolean, positivePressed: boolean) => Axis;
|
|
14
|
-
/**
|
|
15
|
-
* Builds a normalized movement vector from four directional booleans, in
|
|
16
|
-
* screen coordinates: `up` is negative `y`, `right` positive `x`. Opposite
|
|
17
|
-
* presses cancel, and diagonals have length 1.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const direction = InputAxis.vectorFromAxes({
|
|
22
|
-
* left: false,
|
|
23
|
-
* right: true,
|
|
24
|
-
* up: false,
|
|
25
|
-
* down: true
|
|
26
|
-
* })
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @category Vector Helpers
|
|
30
|
-
*/
|
|
31
|
-
export declare const vectorFromAxes: (input: {
|
|
32
|
-
readonly left: boolean;
|
|
33
|
-
readonly right: boolean;
|
|
34
|
-
readonly up: boolean;
|
|
35
|
-
readonly down: boolean;
|
|
36
|
-
}) => Vector2.Vector2;
|
|
37
|
-
/**
|
|
38
|
-
* Builds a normalized movement vector from two explicit axis values
|
|
39
|
-
* (diagonals have length 1).
|
|
40
|
-
*
|
|
41
|
-
* @category Vector Helpers
|
|
42
|
-
*/
|
|
43
|
-
export declare const vectorFromAxisValues: (horizontal: Axis, vertical: Axis) => Vector2.Vector2;
|
|
44
|
-
//# sourceMappingURL=InputAxis.d.ts.map
|
package/dist/InputAxis.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InputAxis.d.ts","sourceRoot":"","sources":["../src/InputAxis.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAA;AAE5C;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE7B;;;;GAIG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,KAAK,IAAoB,CAAA;AAC/F;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,EAAE,CAC3B,KAAK,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,KACrG,OAAO,CAAC,OAAiC,CAAA;AAC9C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,KAAK,OAAO,CAAC,OAAuC,CAAA"}
|
package/dist/InputAxis.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure helpers for normalizing boolean directional input into typed axes and
|
|
3
|
-
* movement vectors.
|
|
4
|
-
*
|
|
5
|
-
* This module is runtime-agnostic: it does not know about keyboard events,
|
|
6
|
-
* gamepads, or host APIs. It only translates already-sampled booleans into the
|
|
7
|
-
* compact movement values that systems consume.
|
|
8
|
-
*
|
|
9
|
-
* Reach for it in the gap between host input sampling and ECS simulation:
|
|
10
|
-
* capture raw button state in the host, normalize it here, then write the
|
|
11
|
-
* resulting axes or vectors into resources/components for systems to consume.
|
|
12
|
-
* With `@typeonce/ritmo-browser`, bind movement as a vector action instead
|
|
13
|
-
* (`Keyboard.vector`, `Gamepad.vector`), which already reports the merged
|
|
14
|
-
* vector; use this module for booleans from another source.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Normalize one sampled host input snapshot into a movement vector.
|
|
19
|
-
* const movement = InputAxis.vectorFromAxes({
|
|
20
|
-
* left: false,
|
|
21
|
-
* right: true,
|
|
22
|
-
* up: false,
|
|
23
|
-
* down: false
|
|
24
|
-
* })
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @module InputAxis
|
|
28
|
-
* @docGroup helpers
|
|
29
|
-
*
|
|
30
|
-
* @categoryDescription Input Types
|
|
31
|
-
* Small shared types that describe normalized axis values.
|
|
32
|
-
*
|
|
33
|
-
* @categoryDescription Axis Helpers
|
|
34
|
-
* Pure helpers that reduce opposing booleans to one explicit signed movement axis.
|
|
35
|
-
*
|
|
36
|
-
* @categoryDescription Vector Helpers
|
|
37
|
-
* Runtime-agnostic helpers that derive branded movement vectors from normalized input.
|
|
38
|
-
*/
|
|
39
|
-
import * as internal from "./internal/inputAxis.js";
|
|
40
|
-
/**
|
|
41
|
-
* Derives one signed axis from two opposing booleans.
|
|
42
|
-
*
|
|
43
|
-
* @category Axis Helpers
|
|
44
|
-
*/
|
|
45
|
-
export const axis = internal.axis;
|
|
46
|
-
/**
|
|
47
|
-
* Builds a normalized movement vector from four directional booleans, in
|
|
48
|
-
* screen coordinates: `up` is negative `y`, `right` positive `x`. Opposite
|
|
49
|
-
* presses cancel, and diagonals have length 1.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const direction = InputAxis.vectorFromAxes({
|
|
54
|
-
* left: false,
|
|
55
|
-
* right: true,
|
|
56
|
-
* up: false,
|
|
57
|
-
* down: true
|
|
58
|
-
* })
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @category Vector Helpers
|
|
62
|
-
*/
|
|
63
|
-
export const vectorFromAxes = internal.vectorFromAxes;
|
|
64
|
-
/**
|
|
65
|
-
* Builds a normalized movement vector from two explicit axis values
|
|
66
|
-
* (diagonals have length 1).
|
|
67
|
-
*
|
|
68
|
-
* @category Vector Helpers
|
|
69
|
-
*/
|
|
70
|
-
export const vectorFromAxisValues = internal.vectorFromAxisValues;
|
|
71
|
-
//# sourceMappingURL=InputAxis.js.map
|
package/dist/InputAxis.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InputAxis.js","sourceRoot":"","sources":["../src/InputAxis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AAUnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAiE,QAAQ,CAAC,IAAI,CAAA;AAC/F;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,cAAc,GAEJ,QAAQ,CAAC,cAAc,CAAA;AAC9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA0D,QAAQ,CAAC,oBAAoB,CAAA"}
|