@typeonce/ritmo-math 0.13.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 (113) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/README.md +18 -13
  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 +59 -15
  12. package/dist/Collide2.d.ts.map +1 -1
  13. package/dist/Collide2.js +156 -18
  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/Segment2.d.ts +56 -0
  24. package/dist/Segment2.d.ts.map +1 -0
  25. package/dist/Segment2.js +32 -0
  26. package/dist/Segment2.js.map +1 -0
  27. package/dist/Vec2.d.ts +47 -7
  28. package/dist/Vec2.d.ts.map +1 -1
  29. package/dist/Vec2.js +56 -8
  30. package/dist/Vec2.js.map +1 -1
  31. package/dist/index.d.ts +10 -21
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +10 -21
  34. package/dist/index.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/Angle.ts +60 -0
  37. package/src/Box2.ts +20 -4
  38. package/src/Collide2.ts +171 -24
  39. package/src/FlowField.ts +34 -10
  40. package/src/Scalar.ts +43 -165
  41. package/src/Segment2.ts +71 -0
  42. package/src/Vec2.ts +58 -8
  43. package/src/index.ts +10 -21
  44. package/dist/Aabb.d.ts +0 -182
  45. package/dist/Aabb.d.ts.map +0 -1
  46. package/dist/Aabb.js +0 -109
  47. package/dist/Aabb.js.map +0 -1
  48. package/dist/InputAxis.d.ts +0 -44
  49. package/dist/InputAxis.d.ts.map +0 -1
  50. package/dist/InputAxis.js +0 -71
  51. package/dist/InputAxis.js.map +0 -1
  52. package/dist/Ops.d.ts +0 -209
  53. package/dist/Ops.d.ts.map +0 -1
  54. package/dist/Ops.js +0 -210
  55. package/dist/Ops.js.map +0 -1
  56. package/dist/Random.d.ts +0 -124
  57. package/dist/Random.d.ts.map +0 -1
  58. package/dist/Random.js +0 -126
  59. package/dist/Random.js.map +0 -1
  60. package/dist/Size2.d.ts +0 -118
  61. package/dist/Size2.d.ts.map +0 -1
  62. package/dist/Size2.js +0 -54
  63. package/dist/Size2.js.map +0 -1
  64. package/dist/SpatialGrid.d.ts +0 -68
  65. package/dist/SpatialGrid.d.ts.map +0 -1
  66. package/dist/SpatialGrid.js +0 -112
  67. package/dist/SpatialGrid.js.map +0 -1
  68. package/dist/Vector2.d.ts +0 -214
  69. package/dist/Vector2.d.ts.map +0 -1
  70. package/dist/Vector2.js +0 -134
  71. package/dist/Vector2.js.map +0 -1
  72. package/dist/internal/aabb.d.ts +0 -27
  73. package/dist/internal/aabb.d.ts.map +0 -1
  74. package/dist/internal/aabb.js +0 -52
  75. package/dist/internal/aabb.js.map +0 -1
  76. package/dist/internal/codec.d.ts +0 -9
  77. package/dist/internal/codec.d.ts.map +0 -1
  78. package/dist/internal/codec.js +0 -16
  79. package/dist/internal/codec.js.map +0 -1
  80. package/dist/internal/fdlibm.d.ts +0 -43
  81. package/dist/internal/fdlibm.d.ts.map +0 -1
  82. package/dist/internal/fdlibm.js +0 -1291
  83. package/dist/internal/fdlibm.js.map +0 -1
  84. package/dist/internal/inputAxis.d.ts +0 -11
  85. package/dist/internal/inputAxis.d.ts.map +0 -1
  86. package/dist/internal/inputAxis.js +0 -13
  87. package/dist/internal/inputAxis.js.map +0 -1
  88. package/dist/internal/scalar.d.ts +0 -11
  89. package/dist/internal/scalar.d.ts.map +0 -1
  90. package/dist/internal/scalar.js +0 -68
  91. package/dist/internal/scalar.js.map +0 -1
  92. package/dist/internal/size2.d.ts +0 -22
  93. package/dist/internal/size2.d.ts.map +0 -1
  94. package/dist/internal/size2.js +0 -38
  95. package/dist/internal/size2.js.map +0 -1
  96. package/dist/internal/vector2.d.ts +0 -39
  97. package/dist/internal/vector2.d.ts.map +0 -1
  98. package/dist/internal/vector2.js +0 -78
  99. package/dist/internal/vector2.js.map +0 -1
  100. package/src/Aabb.ts +0 -180
  101. package/src/InputAxis.ts +0 -81
  102. package/src/Ops.ts +0 -232
  103. package/src/Random.ts +0 -225
  104. package/src/Size2.ts +0 -122
  105. package/src/SpatialGrid.ts +0 -172
  106. package/src/Vector2.ts +0 -216
  107. package/src/internal/aabb.ts +0 -81
  108. package/src/internal/codec.ts +0 -21
  109. package/src/internal/fdlibm.ts +0 -1256
  110. package/src/internal/inputAxis.ts +0 -21
  111. package/src/internal/scalar.ts +0 -104
  112. package/src/internal/size2.ts +0 -54
  113. package/src/internal/vector2.ts +0 -121
