@typeonce/ritmo-math 0.14.0 → 0.16.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 (112) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +17 -12
  3. package/dist/Angle.d.ts +49 -0
  4. package/dist/Angle.d.ts.map +1 -0
  5. package/dist/Angle.js +67 -0
  6. package/dist/Angle.js.map +1 -0
  7. package/dist/Box2.d.ts +20 -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 +23 -1
  12. package/dist/Collide2.d.ts.map +1 -1
  13. package/dist/Collide2.js +23 -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 +22 -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 +54 -51
  22. package/dist/Scalar.js.map +1 -1
  23. package/dist/Segment2.d.ts +3 -0
  24. package/dist/Segment2.d.ts.map +1 -1
  25. package/dist/Segment2.js.map +1 -1
  26. package/dist/Vec2.d.ts +50 -7
  27. package/dist/Vec2.d.ts.map +1 -1
  28. package/dist/Vec2.js +59 -8
  29. package/dist/Vec2.js.map +1 -1
  30. package/dist/index.d.ts +9 -22
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +9 -22
  33. package/dist/index.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/Angle.ts +65 -0
  36. package/src/Box2.ts +24 -4
  37. package/src/Collide2.ts +30 -2
  38. package/src/FlowField.ts +38 -10
  39. package/src/Scalar.ts +46 -165
  40. package/src/Segment2.ts +3 -0
  41. package/src/Vec2.ts +61 -8
  42. package/src/index.ts +9 -22
  43. package/dist/Aabb.d.ts +0 -182
  44. package/dist/Aabb.d.ts.map +0 -1
  45. package/dist/Aabb.js +0 -109
  46. package/dist/Aabb.js.map +0 -1
  47. package/dist/InputAxis.d.ts +0 -44
  48. package/dist/InputAxis.d.ts.map +0 -1
  49. package/dist/InputAxis.js +0 -71
  50. package/dist/InputAxis.js.map +0 -1
  51. package/dist/Ops.d.ts +0 -209
  52. package/dist/Ops.d.ts.map +0 -1
  53. package/dist/Ops.js +0 -210
  54. package/dist/Ops.js.map +0 -1
  55. package/dist/Random.d.ts +0 -124
  56. package/dist/Random.d.ts.map +0 -1
  57. package/dist/Random.js +0 -126
  58. package/dist/Random.js.map +0 -1
  59. package/dist/Size2.d.ts +0 -118
  60. package/dist/Size2.d.ts.map +0 -1
  61. package/dist/Size2.js +0 -54
  62. package/dist/Size2.js.map +0 -1
  63. package/dist/SpatialGrid.d.ts +0 -68
  64. package/dist/SpatialGrid.d.ts.map +0 -1
  65. package/dist/SpatialGrid.js +0 -112
  66. package/dist/SpatialGrid.js.map +0 -1
  67. package/dist/Vector2.d.ts +0 -214
  68. package/dist/Vector2.d.ts.map +0 -1
  69. package/dist/Vector2.js +0 -134
  70. package/dist/Vector2.js.map +0 -1
  71. package/dist/internal/aabb.d.ts +0 -27
  72. package/dist/internal/aabb.d.ts.map +0 -1
  73. package/dist/internal/aabb.js +0 -52
  74. package/dist/internal/aabb.js.map +0 -1
  75. package/dist/internal/codec.d.ts +0 -9
  76. package/dist/internal/codec.d.ts.map +0 -1
  77. package/dist/internal/codec.js +0 -16
  78. package/dist/internal/codec.js.map +0 -1
  79. package/dist/internal/fdlibm.d.ts +0 -43
  80. package/dist/internal/fdlibm.d.ts.map +0 -1
  81. package/dist/internal/fdlibm.js +0 -1291
  82. package/dist/internal/fdlibm.js.map +0 -1
  83. package/dist/internal/inputAxis.d.ts +0 -11
  84. package/dist/internal/inputAxis.d.ts.map +0 -1
  85. package/dist/internal/inputAxis.js +0 -13
  86. package/dist/internal/inputAxis.js.map +0 -1
  87. package/dist/internal/scalar.d.ts +0 -11
  88. package/dist/internal/scalar.d.ts.map +0 -1
  89. package/dist/internal/scalar.js +0 -68
  90. package/dist/internal/scalar.js.map +0 -1
  91. package/dist/internal/size2.d.ts +0 -22
  92. package/dist/internal/size2.d.ts.map +0 -1
  93. package/dist/internal/size2.js +0 -38
  94. package/dist/internal/size2.js.map +0 -1
  95. package/dist/internal/vector2.d.ts +0 -39
  96. package/dist/internal/vector2.d.ts.map +0 -1
  97. package/dist/internal/vector2.js +0 -78
  98. package/dist/internal/vector2.js.map +0 -1
  99. package/src/Aabb.ts +0 -180
  100. package/src/InputAxis.ts +0 -81
  101. package/src/Ops.ts +0 -232
  102. package/src/Random.ts +0 -225
  103. package/src/Size2.ts +0 -122
  104. package/src/SpatialGrid.ts +0 -172
  105. package/src/Vector2.ts +0 -216
  106. package/src/internal/aabb.ts +0 -81
  107. package/src/internal/codec.ts +0 -21
  108. package/src/internal/fdlibm.ts +0 -1256
  109. package/src/internal/inputAxis.ts +0 -21
  110. package/src/internal/scalar.ts +0 -104
  111. package/src/internal/size2.ts +0 -54
  112. package/src/internal/vector2.ts +0 -121
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,oBAAo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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
@@ -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
@@ -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"}
package/dist/Ops.d.ts DELETED
@@ -1,209 +0,0 @@
1
- /**
2
- * Math functions that return the same bits on every JavaScript engine and
3
- * CPU, so a simulation replays exactly on any device.
4
- *
5
- * The spec lets engines approximate `Math.sin`, `cos`, `tan`, `asin`, `acos`,
6
- * `atan`, `atan2`, `exp`, `expm1`, `log`, `log2`, `log10`, `log1p`, `sinh`,
7
- * `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, `cbrt`, `pow`, `hypot`, and
8
- * `a ** b`, and they do: Chrome, Safari, macOS, and Linux disagree in the
9
- * last bit, and a simulation grows that bit into a different run. Use these
10
- * in simulation code instead; each is a pure-JavaScript port of fdlibm (musl
11
- * libm) built only from operations every engine rounds exactly.
12
- *
13
- * Keep using `Math.abs`, `sign`, `min`, `max`, `floor`, `ceil`, `round`,
14
- * `trunc`, `sqrt`, `imul`, `fround`, `+ - * /`, and `x ** 2`: they are
15
- * already exact everywhere. Use `Random` for randomness and `Clock` for time.
16
- * Code that only draws (rendering, effects) can use `Math` freely. The
17
- * `ritmo/use-ops-for-math` rule (`@typeonce/oxlint-plugin-ritmo`) points
18
- * simulation code here.
19
- *
20
- * @example
21
- * ```ts
22
- * // Inside a system: aim, then move along the heading.
23
- * const heading = Ops.atan2(target.y - position.y, target.x - position.x)
24
- * const step = { x: Ops.cos(heading) * speed * dt, y: Ops.sin(heading) * speed * dt }
25
- * const damping = Ops.exp(-friction * dt)
26
- * ```
27
- *
28
- * @module Ops
29
- * @docGroup helpers
30
- *
31
- * @categoryDescription Trigonometry
32
- * Sine, cosine, tangent, and their inverses, in radians.
33
- *
34
- * @categoryDescription Exponentials
35
- * Exponentials, logarithms, powers, and roots.
36
- *
37
- * @categoryDescription Hyperbolic
38
- * Hyperbolic functions and their inverses.
39
- *
40
- * @categoryDescription Lengths
41
- * Euclidean length without overflow.
42
- */
43
- /**
44
- * Sine of `x` radians. Same bits on every engine (within 1 ulp of the exact
45
- * value); use instead of `Math.sin` in simulation code.
46
- *
47
- * @category Trigonometry
48
- */
49
- export declare const sin: (x: number) => number;
50
- /**
51
- * Cosine of `x` radians. Same bits on every engine (within 1 ulp of the
52
- * exact value); use instead of `Math.cos` in simulation code.
53
- *
54
- * @category Trigonometry
55
- */
56
- export declare const cos: (x: number) => number;
57
- /**
58
- * Tangent of `x` radians. Same bits on every engine (within 1 ulp of the
59
- * exact value); use instead of `Math.tan` in simulation code.
60
- *
61
- * @category Trigonometry
62
- */
63
- export declare const tan: (x: number) => number;
64
- /**
65
- * Arcsine of `x` in radians, in [-π/2, π/2]; NaN outside [-1, 1]. Same bits
66
- * on every engine; use instead of `Math.asin` in simulation code.
67
- *
68
- * @category Trigonometry
69
- */
70
- export declare const asin: (x: number) => number;
71
- /**
72
- * Arccosine of `x` in radians, in [0, π]; NaN outside [-1, 1]. Same bits on
73
- * every engine; use instead of `Math.acos` in simulation code.
74
- *
75
- * @category Trigonometry
76
- */
77
- export declare const acos: (x: number) => number;
78
- /**
79
- * Arctangent of `x` in radians, in (-π/2, π/2). Same bits on every engine;
80
- * use instead of `Math.atan` in simulation code. For the angle of a vector,
81
- * use `atan2`.
82
- *
83
- * @category Trigonometry
84
- */
85
- export declare const atan: (x: number) => number;
86
- /**
87
- * The angle of the vector (x, y) in radians, in [-π, π] (note the argument
88
- * order: `y` first, like `Math.atan2`). Same bits on every engine; use
89
- * instead of `Math.atan2` in simulation code.
90
- *
91
- * @category Trigonometry
92
- */
93
- export declare const atan2: (y: number, x: number) => number;
94
- /**
95
- * e raised to `x`. Same bits on every engine (within 1 ulp of the exact
96
- * value); use instead of `Math.exp` in simulation code, for example for
97
- * frame-rate independent damping `exp(-rate * dt)`.
98
- *
99
- * @category Exponentials
100
- */
101
- export declare const exp: (x: number) => number;
102
- /**
103
- * Hyperbolic tangent of `x`, in [-1, 1]. Same bits on every engine (within 2
104
- * ulp of the exact value, like the native one); use instead of `Math.tanh` in
105
- * simulation code.
106
- *
107
- * @category Hyperbolic
108
- */
109
- export declare const tanh: (x: number) => number;
110
- /**
111
- * e raised to `x`, minus 1, accurate for `x` near 0 (where `exp(x) - 1` loses
112
- * digits). Same bits on every engine; use instead of `Math.expm1` in
113
- * simulation code.
114
- *
115
- * @category Exponentials
116
- */
117
- export declare const expm1: (x: number) => number;
118
- /**
119
- * Natural logarithm of `x`: -Infinity at 0, NaN below 0. Same bits on every
120
- * engine (within 1 ulp of the exact value); use instead of `Math.log` in
121
- * simulation code.
122
- *
123
- * @category Exponentials
124
- */
125
- export declare const log: (x: number) => number;
126
- /**
127
- * Base-2 logarithm of `x`: -Infinity at 0, NaN below 0, exact for powers of
128
- * two. Same bits on every engine; use instead of `Math.log2` in simulation
129
- * code.
130
- *
131
- * @category Exponentials
132
- */
133
- export declare const log2: (x: number) => number;
134
- /**
135
- * Base-10 logarithm of `x`: -Infinity at 0, NaN below 0. Same bits on every
136
- * engine; use instead of `Math.log10` in simulation code.
137
- *
138
- * @category Exponentials
139
- */
140
- export declare const log10: (x: number) => number;
141
- /**
142
- * Natural logarithm of `1 + x`, accurate for `x` near 0 (where `log(1 + x)`
143
- * loses digits). Same bits on every engine; use instead of `Math.log1p` in
144
- * simulation code.
145
- *
146
- * @category Exponentials
147
- */
148
- export declare const log1p: (x: number) => number;
149
- /**
150
- * Cube root of `x`, negative for negative `x`. Same bits on every engine;
151
- * use instead of `Math.cbrt` and `x ** (1 / 3)` in simulation code.
152
- *
153
- * @category Exponentials
154
- */
155
- export declare const cbrt: (x: number) => number;
156
- /**
157
- * `base` raised to `exponent`, with the results of `base ** exponent` for
158
- * every special case (NaN, zeros, infinities, negative bases). Same bits on
159
- * every engine (within 1 ulp of the exact value); use instead of `Math.pow`
160
- * and `**` in simulation code. `x * x` and `x ** 2` are already exact.
161
- *
162
- * @category Exponentials
163
- */
164
- export declare const pow: (base: number, exponent: number) => number;
165
- /**
166
- * Hyperbolic sine of `x`. Same bits on every engine (within 1 ulp of the
167
- * exact value); use instead of `Math.sinh` in simulation code.
168
- *
169
- * @category Hyperbolic
170
- */
171
- export declare const sinh: (x: number) => number;
172
- /**
173
- * Hyperbolic cosine of `x`, at least 1. Same bits on every engine (within 1
174
- * ulp of the exact value); use instead of `Math.cosh` in simulation code.
175
- *
176
- * @category Hyperbolic
177
- */
178
- export declare const cosh: (x: number) => number;
179
- /**
180
- * Inverse hyperbolic sine of `x`. Same bits on every engine; use instead of
181
- * `Math.asinh` in simulation code.
182
- *
183
- * @category Hyperbolic
184
- */
185
- export declare const asinh: (x: number) => number;
186
- /**
187
- * Inverse hyperbolic cosine of `x`: NaN below 1. Same bits on every engine;
188
- * use instead of `Math.acosh` in simulation code.
189
- *
190
- * @category Hyperbolic
191
- */
192
- export declare const acosh: (x: number) => number;
193
- /**
194
- * Inverse hyperbolic tangent of `x`: ±Infinity at ±1, NaN beyond. Same bits
195
- * on every engine; use instead of `Math.atanh` in simulation code.
196
- *
197
- * @category Hyperbolic
198
- */
199
- export declare const atanh: (x: number) => number;
200
- /**
201
- * The length of the vector (x, y), `sqrt(x² + y²)` without overflow or
202
- * underflow. Same bits on every engine (within 1 ulp of the exact value);
203
- * use instead of `Math.hypot` in simulation code. Takes exactly two numbers;
204
- * for vectors use `Vec2.length` and `Vec2.distance`.
205
- *
206
- * @category Lengths
207
- */
208
- export declare const hypot: (x: number, y: number) => number;
209
- //# sourceMappingURL=Ops.d.ts.map
package/dist/Ops.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Ops.d.ts","sourceRoot":"","sources":["../src/Ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAmB,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAmB,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAmB,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAoB,CAAA;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAoB,CAAA;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAoB,CAAA;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAqB,CAAA;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAmB,CAAA;AAEpD;;;;;;GAMG;A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C,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAqB,CAAA"}
package/dist/Ops.js DELETED
@@ -1,210 +0,0 @@
1
- /**
2
- * Math functions that return the same bits on every JavaScript engine and
3
- * CPU, so a simulation replays exactly on any device.
4
- *
5
- * The spec lets engines approximate `Math.sin`, `cos`, `tan`, `asin`, `acos`,
6
- * `atan`, `atan2`, `exp`, `expm1`, `log`, `log2`, `log10`, `log1p`, `sinh`,
7
- * `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, `cbrt`, `pow`, `hypot`, and
8
- * `a ** b`, and they do: Chrome, Safari, macOS, and Linux disagree in the
9
- * last bit, and a simulation grows that bit into a different run. Use these
10
- * in simulation code instead; each is a pure-JavaScript port of fdlibm (musl
11
- * libm) built only from operations every engine rounds exactly.
12
- *
13
- * Keep using `Math.abs`, `sign`, `min`, `max`, `floor`, `ceil`, `round`,
14
- * `trunc`, `sqrt`, `imul`, `fround`, `+ - * /`, and `x ** 2`: they are
15
- * already exact everywhere. Use `Random` for randomness and `Clock` for time.
16
- * Code that only draws (rendering, effects) can use `Math` freely. The
17
- * `ritmo/use-ops-for-math` rule (`@typeonce/oxlint-plugin-ritmo`) points
18
- * simulation code here.
19
- *
20
- * @example
21
- * ```ts
22
- * // Inside a system: aim, then move along the heading.
23
- * const heading = Ops.atan2(target.y - position.y, target.x - position.x)
24
- * const step = { x: Ops.cos(heading) * speed * dt, y: Ops.sin(heading) * speed * dt }
25
- * const damping = Ops.exp(-friction * dt)
26
- * ```
27
- *
28
- * @module Ops
29
- * @docGroup helpers
30
- *
31
- * @categoryDescription Trigonometry
32
- * Sine, cosine, tangent, and their inverses, in radians.
33
- *
34
- * @categoryDescription Exponentials
35
- * Exponentials, logarithms, powers, and roots.
36
- *
37
- * @categoryDescription Hyperbolic
38
- * Hyperbolic functions and their inverses.
39
- *
40
- * @categoryDescription Lengths
41
- * Euclidean length without overflow.
42
- */
43
- import * as fdlibm from "./internal/fdlibm.js";
44
- /**
45
- * Sine of `x` radians. Same bits on every engine (within 1 ulp of the exact
46
- * value); use instead of `Math.sin` in simulation code.
47
- *
48
- * @category Trigonometry
49
- */
50
- export const sin = fdlibm.sin;
51
- /**
52
- * Cosine of `x` radians. Same bits on every engine (within 1 ulp of the
53
- * exact value); use instead of `Math.cos` in simulation code.
54
- *
55
- * @category Trigonometry
56
- */
57
- export const cos = fdlibm.cos;
58
- /**
59
- * Tangent of `x` radians. Same bits on every engine (within 1 ulp of the
60
- * exact value); use instead of `Math.tan` in simulation code.
61
- *
62
- * @category Trigonometry
63
- */
64
- export const tan = fdlibm.tan;
65
- /**
66
- * Arcsine of `x` in radians, in [-π/2, π/2]; NaN outside [-1, 1]. Same bits
67
- * on every engine; use instead of `Math.asin` in simulation code.
68
- *
69
- * @category Trigonometry
70
- */
71
- export const asin = fdlibm.asin;
72
- /**
73
- * Arccosine of `x` in radians, in [0, π]; NaN outside [-1, 1]. Same bits on
74
- * every engine; use instead of `Math.acos` in simulation code.
75
- *
76
- * @category Trigonometry
77
- */
78
- export const acos = fdlibm.acos;
79
- /**
80
- * Arctangent of `x` in radians, in (-π/2, π/2). Same bits on every engine;
81
- * use instead of `Math.atan` in simulation code. For the angle of a vector,
82
- * use `atan2`.
83
- *
84
- * @category Trigonometry
85
- */
86
- export const atan = fdlibm.atan;
87
- /**
88
- * The angle of the vector (x, y) in radians, in [-π, π] (note the argument
89
- * order: `y` first, like `Math.atan2`). Same bits on every engine; use
90
- * instead of `Math.atan2` in simulation code.
91
- *
92
- * @category Trigonometry
93
- */
94
- export const atan2 = fdlibm.atan2;
95
- /**
96
- * e raised to `x`. Same bits on every engine (within 1 ulp of the exact
97
- * value); use instead of `Math.exp` in simulation code, for example for
98
- * frame-rate independent damping `exp(-rate * dt)`.
99
- *
100
- * @category Exponentials
101
- */
102
- export const exp = fdlibm.exp;
103
- /**
104
- * Hyperbolic tangent of `x`, in [-1, 1]. Same bits on every engine (within 2
105
- * ulp of the exact value, like the native one); use instead of `Math.tanh` in
106
- * simulation code.
107
- *
108
- * @category Hyperbolic
109
- */
110
- export const tanh = fdlibm.tanh;
111
- /**
112
- * e raised to `x`, minus 1, accurate for `x` near 0 (where `exp(x) - 1` loses
113
- * digits). Same bits on every engine; use instead of `Math.expm1` in
114
- * simulation code.
115
- *
116
- * @category Exponentials
117
- */
118
- export const expm1 = fdlibm.expm1;
119
- /**
120
- * Natural logarithm of `x`: -Infinity at 0, NaN below 0. Same bits on every
121
- * engine (within 1 ulp of the exact value); use instead of `Math.log` in
122
- * simulation code.
123
- *
124
- * @category Exponentials
125
- */
126
- export const log = fdlibm.log;
127
- /**
128
- * Base-2 logarithm of `x`: -Infinity at 0, NaN below 0, exact for powers of
129
- * two. Same bits on every engine; use instead of `Math.log2` in simulation
130
- * code.
131
- *
132
- * @category Exponentials
133
- */
134
- export const log2 = fdlibm.log2;
135
- /**
136
- * Base-10 logarithm of `x`: -Infinity at 0, NaN below 0. Same bits on every
137
- * engine; use instead of `Math.log10` in simulation code.
138
- *
139
- * @category Exponentials
140
- */
141
- export const log10 = fdlibm.log10;
142
- /**
143
- * Natural logarithm of `1 + x`, accurate for `x` near 0 (where `log(1 + x)`
144
- * loses digits). Same bits on every engine; use instead of `Math.log1p` in
145
- * simulation code.
146
- *
147
- * @category Exponentials
148
- */
149
- export const log1p = fdlibm.log1p;
150
- /**
151
- * Cube root of `x`, negative for negative `x`. Same bits on every engine;
152
- * use instead of `Math.cbrt` and `x ** (1 / 3)` in simulation code.
153
- *
154
- * @category Exponentials
155
- */
156
- export const cbrt = fdlibm.cbrt;
157
- /**
158
- * `base` raised to `exponent`, with the results of `base ** exponent` for
159
- * every special case (NaN, zeros, infinities, negative bases). Same bits on
160
- * every engine (within 1 ulp of the exact value); use instead of `Math.pow`
161
- * and `**` in simulation code. `x * x` and `x ** 2` are already exact.
162
- *
163
- * @category Exponentials
164
- */
165
- export const pow = fdlibm.pow;
166
- /**
167
- * Hyperbolic sine of `x`. Same bits on every engine (within 1 ulp of the
168
- * exact value); use instead of `Math.sinh` in simulation code.
169
- *
170
- * @category Hyperbolic
171
- */
172
- export const sinh = fdlibm.sinh;
173
- /**
174
- * Hyperbolic cosine of `x`, at least 1. Same bits on every engine (within 1
175
- * ulp of the exact value); use instead of `Math.cosh` in simulation code.
176
- *
177
- * @category Hyperbolic
178
- */
179
- export const cosh = fdlibm.cosh;
180
- /**
181
- * Inverse hyperbolic sine of `x`. Same bits on every engine; use instead of
182
- * `Math.asinh` in simulation code.
183
- *
184
- * @category Hyperbolic
185
- */
186
- export const asinh = fdlibm.asinh;
187
- /**
188
- * Inverse hyperbolic cosine of `x`: NaN below 1. Same bits on every engine;
189
- * use instead of `Math.acosh` in simulation code.
190
- *
191
- * @category Hyperbolic
192
- */
193
- export const acosh = fdlibm.acosh;
194
- /**
195
- * Inverse hyperbolic tangent of `x`: ±Infinity at ±1, NaN beyond. Same bits
196
- * on every engine; use instead of `Math.atanh` in simulation code.
197
- *
198
- * @category Hyperbolic
199
- */
200
- export const atanh = fdlibm.atanh;
201
- /**
202
- * The length of the vector (x, y), `sqrt(x² + y²)` without overflow or
203
- * underflow. Same bits on every engine (within 1 ulp of the exact value);
204
- * use instead of `Math.hypot` in simulation code. Takes exactly two numbers;
205
- * for vectors use `Vec2.length` and `Vec2.distance`.
206
- *
207
- * @category Lengths
208
- */
209
- export const hypot = fdlibm.hypot;
210
- //# sourceMappingURL=Ops.js.map
package/dist/Ops.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Ops.js","sourceRoot":"","sources":["../src/Ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAA0B,MAAM,CAAC,GAAG,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAA0B,MAAM,CAAC,GAAG,C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