@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.
Files changed (108) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +17 -12
  3. package/dist/Angle.d.ts +44 -0
  4. package/dist/Angle.d.ts.map +1 -0
  5. package/dist/Angle.js +62 -0
  6. package/dist/Angle.js.map +1 -0
  7. package/dist/Box2.d.ts +16 -4
  8. package/dist/Box2.d.ts.map +1 -1
  9. package/dist/Box2.js +16 -1
  10. package/dist/Box2.js.map +1 -1
  11. package/dist/Collide2.d.ts +11 -1
  12. package/dist/Collide2.d.ts.map +1 -1
  13. package/dist/Collide2.js +16 -1
  14. package/dist/Collide2.js.map +1 -1
  15. package/dist/FlowField.d.ts +24 -38
  16. package/dist/FlowField.d.ts.map +1 -1
  17. package/dist/FlowField.js +18 -5
  18. package/dist/FlowField.js.map +1 -1
  19. package/dist/Scalar.d.ts +19 -166
  20. package/dist/Scalar.d.ts.map +1 -1
  21. package/dist/Scalar.js +51 -51
  22. package/dist/Scalar.js.map +1 -1
  23. package/dist/Vec2.d.ts +47 -7
  24. package/dist/Vec2.d.ts.map +1 -1
  25. package/dist/Vec2.js +56 -8
  26. package/dist/Vec2.js.map +1 -1
  27. package/dist/index.d.ts +9 -22
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +9 -22
  30. package/dist/index.js.map +1 -1
  31. package/package.json +3 -3
  32. package/src/Angle.ts +60 -0
  33. package/src/Box2.ts +20 -4
  34. package/src/Collide2.ts +18 -2
  35. package/src/FlowField.ts +34 -10
  36. package/src/Scalar.ts +43 -165
  37. package/src/Vec2.ts +58 -8
  38. package/src/index.ts +9 -22
  39. package/dist/Aabb.d.ts +0 -182
  40. package/dist/Aabb.d.ts.map +0 -1
  41. package/dist/Aabb.js +0 -109
  42. package/dist/Aabb.js.map +0 -1
  43. package/dist/InputAxis.d.ts +0 -44
  44. package/dist/InputAxis.d.ts.map +0 -1
  45. package/dist/InputAxis.js +0 -71
  46. package/dist/InputAxis.js.map +0 -1
  47. package/dist/Ops.d.ts +0 -209
  48. package/dist/Ops.d.ts.map +0 -1
  49. package/dist/Ops.js +0 -210
  50. package/dist/Ops.js.map +0 -1
  51. package/dist/Random.d.ts +0 -124
  52. package/dist/Random.d.ts.map +0 -1
  53. package/dist/Random.js +0 -126
  54. package/dist/Random.js.map +0 -1
  55. package/dist/Size2.d.ts +0 -118
  56. package/dist/Size2.d.ts.map +0 -1
  57. package/dist/Size2.js +0 -54
  58. package/dist/Size2.js.map +0 -1
  59. package/dist/SpatialGrid.d.ts +0 -68
  60. package/dist/SpatialGrid.d.ts.map +0 -1
  61. package/dist/SpatialGrid.js +0 -112
  62. package/dist/SpatialGrid.js.map +0 -1
  63. package/dist/Vector2.d.ts +0 -214
  64. package/dist/Vector2.d.ts.map +0 -1
  65. package/dist/Vector2.js +0 -134
  66. package/dist/Vector2.js.map +0 -1
  67. package/dist/internal/aabb.d.ts +0 -27
  68. package/dist/internal/aabb.d.ts.map +0 -1
  69. package/dist/internal/aabb.js +0 -52
  70. package/dist/internal/aabb.js.map +0 -1
  71. package/dist/internal/codec.d.ts +0 -9
  72. package/dist/internal/codec.d.ts.map +0 -1
  73. package/dist/internal/codec.js +0 -16
  74. package/dist/internal/codec.js.map +0 -1
  75. package/dist/internal/fdlibm.d.ts +0 -43
  76. package/dist/internal/fdlibm.d.ts.map +0 -1
  77. package/dist/internal/fdlibm.js +0 -1291
  78. package/dist/internal/fdlibm.js.map +0 -1
  79. package/dist/internal/inputAxis.d.ts +0 -11
  80. package/dist/internal/inputAxis.d.ts.map +0 -1
  81. package/dist/internal/inputAxis.js +0 -13
  82. package/dist/internal/inputAxis.js.map +0 -1
  83. package/dist/internal/scalar.d.ts +0 -11
  84. package/dist/internal/scalar.d.ts.map +0 -1
  85. package/dist/internal/scalar.js +0 -68
  86. package/dist/internal/scalar.js.map +0 -1
  87. package/dist/internal/size2.d.ts +0 -22
  88. package/dist/internal/size2.d.ts.map +0 -1
  89. package/dist/internal/size2.js +0 -38
  90. package/dist/internal/size2.js.map +0 -1
  91. package/dist/internal/vector2.d.ts +0 -39
  92. package/dist/internal/vector2.d.ts.map +0 -1
  93. package/dist/internal/vector2.js +0 -78
  94. package/dist/internal/vector2.js.map +0 -1
  95. package/src/Aabb.ts +0 -180
  96. package/src/InputAxis.ts +0 -81
  97. package/src/Ops.ts +0 -232
  98. package/src/Random.ts +0 -225
  99. package/src/Size2.ts +0 -122
  100. package/src/SpatialGrid.ts +0 -172
  101. package/src/Vector2.ts +0 -216
  102. package/src/internal/aabb.ts +0 -81
  103. package/src/internal/codec.ts +0 -21
  104. package/src/internal/fdlibm.ts +0 -1256
  105. package/src/internal/inputAxis.ts +0 -21
  106. package/src/internal/scalar.ts +0 -104
  107. package/src/internal/size2.ts +0 -54
  108. package/src/internal/vector2.ts +0 -121