package/CHANGELOG.md CHANGED
@@ -1,5 +1,154 @@
1
1
  # @typeonce/ritmo-math
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c75daff: **Breaking: `Ops` and `Random` moved from `@typeonce/ritmo-math` into `@typeonce/ritmo`.** Determinism belongs to the runtime: every simulation needs same-bits math and a seeded generator, with or without the 2D helpers. The modules are unchanged; only the import path moves, and `@typeonce/ritmo-math` no longer exports them. The `Ops` header now states that its list is closed: the 22 functions engines may approximate and `**`; everything else on `Math` is already exact. `@typeonce/ritmo-devtools` and `@typeonce/ritmo-netcode` no longer depend on `@typeonce/ritmo-math`.
8
+
9
+ ```diff
10
+ - import { Ops, Random } from "@typeonce/ritmo-math"
11
+ + import { Ops, Random } from "@typeonce/ritmo"
12
+ - import * as Random from "@typeonce/ritmo-math/Random"
13
+ + import * as Random from "@typeonce/ritmo/Random"
14
+ - import * as Ops from "@typeonce/ritmo-math/Ops"
15
+ + import * as Ops from "@typeonce/ritmo/Ops"
16
+ ```
17
+
18
+ `oxlint --fix` with `ritmo/use-ops-for-math` adds the new import where a `Math` call is rewritten; other imports need the path changed by hand.
19
+
20
+ - c75daff: **Breaking: `@typeonce/ritmo-math` holds plain-data 2D helpers only.** It holds the 2D helpers most games would otherwise rewrite, as plain data in and out, built on `Ops` so they replay the same on every engine. Validated value types are the game's schema's job, so these are removed:
21
+
22
+ - **`Vector2`, `Size2`, `Aabb`, and `InputAxis`.** Declare the shape with the game's schema library and use `Vec2` / `Box2` for the arithmetic:
23
+ ```diff
24
+ - const Position = Descriptor.ConstructedComponent(Vector2.codec)("Game/Position")
25
+ + const Position = Descriptor.ConstructedComponent(z.object({ x: z.number(), y: z.number() }))("Game/Position")
26
+ - Vector2.add(a, b), Vector2.normalizeOrZero(v), Vector2.length(v)
27
+ + Vec2.add(a, b), Vec2.normalizeOr(v, Vec2.zero), Vec2.length(v)
28
+ - Aabb.intersects(first, second)
29
+ + Math.abs(a.x - b.x) * 2 < a.width + b.width && Math.abs(a.y - b.y) * 2 < a.height + b.height // or Box2 edges
30
+ - InputAxis.vectorFromAxes(keys)
31
+ + Keyboard.vector({ up, down, left, right }) from @typeonce/ritmo-browser, read as input.vectors.<name>
32
+ ```
33
+ To keep a branded value, brand it with the schema (`z.object({ ... }).brand<"Position">()`); the skill's "Branded values" section has each library's form.
34
+ - **`Scalar`'s brands (`Finite`, `NonNegative`, `Positive`, their constructors and codecs, `Error`, `InterpolationError`, `FiniteResult`), and `Scalar.clamp`, `inverseLerp`, `remap`.** `Scalar` is now three functions on plain numbers. `approach` is renamed:
35
+ ```diff
36
+ - Scalar.approach(speed, target, step)
37
+ + Scalar.moveToward(speed, target, step)
38
+ - Scalar.clamp(value, min, max)
39
+ + Math.min(Math.max(value, min), max)
40
+ - Scalar.remap(value, a, b, c, d) // Result
41
+ + Scalar.lerp(c, d, (value - a) / (b - a)) // check b !== a where it can be equal
42
+ ```
43
+ `Scalar.lerp` takes and returns plain numbers.
44
+ - **`SpatialGrid`.** A broad phase is game code now: copy the module from the skill's `playbooks/spatial-grid.md` (same `clear` / `insert` / `forEachIn` shape, `make(cellSize: number)` returns a `Result`).
45
+
46
+ **Breaking: `FlowField.make(cellSize: number)` returns `Result<FlowField, InvalidCellSize>`** instead of taking a `Scalar.Positive`. A size that is not a finite number above 0 is the typed failure `{ _tag: "InvalidCellSize", value }`.
47
+
48
+ ```diff
49
+ - const paths = FlowField.make(Scalar.Positive.option(30)!)
50
+ + const made = FlowField.make(30)
51
+ + if (!made.ok) return made
52
+ + const paths = made.value
53
+ ```
54
+
55
+ **New helpers games kept rewriting**, each total over finite numbers:
56
+
57
+ - `Angle.wrap(angle)` into [-π, π) (both ±π give -π), exact; `Angle.turnToward(angle, target, maxStep)` the short way, never overshooting. The difference of two headings is `Angle.wrap(to - from)`.
58
+ - `Vec2.perpendicular(a)` (`{ x: -a.y, y: a.x }`; the 2D cross product is `dot(perpendicular(a), b)`), `Vec2.fromAngle(angle)` (a unit vector through `Ops.cos`/`sin`), `Vec2.angle(a)` (through `Ops.atan2`: 0 for the zero vector, never `-0`), and `Vec2.decayToward(current, target, rate, dt)`.
59
+ - `Scalar.moveToward(current, target, maxDelta)`, `Scalar.lerp(start, end, amount)` (unclamped), `Scalar.decayToward(current, target, rate, dt)` (`target + (current - target) * Ops.exp(-rate * dt)`, the same at any step rate).
60
+ - `Box2.closestPoint(box, point)` (a point inside comes back unchanged) and `Collide2.overlapsCircleCircle(center, radius, other, otherRadius)` (touching counts).
61
+
62
+ ### Patch Changes
63
+
64
+ - d01a735: **Zod schemas work with Ritmo: the schema back to the saved form is under `"~encode"`, not `encode`.** Zod (from 4.1) gives every schema an `encode()` method, which Ritmo read as its encode schema: `Descriptor.ConstructedComponent(z.object(...))` did not compile, and with a cast `runtime.snapshot()` threw `Cannot read properties of undefined (reading 'validate')`. The key now starts with `~`, like Standard Schema's own `~standard`, so no library's methods collide with it. A Zod, Valibot, or ArkType schema of plain data passes as it is; Ritmo's tests now save and load a schema of each, and of Effect, through JSON.
65
+
66
+ - **Breaking: a codec carries its encode schema as `"~encode"`.** The Effect helper from the skill's `playbooks/effect.md` (or a hand-written codec) renames the key:
67
+
68
+ ```diff
69
+ return {
70
+ "~standard": Schema.toStandardSchemaV1(json)["~standard"],
71
+ - encode: Schema.toStandardSchemaV1(Schema.flip(json))
72
+ + "~encode": Schema.toStandardSchemaV1(Schema.flip(json))
73
+ }
74
+ ```
75
+
76
+ A transforming schema without it fails with `give it a ~encode schema back to the saved form`.
77
+
78
+ - **Values that transform** (a `Date`, a `Map`) save through a `"~encode"` from any library. Zod's comes from the new `playbooks/zod.md` helper, built on Zod's own `safeEncode`: `Descriptor.ConstructedComponent(codec(z.codec(z.iso.datetime(), z.date(), { decode, encode })))`. With Valibot, ArkType, or any other Standard Schema library, write the reverse schema by hand:
79
+
80
+ ```ts
81
+ const Born = Descriptor.ConstructedComponent({
82
+ "~standard": v.pipe(
83
+ v.string(),
84
+ v.isoTimestamp(),
85
+ v.transform((text) => new Date(text))
86
+ )["~standard"],
87
+ "~encode": v.pipe(
88
+ v.date(),
89
+ v.transform((date) => date.toISOString())
90
+ ),
91
+ })("Game/Born");
92
+ ```
93
+
94
+ - **Handles and deadlines inside a game's schema** are built from their guards with a schema that narrows to the guard's type: `z.unknown().refine(Entity.isHandle(Root))` in Zod, `v.pipe(v.unknown(), v.guard(...))` in Valibot, `type("unknown").narrow(...)` in ArkType, `Schema.declare(...)` in Effect. The docs said `z.custom(guard)`, which types the value as `unknown`.
95
+
96
+ - Updated dependencies [3a195b7]
97
+ - Updated dependencies [d01a735]
98
+ - Updated dependencies [45458dc]
99
+ - Updated dependencies [c75daff]
100
+ - Updated dependencies [b77b17d]
101
+ - Updated dependencies [c20f20b]
102
+ - Updated dependencies [01959dd]
103
+ - Updated dependencies [637fa1f]
104
+ - Updated dependencies [44e9b42]
105
+ - @typeonce/ritmo@0.15.0
106
+
107
+ ## 0.14.0
108
+
109
+ ### Minor Changes
110
+
111
+ - e169263: **`Collide2` collides circles with line segments, so walls can run at any angle.** The new `Segment2` module is the plain segment `Collide2` reads every frame (`Segment2.between(a, b)`, `closestPoint`, `overlapsCircle`), like `Box2` for boxes. A segment is a two-sided wall with round ends; both ends at one point make a round post. `Collide2.sweepCircleSegment` finds the first contact with one, next to `sweepCircleBox`. A map traced from survey data, a slanted fence, or a polygon's edges no longer need a hand-written port of `moveCircle`.
112
+
113
+ ```ts
114
+ const fence = Segment2.between({ x: 0, y: 0 }, { x: 40, y: 30 });
115
+ const moved = Collide2.moveCircle(position, delta, radius, {
116
+ boxes: rooms,
117
+ segments: [fence],
118
+ });
119
+ ```
120
+
121
+ - **Breaking: `moveCircle` and `pushOut` take the walls by kind, as `Collide2.Walls`** (`{ boxes?, segments? }`), instead of an array of boxes. An array no longer compiles (`pass walls by kind: { boxes: walls } or { segments: walls }`):
122
+
123
+ ```diff
124
+ -Collide2.moveCircle(position, delta, radius, walls)
125
+ +Collide2.moveCircle(position, delta, radius, { boxes: walls })
126
+ -Collide2.pushOut(position, radius, walls)
127
+ +Collide2.pushOut(position, radius, { boxes: walls })
128
+ ```
129
+
130
+ - **Breaking: `sweepCircleBoxes` is `sweepCircle`**, the first contact with any of the walls (line of sight with a radius of 0, as before):
131
+
132
+ ```diff
133
+ -Collide2.sweepCircleBoxes(eye, Vec2.subtract(target, eye), 0, walls) === undefined
134
+ +Collide2.sweepCircle(eye, Vec2.subtract(target, eye), 0, { boxes: walls }) === undefined
135
+ ```
136
+
137
+ Results against boxes are unchanged.
138
+
139
+ ### Patch Changes
140
+
141
+ - Updated dependencies [c3719a5]
142
+ - Updated dependencies [70d054e]
143
+ - Updated dependencies [adb4066]
144
+ - Updated dependencies [97e95fb]
145
+ - Updated dependencies [dbfbd9d]
146
+ - Updated dependencies [343660e]
147
+ - Updated dependencies [d24258e]
148
+ - Updated dependencies [cfe332a]
149
+ - Updated dependencies [8aa1e85]
150
+ - @typeonce/ritmo@0.14.0
151
+
3
152
  ## 0.13.0
4
153
 
5
154
  ### Minor Changes
package/README.md CHANGED
@@ -1,35 +1,40 @@
1
1
  # `@typeonce/ritmo-math`
2
2
 
3
- Math for ritmo games, in two kinds:
3
+ ritmo-math holds the 2D helpers most games would otherwise rewrite, as plain data in and plain data out, built on Ops so they replay the same on every engine; it never ports a third-party algorithm, and determinism alone is never a reason to add one.
4
4
 
5
- - **Validated values**: `Scalar` (`Finite`, `NonNegative`, `Positive`), `Vector2`, `Size2`, and `Aabb`. Each has constructors that validate input (`result`, `option`), a guard `is`, and one `codec`, a Standard Schema: `Descriptor.ConstructedComponent(Vector2.codec)` saves the value and checks it on restore. Inside a game's own schema, build the field from the guard (`Schema.declare(Vector2.is)` in Effect, `z.custom(Vector2.is)` in Zod). `Random.codec` does the same for a generator kept in a resource.
6
- - **Hot-path helpers** on plain numbers, for code that runs every step: `Vec2` vector arithmetic (validated `Vector2` values pass straight in), `Box2` edge boxes, `Collide2` swept circle collision that slides along walls and never tunnels through them, a `SpatialGrid` broad phase that allocates nothing per step, a `FlowField` that leads bodies around walls, a deterministic `Random` whose whole state is one integer (keep it in a resource, so runs replay), and `Ops`, math functions that return the same bits on every engine.
5
+ - `Vec2`: vector arithmetic on `{ x, y }`, lengths, `perpendicular`, `fromAngle` and `angle`, `moveToward`, `clampLength`, and `decayToward`, an ease that is the same at any step rate.
6
+ - `Angle`: `wrap` into [-π, π) and `turnToward` the short way at a capped rate, for headings stored as one number.
7
+ - `Scalar`: `moveToward`, `lerp`, and `decayToward` on plain numbers.
8
+ - `Box2` edge boxes and `Segment2` walls at any angle, with circle overlap tests and `Box2.closestPoint`.
9
+ - `Collide2`: swept circle collision against boxes and segments that slides along walls and never tunnels through them, circle against circle, and `pushOut`.
10
+ - `FlowField`: one search toward a goal that leads every body around the walls.
7
11
 