@@ -1 +0,0 @@
1
- {"version":3,"file":"Random.js","sourceRoot":"","sources":["../src/Random.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AA6B7C,MAAM,MAAM,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,QAAQ,CAAA;AAE3E,MAAM,UAAU;IACd,KAAK,CAAQ;IAEb,YAAY,KAAa;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,IAAI;QACF,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAC5C,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QAClB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,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MAAM,IAAI,GAAG,CAAC,KAAa,EAAS,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAU,CAAA;AAEpE,MAAM,UAAW,SAAQ,UAAU;IACxB,KAAK,CAAkB;IAEhC,YAAY,IAAsB;QAChC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;IACnB,CAAC;IAEQ,IAAI;QACX,+EAA+E;QAC/E,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;QAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAc,CAAC,CAAA;QACnC,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAsB,EAAU,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA"}
package/dist/Size2.d.ts DELETED
@@ -1,118 +0,0 @@
1
- /**
2
- * Branded two-dimensional sizes with explicit validation.
3
- *
4
- * Sizes model non-negative width/height pairs and are commonly used for
5
- * colliders, viewports, and AABB dimensions.
6
- *
7
- * Reach for this module when authored or host-provided dimensions should be
8
- * validated once and then carried through gameplay code, runtime bootstrap, or
9
- * geometry helpers without repeating non-negative checks everywhere.
10
- *
11
- * @example
12
- * ```ts
13
- * // Validate raw viewport dimensions before storing or reusing them.
14
- * const viewport = Size2.result({ width: 800, height: 600 })
15
- * if (!viewport.ok) return
16
- *
17
- * // Read the branded size later without rechecking width/height validity.
18
- * const width = Size2.width(viewport.value)
19
- * ```
20
- *
21
- * @module Size2
22
- * @docGroup data-structures
23
- *
24
- * @categoryDescription Size Types
25
- * Raw, branded, and error shapes for validated two-dimensional sizes.
26
- *
27
- * @categoryDescription Construction
28
- * Non-throwing constructor boundaries that validate raw width and height input.
29
- *
30
- * @categoryDescription Accessors
31
- * Pure readers and raw views over already-validated size values.
32
- */
33
- import type * as Brand from "@typeonce/ritmo/Brand";
34
- import type { StandardSchema } from "@typeonce/ritmo/Descriptor";
35
- import type * as Result from "@typeonce/ritmo/Result";
36
- import type * as Scalar from "./Scalar.ts";
37
- /**
38
- * Raw size input accepted by the public constructors.
39
- *
40
- * @category Size Types
41
- */
42
- export type Raw = {
43
- readonly width: number;
44
- readonly height: number;
45
- };
46
- /**
47
- * Validated non-negative width/height pair.
48
- *
49
- * @category Size Types
50
- */
51
- export type Size2 = Brand.Branded<{
52
- readonly width: Scalar.NonNegative;
53
- readonly height: Scalar.NonNegative;
54
- }, "Size2">;
55
- /**
56
- * Structured size-construction failure.
57
- *
58
- * @category Size Types
59
- */
60
- export type Error = {
61
- readonly tag: "Size2/Invalid";
62
- readonly width: Scalar.Error | null;
63
- readonly height: Scalar.Error | null;
64
- readonly input: Raw;
65
- };
66
- /**
67
- * Validates one raw size and returns an explicit result.
68
- *
69
- * @category Construction
70
- */
71
- export declare const result: (raw: Raw) => Result.Result<Size2, Error>;
72
- /**
73
- * The codec of `Size2` (a Standard Schema, see `Descriptor.Codec`): give it to
74
- * `Descriptor.ConstructedComponent(...)` so raw input and saves are validated.
75
- * Its saved form is the raw shape, so it needs no `encode`. To put a `Size2`
76
- * inside your own object schema, use {@link is} with your library's guard
77
- * schema (`Schema.declare`, `z.custom`).
78
- *
79
- * @example
80
- * ```ts
81
- * const Position = Descriptor.ConstructedComponent(Size2.codec)("Game/Position")
82
- * ```
83
- *
84
- * @category Construction
85
- */
86
- export declare const codec: StandardSchema<Raw, Size2>;
87
- /**
88
- * Validates one raw size and returns `null` on failure.
89
- *
90
- * @category Construction
91
- */
92
- export declare const option: (raw: Raw) => Size2 | null;
93
- /**
94
- * Whether any value is a valid `Size2`: a guard, also for building a
95
- * `Size2` field in your own schema (`Schema.declare(Size2.is)`).
96
- *
97
- * @category Construction
98
- */
99
- export declare const is: (raw: unknown) => raw is Size2;
100
- /**
101
- * Converts one branded size back to a fresh raw object.
102
- *
103
- * @category Accessors
104
- */
105
- export declare const toRaw: (size: Size2) => Raw;
106
- /**
107
- * Reads the width component of one branded size.
108
- *
109
- * @category Accessors
110
- */
111
- export declare const width: (size: Size2) => Scalar.NonNegative;
112
- /**
113
- * Reads the height component of one branded size.
114
- *
115
- * @category Accessors
116
- */
117
- export declare const height: (size: Size2) => Scalar.NonNegative;
118
- //# sourceMappingURL=Size2.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Size2.d.ts","sourceRoot":"","sources":["../src/Size2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,KAAK,KAAK,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAE1C;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG;IAChB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAA;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAA;CACpC,EAAE,OAAO,CAAC,CAAA;AAEX;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAmB,CAAA;AAChF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,EAAE,cAAc,CAAC,GAAG,EAAE,KAAK,CAAkB,CAAA;AAC/D;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,KAAK,GAAG,IAAsB,CAAA;AACjE;;;;;GAKG;AACH,eAAO,MAAM,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,GAAG,IAAI,KAAmB,CAAA;AAC7D;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,GAAoB,CAAA;AACzD;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC,WAA4B,CAAA;AACxE;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC,WAA6B,CAAA"}
package/dist/Size2.js DELETED
@@ -1,54 +0,0 @@
1
- import * as internal from "./internal/size2.js";
2
- /**
3
- * Validates one raw size and returns an explicit result.
4
- *
5
- * @category Construction
6
- */
7
- export const result = internal.result;
8
- /**
9
- * The codec of `Size2` (a Standard Schema, see `Descriptor.Codec`): give it to
10
- * `Descriptor.ConstructedComponent(...)` so raw input and saves are validated.
11
- * Its saved form is the raw shape, so it needs no `encode`. To put a `Size2`
12
- * inside your own object schema, use {@link is} with your library's guard
13
- * schema (`Schema.declare`, `z.custom`).
14
- *
15
- * @example
16
- * ```ts
17
- * const Position = Descriptor.ConstructedComponent(Size2.codec)("Game/Position")
18
- * ```
19
- *
20
- * @category Construction
21
- */
22
- export const codec = internal.codec;
23
- /**
24
- * Validates one raw size and returns `null` on failure.
25
- *
26
- * @category Construction
27
- */
28
- export const option = internal.option;
29
- /**
30
- * Whether any value is a valid `Size2`: a guard, also for building a
31
- * `Size2` field in your own schema (`Schema.declare(Size2.is)`).
32
- *
33
- * @category Construction
34
- */
35
- export const is = internal.is;
36
- /**
37
- * Converts one branded size back to a fresh raw object.
38
- *
39
- * @category Accessors
40
- */
41
- export const toRaw = internal.toRaw;
42
- /**
43
- * Reads the width component of one branded size.
44
- *
45
- * @category Accessors
46
- */
47
- export const width = internal.width;
48
- /**
49
- * Reads the height component of one branded size.
50
- *
51
- * @category Accessors
52
- */
53
- export const height = internal.height;
54
- //# sourceMappingURL=Size2.js.map
package/dist/Size2.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Size2.js","sourceRoot":"","sources":["../src/Size2.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAoC/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAA8C,QAAQ,CAAC,MAAM,CAAA;AAChF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,KAAK,GAA+B,QAAQ,CAAC,KAAK,CAAA;AAC/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAA+B,QAAQ,CAAC,MAAM,CAAA;AACjE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,EAAE,GAAmC,QAAQ,CAAC,EAAE,CAAA;AAC7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyB,QAAQ,CAAC,KAAK,CAAA;AACzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAwC,QAAQ,CAAC,KAAK,CAAA;AACxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAwC,QAAQ,CAAC,MAAM,CAAA"}
@@ -1,68 +0,0 @@
1
- /**
2
- * A uniform spatial hash for broad-phase queries over circles.
3
- *
4
- * Rebuilt every step: `clear`, then `insert` each circle under the caller's
5
- * own index (its position in an array the caller keeps). Queries visit each
6
- * candidate whose cells overlap the query box once; the caller runs the
7
- * exact test. Cell arrays are reused between rebuilds, so a steady state
8
- * allocates nothing per step.
9
- *
10
- * Cells are keyed by packing their coordinates into 16 bits per axis, so
11
- * cells from -32768 to 32767 on each axis are distinct. Coordinates beyond
12
- * that share keys with other cells: a query then visits extra candidates,
13
- * but never misses one.
14
- *
15
- * @example
16
- * ```ts
17
- * const grid = SpatialGrid.make(cellSize)
18
- * // Each step:
19
- * grid.clear()
20
- * bodies.forEach((body, index) => grid.insert(index, body.x, body.y, body.r))
21
- * grid.forEachIn(x - range, y - range, x + range, y + range, (index) => {
22
- * const other = bodies[index]!
23
- * // exact test against `other`
24
- * })
25
- * ```
26
- *
27
- * @module SpatialGrid
28
- * @docGroup helpers
29
- *
30
- * @categoryDescription Grid Types
31
- * The grid interface.
32
- *
33
- * @categoryDescription Construction
34
- * Making a grid.
35
- */
36
- import type * as Scalar from "./Scalar.ts";
37
- /**
38
- * A spatial hash over circles.
39
- *
40
- * @category Grid Types
41
- */
42
- export interface SpatialGrid {
43
- /** The side of one square cell, in world units. */
44
- readonly cellSize: Scalar.Positive;
45
- /** Removes every circle, keeping the storage for the next rebuild. */
46
- clear(): void;
47
- /**
48
- * Adds circle `index` (a non-negative integer) covering `[x ± r] × [y ± r]`.
49
- * A non-finite coordinate or radius throws: it would cover no cell or all of them.
50
- */
51
- insert(index: number, x: number, y: number, r: number): void;
52
- /**
53
- * Calls `visit` once for every circle whose cells overlap the box, in no
54
- * particular order. `visit` must not insert into or query this grid. A
55
- * non-finite bound throws (an unbounded box would never finish); a box
56
- * covering more cells than are occupied scans the occupied cells instead.
57
- */
58
- forEachIn(minX: number, minY: number, maxX: number, maxY: number, visit: (index: number) => void): void;
59
- }
60
- /**
61
- * An empty grid with square cells of `cellSize` world units. Pick a size near
62
- * the typical query box: much smaller cells make every insert and query
63
- * touch many cells, much larger ones return many far candidates.
64
- *
65
- * @category Construction
66
- */
67
- export declare const make: (cellSize: Scalar.Positive) => SpatialGrid;
68
- //# sourceMappingURL=SpatialGrid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpatialGrid.d.ts","sourceRoot":"","sources":["../src/SpatialGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAE1C;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAA;IAClC,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAA;IACb;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5D;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAA;CACxG;AAyGD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,aAAc,MAAM,CAAC,QAAQ,KAAG,WAAiC,CAAA"}
@@ -1,112 +0,0 @@
1
- const key = (cx, cy) => ((cx + 32768) << 16) | ((cy + 32768) & 0xffff);
2
- // Keys repeat every 65,536 cells, so a longer span visits nothing new.
3
- const AXIS_CELLS = 65_536;
4
- const lastCell = (first, last) => Math.min(last, first + AXIS_CELLS - 1);
5
- /** Whether a cell coordinate packed in a key falls in `[first, last]`, counting the keys' wrap-around. */
6
- const coveredBy = (coordinate, first, last) => (((coordinate - first) % AXIS_CELLS) + AXIS_CELLS) % AXIS_CELLS <= last - first;
7
- const notFinite = (operation, ...values) => {
8
- const value = values.find((value) => !Number.isFinite(value));
9
- throw new Error(`SpatialGrid.${operation} needs finite numbers, got ${value}`);
10
- };
11
- class Grid {
12
- cellSize;
13
- cells = new Map();
14
- used = [];
15
- // `stamp[index] === query` marks a circle already visited by this query.
16
- stamp = new Int32Array(64);
17
- query = 0;
18
- constructor(cellSize) {
19
- this.cellSize = cellSize;
20
- }
21
- clear() {
22
- for (const cell of this.used)
23
- cell.length = 0;
24
- this.used.length = 0;
25
- }
26
- insert(index, x, y, r) {
27
- // `x - x === 0` is false only for NaN and ±Infinity, without a call per number.
28
- if (x - x !== 0 || y - y !== 0 || r - r !== 0)
29
- notFinite("insert", x, y, r);
30
- const size = this.cellSize;
31
- const minX = Math.floor((x - r) / size);
32
- const maxX = lastCell(minX, Math.floor((x + r) / size));
33
- const minY = Math.floor((y - r) / size);
34
- const maxY = lastCell(minY, Math.floor((y + r) / size));
35
- for (let cx = minX; cx <= maxX; cx++) {
36
- for (let cy = minY; cy <= maxY; cy++) {
37
- const cellKey = key(cx, cy);
38
- let cell = this.cells.get(cellKey);
39
- if (cell === undefined) {
40
- cell = [];
41
- this.cells.set(cellKey, cell);
42
- }
43
- if (cell.length === 0)
44
- this.used.push(cell);
45
- cell.push(index);
46
- }
47
- }
48
- if (index >= this.stamp.length) {
49
- const grown = new Int32Array(Math.max(index + 1, this.stamp.length * 2));
50
- grown.set(this.stamp);
51
- this.stamp = grown;
52
- }
53
- }
54
- forEachIn(minX, minY, maxX, maxY, visit) {
55
- if (minX - minX !== 0 || minY - minY !== 0 || maxX - maxX !== 0 || maxY - maxY !== 0)
56
- notFinite("forEachIn", minX, minY, maxX, maxY);
57
- const size = this.cellSize;
58
- // Start the marks over before the counter leaves the stamps' range (after
59
- // about two billion queries), so old marks never match a new query.
60
- if (this.query === 0x7fffffff) {
61
- this.stamp.fill(0);
62
- this.query = 0;
63
- }
64
- this.query += 1;
65
- const query = this.query;
66
- const stamp = this.stamp;
67
- const x0 = Math.floor(minX / size);
68
- const x1 = lastCell(x0, Math.floor(maxX / size));
69
- const y0 = Math.floor(minY / size);
70
- const y1 = lastCell(y0, Math.floor(maxY / size));
71
- if ((x1 - x0 + 1) * (y1 - y0 + 1) > this.cells.size) {
72
- // A box larger than the occupied area: scan the cells that exist.
73
- for (const [cellKey, cell] of this.cells) {
74
- if (cell.length === 0)
75
- continue;
76
- if (!coveredBy(((cellKey >> 16) & 0xffff) - 32768, x0, x1) || !coveredBy((cellKey & 0xffff) - 32768, y0, y1))
77
- continue;
78
- for (let offset = 0; offset < cell.length; offset++) {
79
- const index = cell[offset];
80
- if (stamp[index] === query)
81
- continue;
82
- stamp[index] = query;
83
- visit(index);
84
- }
85
- }
86
- return;
87
- }
88
- for (let cx = x0; cx <= x1; cx++) {
89
- for (let cy = y0; cy <= y1; cy++) {
90
- const cell = this.cells.get(key(cx, cy));
91
- if (cell === undefined)
92
- continue;
93
- for (let offset = 0; offset < cell.length; offset++) {
94
- const index = cell[offset];
95
- if (stamp[index] === query)
96
- continue;
97
- stamp[index] = query;
98
- visit(index);
99
- }
100
- }
101
- }
102
- }
103
- }
104
- /**
105
- * An empty grid with square cells of `cellSize` world units. Pick a size near
106
- * the typical query box: much smaller cells make every insert and query
107
- * touch many cells, much larger ones return many far candidates.
108
- *
109
- * @category Construction
110
- */
111
- export const make = (cellSize) => new Grid(cellSize);
112
- //# sourceMappingURL=SpatialGrid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpatialGrid.js","sourceRoot":"","sources":["../src/SpatialGrid.ts"],"names":[],"mappings":"AA6DA,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,EAAU,EAAU,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,CAAA;AAE9F,uEAAuE;AACvE,MAAM,UAAU,GAAG,MAAM,CAAA;AACzB,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,IAAY,EAAU,EAAE,CAAC,IAA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EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;gBACjC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;gBACxC,IAAI,IAAI,KAAK,SAAS;oBAAE,SAAQ;gBAChC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;oBACpD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAE,CAAA;oBAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK;wBAAE,SAAQ;oBACpC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;oBACpB,KAAK,CAAC,KAAK,CAAC,CAAA;gBACd,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,QAAyB,EAAe,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAA"}
package/dist/Vector2.d.ts DELETED
@@ -1,214 +0,0 @@
1
- /**
2
- * Branded two-dimensional vectors with explicit validation.
3
- *
4
- * Raw `{ x, y }` input is validated once at the constructor boundary. All
5
- * other helpers work on branded vectors only and remain pure and immutable.
6
- *
7
- * This is the common math value that game code threads through position,
8
- * velocity, input direction, camera motion, and collision helpers. Use it when
9
- * vectors should stay explicitly validated and reusable across ECS and helper
10
- * modules. For per-frame arithmetic on numbers already known to be sane, use
11
- * `Vec2` (a `Vector2` is a `Vec2`, so it passes without conversion).
12
- *
13
- * @example
14
- * ```ts
15
- * // Validate one raw velocity before storing or reusing it elsewhere.
16
- * const velocity = Vector2.result({ x: 3, y: 4 })
17
- * if (!velocity.ok) return
18
- *
19
- * // Derive a movement direction from the branded vector.
20
- * const direction = Vector2.normalizeOrZero(velocity.value)
21
- * ```
22
- *
23
- * @module Vector2
24
- * @docGroup data-structures
25
- *
26
- * @categoryDescription Vector Types
27
- * Raw, branded, and error shapes used to describe validated two-dimensional vectors.
28
- *
29
- * @categoryDescription Construction
30
- * Non-throwing constructor boundaries that validate raw input and produce branded vectors.
31
- *
32
- * @categoryDescription Accessors
33
- * Pure readers and views that expose branded vector components without mutation.
34
- *
35
- * @categoryDescription Operations
36
- * Immutable vector math and normalization helpers on already-validated values.
37
- */
38
- import type * as Brand from "@typeonce/ritmo/Brand";
39
- import type { StandardSchema } from "@typeonce/ritmo/Descriptor";
40
- import type * as Result from "@typeonce/ritmo/Result";
41
- import type * as Scalar from "./Scalar.ts";
42
- /**
43
- * Raw vector input accepted by the public constructors.
44
- *
45
- * @category Vector Types
46
- */
47
- export type Raw = {
48
- readonly x: number;
49
- readonly y: number;
50
- };
51
- /**
52
- * Validated two-dimensional vector.
53
- *
54
- * @category Vector Types
55
- */
56
- export type Vector2 = Brand.Branded<{
57
- readonly x: Scalar.Finite;
58
- readonly y: Scalar.Finite;
59
- }, "Vector2">;
60
- /**
61
- * Structured vector-construction failure.
62
- *
63
- * @category Vector Types
64
- */
65
- export type Error = {
66
- readonly tag: "Vector2/Invalid";
67
- readonly x: Scalar.Error | null;
68
- readonly y: Scalar.Error | null;
69
- readonly input: Raw;
70
- };
71
- /**
72
- * Explicit failure produced when a zero-length vector cannot be normalized.
73
- *
74
- * @category Vector Types
75
- */
76
- export type NormalizeError = {
77
- readonly tag: "Vector2/ZeroLength";
78
- };
79
- /**
80
- * Validates one raw vector and returns an explicit result.
81
- *
82
- * @example
83
- * ```ts
84
- * const position = Vector2.result({ x: 16, y: 24 })
85
- * ```
86
- *
87
- * @category Construction
88
- */
89
- export declare const result: (raw: Raw) => Result.Result<Vector2, Error>;
90
- /**
91
- * The codec of `Vector2` (a Standard Schema, see `Descriptor.Codec`): give it to
92
- * `Descriptor.ConstructedComponent(...)` so raw input and saves are validated.
93
- * Its saved form is the raw shape, so it needs no `encode`. To put a `Vector2`
94
- * inside your own object schema, use {@link is} with your library's guard
95
- * schema (`Schema.declare`, `z.custom`).
96
- *
97
- * @example
98
- * ```ts
99
- * const Position = Descriptor.ConstructedComponent(Vector2.codec)("Game/Position")
100
- * ```
101
- *
102
- * @category Construction
103
- */
104
- export declare const codec: StandardSchema<Raw, Vector2>;
105
- /**
106
- * Validates one raw vector and returns `null` on failure.
107
- *
108
- * @category Construction
109
- */
110
- export declare const option: (raw: Raw) => Vector2 | null;
111
- /**
112
- * Whether any value is a valid `Vector2`: a guard, also for building a
113
- * `Vector2` field in your own schema (`Schema.declare(Vector2.is)`).
114
- *
115
- * @category Construction
116
- */
117
- export declare const is: (raw: unknown) => raw is Vector2;
118
- /**
119
- * Converts one branded vector back to a fresh raw object.
120
- *
121
- * @category Accessors
122
- */
123
- export declare const toRaw: (vector: Vector2) => Raw;
124
- /**
125
- * Exposes the branded components of one vector.
126
- *
127
- * @category Accessors
128
- */
129
- export declare const components: (vector: Vector2) => {
130
- readonly x: Scalar.Finite;
131
- readonly y: Scalar.Finite;
132
- };
133
- /**
134
- * Reads the `x` component of one branded vector.
135
- *
136
- * @category Accessors
137
- */
138
- export declare const x: (vector: Vector2) => Scalar.Finite;
139
- /**
140
- * Reads the `y` component of one branded vector.
141
- *
142
- * @category Accessors
143
- */
144
- export declare const y: (vector: Vector2) => Scalar.Finite;
145
- /**
146
- * Returns the canonical zero vector.
147
- *
148
- * @category Construction
149
- */
150
- export declare const zero: () => Vector2;
151
- /**
152
- * Returns the sum of two branded vectors.
153
- *
154
- * Keeps the brands without re-validating: finite while the result stays
155
- * within `±Number.MAX_VALUE` (see `Scalar.Finite`).
156
- *
157
- * @category Operations
158
- */
159
- export declare const add: (left: Vector2, right: Vector2) => Vector2;
160
- /**
161
- * Returns the component-wise difference between two branded vectors.
162
- *
163
- * Keeps the brands without re-validating: finite while the result stays
164
- * within `±Number.MAX_VALUE` (see `Scalar.Finite`).
165
- *
166
- * @category Operations
167
- */
168
- export declare const subtract: (left: Vector2, right: Vector2) => Vector2;
169
- /**
170
- * Scales one vector by one validated finite scalar.
171
- *
172
- * Keeps the brands without re-validating: finite while the result stays
173
- * within `±Number.MAX_VALUE` (see `Scalar.Finite`).
174
- *
175
- * @category Operations
176
- */
177
- export declare const scale: (vector: Vector2, scalar: Scalar.Finite) => Vector2;
178
- /**
179
- * Returns the squared length of one vector.
180
- *
181
- * Keeps the brands without re-validating: finite while the result stays
182
- * within `±Number.MAX_VALUE` (see `Scalar.Finite`).
183
- *
184
- * @category Operations
185
- */
186
- export declare const lengthSquared: (vector: Vector2) => Scalar.NonNegative;
187
- /**
188
- * Returns the length of one vector.
189
- *
190
- * @category Operations
191
- */
192
- export declare const length: (vector: Vector2) => Scalar.NonNegative;
193
- /**
194
- * Returns the normalized vector when its length is non-zero.
195
- *
196
- * @example
197
- * ```ts
198
- * const direction = Vector2.normalize(Vector2.zero())
199
- * if (!direction.ok) {
200
- * return
201
- * }
202
- * ```
203
- *
204
- * @category Operations
205
- */
206
- export declare const normalize: (vector: Vector2) => Result.Result<Vector2, NormalizeError>;
207
- /**
208
- * Returns the normalized vector or the canonical zero vector when the input
209
- * length is zero.
210
- *
211
- * @category Operations
212
- */
213
- export declare const normalizeOrZero: (vector: Vector2) => Vector2;
214
- //# sourceMappingURL=Vector2.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../src/Vector2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,KAAK,KAAK,KAAK,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAE1C;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG;IAChB,QAAQ,CAAC,CAAC,EAAE,MAAM,C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