8
12
  ```ts
9
- import { Collide2, FlowField, Random, SpatialGrid, Vec2 } from "@typeonce/ritmo-math"
13
+ import { Collide2, FlowField, Vec2 } from "@typeonce/ritmo-math"
14
+
15
+ // Once: a flow field with 30-unit cells (a typed failure for a bad size).
16
+ const made = FlowField.make(30)
17
+ if (!made.ok) throw new Error(`bad cell size ${made.error.value}`)
18
+ const paths = made.value
10
19
 
11
20
  // Each step: chase the player around the walls, sliding along them.
12
21
  paths.setWalls(walls, radius)
13
22
  paths.setGoal(player)
14
23
  const way = paths.way(enemy) ?? Vec2.normalizeOr(Vec2.subtract(player, enemy), Vec2.zero)
15
- const moved = Collide2.moveCircle(enemy, Vec2.scale(way, speed * dt), radius, walls)
24
+ const moved = Collide2.moveCircle(enemy, Vec2.scale(way, speed * dt), radius, { boxes: walls })
16
25
  ```
17
26
 
18
27
  ```sh
19
28
  pnpm add @typeonce/ritmo-math @typeonce/ritmo
20
29
  ```
21
30
 
22
- ## Determinism across devices
31
+ Values come in already validated: a position is a component the game's own schema checked when it entered the world (`z.object({ x: z.number(), y: z.number() })` and the like), and every helper reads and returns that plain shape. There are no math value types to construct and no codecs here.
23
32
 
24
- JavaScript engines may approximate `Math.sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `atan2`, `exp`, `expm1`, `log`, `log2`, `log10`, `log1p`, `cbrt`, `pow`, `hypot`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, and `a ** b`, and they do: Chrome, Safari, macOS, and Linux disagree in the last bit, and a simulation grows that bit into a different run, so a session recorded on a phone stops replaying on a server. `Ops` has the same functions as pure-JavaScript ports of fdlibm, built only from operations every engine rounds exactly, so they return the same bits everywhere (within an ulp of the exact value). Use them in simulation code; `Math.abs`, `min`, `max`, `floor`, `ceil`, `round`, `trunc`, `sign`, `sqrt`, `+ - * /`, and `x ** 2` are already exact. `Vec2`, `Collide2`, and `FlowField` use `Ops` themselves, and the `ritmo/use-ops-for-math` rule of [`@typeonce/oxlint-plugin-ritmo`](https://github.com/typeonce-dev/ritmo/blob/main/packages/oxlint-plugin/README.md) reports the `Math` calls left in simulation code.
33
+ ## Determinism
25
34
 
26
- ```ts
27
- import { Ops } from "@typeonce/ritmo-math"
35
+ Every helper that needs a non-exact function (`cos`, `sin`, `atan2`, `exp`, `hypot`) calls [`Ops`](https://github.com/typeonce-dev/ritmo/blob/main/packages/core/README.md) from `@typeonce/ritmo`, so a session recorded in one browser replays on any other engine. `Angle`, `Box2`, `Segment2`, `perpendicular`, and the rest use only operations every engine rounds exactly. Game code that needs other math calls `Ops` directly; the `ritmo/use-ops-for-math` rule of [`@typeonce/oxlint-plugin-ritmo`](https://github.com/typeonce-dev/ritmo/blob/main/packages/oxlint-plugin/README.md) reports a `Math` call left in simulation code, and `oxlint --fix` rewrites it.
28
36
 
29
- const heading = Ops.atan2(target.y - position.y, target.x - position.x)
30
- const velocity = { x: Ops.cos(heading) * speed, y: Ops.sin(heading) * speed }
31
- const damping = Ops.exp(-friction * dt)
32
- ```
37
+ A broad phase (a spatial grid) is not here: the [skill](https://github.com/typeonce-dev/ritmo/blob/main/packages/core/skills/ritmo/playbooks/spatial-grid.md) has one to copy into the game, sized to its own data.
33
38
 
34
39
  Released together with [`@typeonce/ritmo`](https://github.com/typeonce-dev/ritmo/blob/main/packages/core/README.md), always with the same version.
35
40
 
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Angles in radians, for headings a system stores as one number: a turret's
3
+ * aim, a body's facing.
4
+ *
5
+ * Angles wrap: 350° and -10° are the same heading, so comparing or turning
6
+ * them needs the wrap first. `wrap` brings any angle into [-π, π), and the
7
+ * difference between two headings is `wrap(to - from)`, the short way round.
8
+ * Both helpers are exact (`%` and `+ -` only), so they replay the same on
9
+ * every engine. For the angle of a vector use `Vec2.angle`, for the unit
10
+ * vector of an angle `Vec2.fromAngle`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Turn a turret toward its target at a capped rate.
15
+ * const wanted = Vec2.angle(Vec2.subtract(target, turret.position))
16
+ * const aim = Angle.turnToward(turret.aim, wanted, turnRate * dt)
17
+ * ```
18
+ *
19
+ * @module Angle
20
+ * @docGroup helpers
21
+ *
22
+ * @categoryDescription Operations
23
+ * Wrapping and turning angles.
24
+ */
25
+ /**
26
+ * `angle` brought into [-π, π) by whole turns: π and -π both give -π. Use it
27
+ * to keep a stored heading bounded, and for the signed short-way difference
28
+ * between two headings, `wrap(to - from)`. Exact on every engine.
29
+ *
30
+ * @category Operations
31
+ */
32
+ export declare const wrap: (angle: number) => number;
33
+ /**
34
+ * `angle` turned toward `target` the short way by at most `maxStep` radians,
35
+ * never overshooting: `wrap(target)` once it is within `maxStep`, and
36
+ * `wrap(angle)` when `maxStep` is 0 or less. Headings exactly half a turn
37
+ * apart turn the negative way. For a capped turn rate (a turret, a homing
38
+ * shot); for plain numbers use `Scalar.moveToward`, for points
39
+ * `Vec2.moveToward`.
40
+ *
41
+ * @category Operations
42
+ */
43
+ export declare const turnToward: (angle: number, target: number, maxStep: number) => number;
44
+ //# sourceMappingURL=Angle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Angle.d.ts","sourceRoot":"","sources":["../src/Angle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,UAAW,MAAM,KAAG,MAOpC,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,UAAU,MAAM,WAAW,MAAM,KAAG,MAM3E,CAAA"}
package/dist/Angle.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Angles in radians, for headings a system stores as one number: a turret's
3
+ * aim, a body's facing.
4
+ *
5
+ * Angles wrap: 350° and -10° are the same heading, so comparing or turning
6
+ * them needs the wrap first. `wrap` brings any angle into [-π, π), and the
7
+ * difference between two headings is `wrap(to - from)`, the short way round.
8
+ * Both helpers are exact (`%` and `+ -` only), so they replay the same on
9
+ * every engine. For the angle of a vector use `Vec2.angle`, for the unit
10
+ * vector of an angle `Vec2.fromAngle`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Turn a turret toward its target at a capped rate.
15
+ * const wanted = Vec2.angle(Vec2.subtract(target, turret.position))
16
+ * const aim = Angle.turnToward(turret.aim, wanted, turnRate * dt)
17
+ * ```
18
+ *
19
+ * @module Angle
20
+ * @docGroup helpers
21
+ *
22
+ * @categoryDescription Operations
23
+ * Wrapping and turning angles.
24
+ */
25
+ const TAU = 2 * Math.PI;
26
+ /**
27
+ * `angle` brought into [-π, π) by whole turns: π and -π both give -π. Use it
28
+ * to keep a stored heading bounded, and for the signed short-way difference
29
+ * between two headings, `wrap(to - from)`. Exact on every engine.
30
+ *
31
+ * @category Operations
32
+ */
33
+ export const wrap = (angle) => {
34
+ // `%` is exact, and so is adding or removing one turn from a value within
35
+ // one turn of it, so the result is the exact remainder.
36
+ let wrapped = angle % TAU;
37
+ if (wrapped >= Math.PI)
38
+ wrapped -= TAU;
39
+ else if (wrapped < -Math.PI)
40
+ wrapped += TAU;
41
+ return wrapped === 0 ? 0 : wrapped;
42
+ };
43
+ /**
44
+ * `angle` turned toward `target` the short way by at most `maxStep` radians,
45
+ * never overshooting: `wrap(target)` once it is within `maxStep`, and
46
+ * `wrap(angle)` when `maxStep` is 0 or less. Headings exactly half a turn
47
+ * apart turn the negative way. For a capped turn rate (a turret, a homing
48
+ * shot); for plain numbers use `Scalar.moveToward`, for points
49
+ * `Vec2.moveToward`.
50
+ *
51
+ * @category Operations
52
+ */
53
+ export const turnToward = (angle, target, maxStep) => {
54
+ const from = wrap(angle);
55
+ if (!(maxStep > 0))
56
+ return from;
57
+ const gap = wrap(target - from);
58
+ if (Math.abs(gap) <= maxStep)
59
+ return wrap(target);
60
+ return wrap(gap > 0 ? from + maxStep : from - maxStep);
61
+ };
62
+ //# sourceMappingURL=Angle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Angle.js","sourceRoot":"","sources":["../src/Angle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,CAAA;AAEvB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5C,0EAA0E;IAC1E,wDAAwD;IACxD,IAAI,OAAO,GAAG,KAAK,GAAG,GAAG,CAAA;IACzB,IAAI,OAAO,IAAI,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,GAAG,CAAA;SACjC,IAAI,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,GAAG,CAAA;IAC3C,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AACpC,CAAC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,OAAe,EAAU,EAAE;IACnF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;IACxB,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAA;IACjD,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAA;AACxD,CAAC,CAAA"}
package/dist/Box2.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Plain axis-aligned boxes stored by their edges, for hot-path collision.
3
3
  *
4
- * `Aabb` is the validated, centered box for authored and stored values;
5
4
  * `Box2` is the edge form the collision helpers (`Collide2`, `FlowField`)
6
- * read every frame, built once from whatever the game stores.
5
+ * read every frame, built once from whatever the game stores (a center and a
6
+ * size, a tile's corner).
7
7
  *
8
8
  * @example
9
9
  * ```ts
@@ -18,7 +18,7 @@
18
18
  * The structural box shape.
19
19
  *
20
20
  * @categoryDescription Operations
21
- * Building boxes and testing them against circles.
21
+ * Building boxes, testing them against circles, and the closest point.
22
22
  */
23
23
  import type { Vec2 } from "./Vec2.ts";
24
24
  /**
@@ -41,9 +41,21 @@ export interface Box2 {
41
41
  */
42
42
  export declare const around: (x: number, y: number, halfWidth: number, halfHeight: number) => Box2;
43
43
  /**
44
- * Whether a circle overlaps (or touches) the box.
44
+ * Whether a circle overlaps (or touches) the box. For two circles use
45
+ * `Collide2.overlapsCircleCircle`, for a wall at any angle
46
+ * `Segment2.overlapsCircle`.
45
47
  *
46
48
  * @category Operations
47
49
  */
48
50
  export declare const overlapsCircle: (box: Box2, center: Vec2, radius: number) => boolean;
51
+ /**
52
+ * The point of `box` closest to `point`: `point` clamped to the box's edges.
53
+ * A point inside the box comes back unchanged, so this keeps a body inside an
54
+ * arena, or gives the direction from an obstacle to a body outside it
55
+ * (`Vec2.subtract(body, closestPoint(box, body))`). To push a circle out of
56
+ * walls it overlaps, use `Collide2.pushOut`.
57
+ *
58
+ * @category Operations
59
+ */
60
+ export declare const closestPoint: (box: Box2, point: Vec2) => Vec2;
49
61
  //# sourceMappingURL=Box2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Box2.d.ts","sourceRoot":"","sources":["../src/Box2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,MAAO,MAAM,KAAK,MAAM,aAAa,MAAM,cAAc,MAAM,KAAG,IAKnF,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAS,IAAI,UAAU,IAAI,UAAU,MAAM,KAAG,OAIxE,CAAA"}
1
+ {"version":3,"file":"Box2.d.ts","sourceRoot":"","sources":["../src/Box2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,MAAO,MAAM,KAAK,MAAM,aAAa,MAAM,cAAc,MAAM,KAAG,IAKnF,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAAS,IAAI,UAAU,IAAI,UAAU,MAAM,KAAG,OAIxE,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,QAAS,IAAI,SAAS,IAAI,KAAG,IAGpD,CAAA"}
package/dist/Box2.js CHANGED
@@ -11,7 +11,9 @@ export const around = (x, y, halfWidth, halfHeight) => ({
11
11
  maxY: y + halfHeight
12
12
  });
13
13
  /**
14
- * Whether a circle overlaps (or touches) the box.
14
+ * Whether a circle overlaps (or touches) the box. For two circles use
15
+ * `Collide2.overlapsCircleCircle`, for a wall at any angle
16
+ * `Segment2.overlapsCircle`.
15
17
  *
16
18
  * @category Operations
17
19
  */
@@ -20,4 +22,17 @@ export const overlapsCircle = (box, center, radius) => {
20
22
  const dy = center.y - Math.max(box.minY, Math.min(center.y, box.maxY));
21
23
  return dx * dx + dy * dy <= radius * radius;
22
24
  };
25
+ /**
26
+ * The point of `box` closest to `point`: `point` clamped to the box's edges.
27
+ * A point inside the box comes back unchanged, so this keeps a body inside an
28
+ * arena, or gives the direction from an obstacle to a body outside it
29
+ * (`Vec2.subtract(body, closestPoint(box, body))`). To push a circle out of
30
+ * walls it overlaps, use `Collide2.pushOut`.
31
+ *
32
+ * @category Operations
33
+ */
34
+ export const closestPoint = (box, point) => ({
35
+ x: Math.max(box.minX, Math.min(point.x, box.maxX)),
36
+ y: Math.max(box.minY, Math.min(point.y, box.maxY))
37
+ });
23
38
  //# sourceMappingURL=Box2.js.map
package/dist/Box2.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Box2.js","sourceRoot":"","sources":["../src/Box2.ts"],"names":[],"mappings":"AAqCA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,SAAiB,EAAE,UAAkB,EAAQ,EAAE,CAAC,CAAC;IAC5F,IAAI,EAAE,CAAC,GAAG,SAAS;IACnB,IAAI,EAAE,CAAC,GAAG,UAAU;IACpB,IAAI,EAAE,CAAC,GAAG,SAAS;IACnB,IAAI,EAAE,CAAC,GAAG,UAAU;CACrB,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAS,EAAE,MAAY,EAAE,MAAc,EAAW,EAAE;IACjF,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IACtE,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC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KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;CACnD,CAAC,CAAA"}
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Continuous collision for moving circles against static boxes and circles.
2
+ * Continuous collision for moving circles against static walls (axis-aligned
3
+ * boxes and line segments) and circles.
3
4
  *
4
- * Movement is swept, not sampled: `sweepCircleBox` finds the first time of
5
+ * Movement is swept, not sampled: `sweepCircle` finds the first time of
5
6
  * contact along the whole displacement, so fast movers (dashes, projectiles)
6
7
  * cannot skip over a wall between two steps. `moveCircle` stops at walls and
7
- * slides along them.
8
+ * slides along them. Walls are passed as {@link Walls}: `Box2` boxes for a
9
+ * grid of rooms, `Segment2` segments for walls at any angle, or both.
8
10
  *
9
11
  * Every query returns `undefined` for "no contact", never throws, and
10
12
  * allocates only its result. Inputs are expected to be finite.
@@ -12,7 +14,7 @@
12
14
  * @example
13
15
  * ```ts
14
16
  * // Move a body by its velocity this step, sliding along the walls.
15
- * const moved = Collide2.moveCircle(position, Vec2.scale(velocity, dt), radius, walls)
17
+ * const moved = Collide2.moveCircle(position, Vec2.scale(velocity, dt), radius, { boxes: walls })
16
18
  * if (moved.blocked) bumpedWall()
17
19
  * ```
18
20
  *
@@ -23,12 +25,13 @@
23
25
  * Contacts and movement results.
24
26
  *
25
27
  * @categoryDescription Queries
26
- * First-contact sweeps and overlap resolution.
28
+ * First-contact sweeps and overlap tests.
27
29
  *
28
30
  * @categoryDescription Movement
29
31
  * Moving a circle through walls with sliding.
30
32
  */
31
33
  import type { Box2 } from "./Box2.ts";
34
+ import type { Segment2 } from "./Segment2.ts";
32
35
  import type { Vec2 } from "./Vec2.ts";
33
36
  /**
34
37
  * A contact along a sweep.
@@ -38,10 +41,22 @@ import type { Vec2 } from "./Vec2.ts";
38
41
  export interface Hit {
39
42
  /** Fraction of the displacement travelled before contact, in [0, 1]. */
40
43
  readonly time: number;
41
- /** Unit contact normal, pointing away from the box. */
44
+ /** Unit contact normal, pointing away from the wall. */
42
45
  readonly nx: number;
43
46
  readonly ny: number;
44
47
  }
48
+ /**
49
+ * The static walls a circle collides with: axis-aligned `boxes`, line
50
+ * `segments`, or both. A missing list is no walls of that kind.
51
+ *
52
+ * @category Collision Types
53
+ */
54
+ export interface Walls {
55
+ readonly boxes?: ReadonlyArray<Box2>;
56
+ readonly segments?: ReadonlyArray<Segment2>;
57
+ /** Not a setting: an array of walls is passed by kind. */
58
+ readonly length?: "pass walls by kind: { boxes: walls } or { segments: walls }";
59
+ }
45
60
  /**
46
61
  * Where a moved circle ended up.
47
62
  *
@@ -79,7 +94,18 @@ export declare const rayCircle: (ox: number, oy: number, dx: number, dy: number,
79
94
  */
80
95
  export declare const sweepCircleBox: (origin: Vec2, delta: Vec2, radius: number, box: Box2) => Hit | undefined;
81
96
  /**
82
- * First contact of a moving circle with any of `boxes`, or `undefined`.
97
+ * First contact of a circle of `radius` at `origin` moving by `delta` with
98
+ * `segment`, or `undefined`. Contact is computed against the segment
99
+ * thickened by the radius with round ends (the exact Minkowski sum), so the
100
+ * circle slides along it and around its ends. A circle that starts exactly
101
+ * touching it and moves into it hits at time 0. A circle that starts
102
+ * overlapping the segment is not reported; resolve it with `pushOut` first.
103
+ *
104
+ * @category Queries
105
+ */
106
+ export declare const sweepCircleSegment: (origin: Vec2, delta: Vec2, radius: number, segment: Segment2) => Hit | undefined;
107
+ /**
108
+ * First contact of a moving circle with any of `walls`, or `undefined`.
83
109
  *
84
110
  * With a `radius` of 0 the circle is a point and the sweep is a segment, so
85
111
  * this is also line of sight: `undefined` means nothing blocks the line from
@@ -88,12 +114,12 @@ export declare const sweepCircleBox: (origin: Vec2, delta: Vec2, radius: number,
88
114
  *
89
115
  * @example
90
116
  * ```ts
91
- * const sees = Collide2.sweepCircleBoxes(eye, Vec2.subtract(target, eye), 0, walls) === undefined
117
+ * const sees = Collide2.sweepCircle(eye, Vec2.subtract(target, eye), 0, { boxes: walls }) === undefined
92
118
  * ```
93
119
  *
94
120
  * @category Queries
95
121
  */
96
- export declare const sweepCircleBoxes: (origin: Vec2, delta: Vec2, radius: number, boxes: ReadonlyArray<Box2>) => Hit | undefined;
122
+ export declare const sweepCircle: (origin: Vec2, delta: Vec2, radius: number, walls: Walls) => Hit | undefined;
97
123
  /**
98
124
  * First time in [0, 1] at which a circle of `radius` moving from `origin` by
99
125
  * `delta` touches a circle of `targetRadius` at `target`, or `undefined`. A
@@ -103,20 +129,38 @@ export declare const sweepCircleBoxes: (origin: Vec2, delta: Vec2, radius: numbe
103
129
  */
104
130
  export declare const sweepCircleCircle: (origin: Vec2, delta: Vec2, radius: number, target: Vec2, targetRadius: number) => number | undefined;
105
131
  /**
106
- * Pushes a circle out of every box it overlaps, in order, leaving `skin`
107
- * between it and each wall. Returns the corrected center.
132
+ * Whether a circle of `radius` at `center` overlaps (or touches) a circle of
133
+ * `otherRadius` at `other`, without a square root. Touching counts, as in
134
+ * `Box2.overlapsCircle` and `Segment2.overlapsCircle`. For a pickup or a hit
135
+ * between bodies that have already moved; when one moves fast enough to pass
136
+ * through the other in one step, use {@link sweepCircleCircle}.
137
+ *
138
+ * @category Queries
139
+ */
140
+ export declare const overlapsCircleCircle: (center: Vec2, radius: number, other: Vec2, otherRadius: number) => boolean;
141
+ /**
142
+ * Pushes a circle out of every wall it overlaps, boxes first and then
143
+ * segments, each in order, leaving `skin` between it and each wall. Returns
144
+ * the corrected center. A center inside a box leaves through the nearest
145
+ * side; a center exactly on a segment leaves along the segment's left normal.
108
146
  *
109
147
  * @category Movement
110
148
  */
111
- export declare const pushOut: (center: Vec2, radius: number, boxes: ReadonlyArray<Box2>, skin?: number) => Vec2;
149
+ export declare const pushOut: (center: Vec2, radius: number, walls: Walls, skin?: number) => Vec2;
112
150
  /**
113
151
  * Moves a circle by `delta`, stopping at walls and sliding along them (up to
114
152
  * four contacts per call). The whole path is swept, so no displacement can
115
153
  * tunnel through a wall. A circle that starts inside a wall is pushed out
116
- * first. A circle meeting a box's corner dead-on goes around it rather than
117
- * stopping against it.
154
+ * first. A circle meeting a box's corner or a segment's end dead-on goes
155
+ * around it rather than stopping against it.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * // A map traced from survey data: every wall is a segment.
160
+ * const moved = Collide2.moveCircle(position, delta, radius, { segments: nearbyWalls })
161
+ * ```
118
162
  *
119
163
  * @category Movement
120
164
  */
121
- export declare const moveCircle: (start: Vec2, delta: Vec2, radius: number, boxes: ReadonlyArray<Box2>, skin?: number) => MoveResult;
165
+ export declare const moveCircle: (start: Vec2, delta: Vec2, radius: number, walls: Walls, skin?: number) => MoveResult;
122
166
  //# sourceMappingURL=Collide2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Collide2.d.ts","sourceRoot":"","sources":["../src/Collide2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;;GAIG;AACH,MAAM,WAAW,GAAG;IAClB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;IACvB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,OAAO,CAAA;AAE/B;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,OAAQ,MAAM,MAAM,MAAM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