@benev/math 0.2.0-4 → 0.3.0-2

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 (165) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -3
  3. package/package.json +5 -5
  4. package/s/{tools → core}/circular.ts +1 -1
  5. package/s/core/quat.ts +12 -8
  6. package/s/{tools → core}/scalar.ts +2 -2
  7. package/s/core/vec2.ts +24 -20
  8. package/s/core/vec3.ts +24 -20
  9. package/s/core/vec4.ts +6 -2
  10. package/s/index.ts +5 -10
  11. package/s/optimizers/hash-map.ts +2 -2
  12. package/s/optimizers/zen.ts +4 -4
  13. package/s/physics/2d/collide2d.barrel.ts +3 -0
  14. package/s/physics/2d/collide2d.ts +2 -2
  15. package/s/physics/2d/intersect2d.barrel.ts +3 -0
  16. package/s/physics/2d/intersect2d.ts +11 -11
  17. package/s/physics/index.ts +4 -0
  18. package/s/shapes/2d/circle.ts +3 -3
  19. package/s/shapes/2d/rect.ts +7 -7
  20. package/s/shapes/3d/box.ts +10 -10
  21. package/s/shapes/3d/segment.ts +8 -8
  22. package/s/shapes/index.ts +7 -0
  23. package/s/tools/angles.ts +26 -26
  24. package/s/tools/make-noise.ts +13 -0
  25. package/s/tools/spline.ts +30 -36
  26. package/x/concepts/angles.d.ts +29 -0
  27. package/x/concepts/angles.js +62 -0
  28. package/x/concepts/angles.js.map +1 -0
  29. package/x/concepts/circular.d.ts +17 -0
  30. package/x/concepts/circular.js +70 -0
  31. package/x/concepts/circular.js.map +1 -0
  32. package/x/concepts/noise.d.ts +9 -0
  33. package/x/concepts/noise.js +20 -0
  34. package/x/concepts/noise.js.map +1 -0
  35. package/x/concepts/quat.d.ts +35 -0
  36. package/x/concepts/quat.js +110 -0
  37. package/x/concepts/quat.js.map +1 -0
  38. package/x/concepts/randy.d.ts +39 -0
  39. package/x/concepts/randy.js +95 -0
  40. package/x/concepts/randy.js.map +1 -0
  41. package/x/concepts/scalar.d.ts +51 -0
  42. package/x/concepts/scalar.js +219 -0
  43. package/x/concepts/scalar.js.map +1 -0
  44. package/x/concepts/spline.d.ts +9 -0
  45. package/x/concepts/spline.js +59 -0
  46. package/x/concepts/spline.js.map +1 -0
  47. package/x/concepts/vec2.d.ts +114 -0
  48. package/x/concepts/vec2.js +314 -0
  49. package/x/concepts/vec2.js.map +1 -0
  50. package/x/concepts/vec3.d.ts +117 -0
  51. package/x/concepts/vec3.js +357 -0
  52. package/x/concepts/vec3.js.map +1 -0
  53. package/x/concepts/vec4.d.ts +21 -0
  54. package/x/concepts/vec4.js +62 -0
  55. package/x/concepts/vec4.js.map +1 -0
  56. package/x/core/circular.d.ts +17 -0
  57. package/x/core/circular.js +71 -0
  58. package/x/core/circular.js.map +1 -0
  59. package/x/core/quat.d.ts +4 -3
  60. package/x/core/quat.js +11 -8
  61. package/x/core/quat.js.map +1 -1
  62. package/x/core/scalar.d.ts +51 -0
  63. package/x/core/scalar.js +219 -0
  64. package/x/core/scalar.js.map +1 -0
  65. package/x/core/vec2.d.ts +11 -10
  66. package/x/core/vec2.js +23 -20
  67. package/x/core/vec2.js.map +1 -1
  68. package/x/core/vec3.d.ts +11 -10
  69. package/x/core/vec3.js +23 -20
  70. package/x/core/vec3.js.map +1 -1
  71. package/x/core/vec4.d.ts +2 -1
  72. package/x/core/vec4.js +5 -2
  73. package/x/core/vec4.js.map +1 -1
  74. package/x/helpers/angles.d.ts +19 -0
  75. package/x/helpers/angles.js +41 -0
  76. package/x/helpers/angles.js.map +1 -0
  77. package/x/helpers/circular.d.ts +17 -0
  78. package/x/helpers/circular.js +71 -0
  79. package/x/helpers/circular.js.map +1 -0
  80. package/x/helpers/noise.d.ts +9 -0
  81. package/x/helpers/noise.js +20 -0
  82. package/x/helpers/noise.js.map +1 -0
  83. package/x/helpers/randy.d.ts +31 -0
  84. package/x/helpers/randy.js +85 -0
  85. package/x/helpers/randy.js.map +1 -0
  86. package/x/helpers/scalar.d.ts +51 -0
  87. package/x/helpers/scalar.js +219 -0
  88. package/x/helpers/scalar.js.map +1 -0
  89. package/x/helpers/spline.d.ts +9 -0
  90. package/x/helpers/spline.js +61 -0
  91. package/x/helpers/spline.js.map +1 -0
  92. package/x/importmap.json +7 -0
  93. package/x/index.d.ts +4 -10
  94. package/x/index.js +4 -10
  95. package/x/index.js.map +1 -1
  96. package/x/optimizers/hash-map.js +2 -2
  97. package/x/optimizers/zen.js +4 -4
  98. package/x/optimizers/zen.js.map +1 -1
  99. package/x/physics/2d/collide2d.barrel.d.ts +1 -0
  100. package/x/physics/2d/collide2d.barrel.js +2 -0
  101. package/x/physics/2d/collide2d.barrel.js.map +1 -0
  102. package/x/physics/2d/collide2d.js +2 -2
  103. package/x/physics/2d/collide2d.js.map +1 -1
  104. package/x/physics/2d/intersect2d.barrel.d.ts +1 -0
  105. package/x/physics/2d/intersect2d.barrel.js +2 -0
  106. package/x/physics/2d/intersect2d.barrel.js.map +1 -0
  107. package/x/physics/2d/intersect2d.d.ts +3 -3
  108. package/x/physics/2d/intersect2d.js +11 -11
  109. package/x/physics/2d/intersect2d.js.map +1 -1
  110. package/x/physics/index.d.ts +2 -0
  111. package/x/physics/index.js +3 -0
  112. package/x/physics/index.js.map +1 -0
  113. package/x/primitives/circular.d.ts +17 -0
  114. package/x/primitives/circular.js +70 -0
  115. package/x/primitives/circular.js.map +1 -0
  116. package/x/primitives/quat.d.ts +35 -0
  117. package/x/primitives/quat.js +110 -0
  118. package/x/primitives/quat.js.map +1 -0
  119. package/x/primitives/scalar.d.ts +51 -0
  120. package/x/primitives/scalar.js +219 -0
  121. package/x/primitives/scalar.js.map +1 -0
  122. package/x/primitives/vec2.d.ts +114 -0
  123. package/x/primitives/vec2.js +319 -0
  124. package/x/primitives/vec2.js.map +1 -0
  125. package/x/primitives/vec3.d.ts +117 -0
  126. package/x/primitives/vec3.js +363 -0
  127. package/x/primitives/vec3.js.map +1 -0
  128. package/x/primitives/vec4.d.ts +21 -0
  129. package/x/primitives/vec4.js +62 -0
  130. package/x/primitives/vec4.js.map +1 -0
  131. package/x/shapes/2d/circle.js +3 -3
  132. package/x/shapes/2d/circle.js.map +1 -1
  133. package/x/shapes/2d/rect.js +7 -7
  134. package/x/shapes/2d/rect.js.map +1 -1
  135. package/x/shapes/3d/box.js +10 -10
  136. package/x/shapes/3d/box.js.map +1 -1
  137. package/x/shapes/3d/segment.js +7 -7
  138. package/x/shapes/3d/segment.js.map +1 -1
  139. package/x/shapes/index.d.ts +4 -0
  140. package/x/shapes/index.js +5 -0
  141. package/x/shapes/index.js.map +1 -0
  142. package/x/tools/angles.d.ts +22 -13
  143. package/x/tools/angles.js +27 -29
  144. package/x/tools/angles.js.map +1 -1
  145. package/x/tools/spline.d.ts +2 -4
  146. package/x/tools/spline.js +20 -26
  147. package/x/tools/spline.js.map +1 -1
  148. package/x/utils/angles.d.ts +19 -0
  149. package/x/utils/angles.js +41 -0
  150. package/x/utils/angles.js.map +1 -0
  151. package/x/utils/circular.d.ts +17 -0
  152. package/x/utils/circular.js +70 -0
  153. package/x/utils/circular.js.map +1 -0
  154. package/x/utils/noise.d.ts +9 -0
  155. package/x/utils/noise.js +20 -0
  156. package/x/utils/noise.js.map +1 -0
  157. package/x/utils/randy.d.ts +31 -0
  158. package/x/utils/randy.js +85 -0
  159. package/x/utils/randy.js.map +1 -0
  160. package/x/utils/scalar.d.ts +51 -0
  161. package/x/utils/scalar.js +219 -0
  162. package/x/utils/scalar.js.map +1 -0
  163. package/x/utils/spline.d.ts +9 -0
  164. package/x/utils/spline.js +61 -0
  165. package/x/utils/spline.js.map +1 -0
@@ -0,0 +1,70 @@
1
+ import { Scalar } from "./scalar.js";
2
+ export class Circular {
3
+ x;
4
+ constructor(x) {
5
+ this.x = x;
6
+ }
7
+ clone() {
8
+ return new Circular(this.x);
9
+ }
10
+ set(x) {
11
+ this.x = x;
12
+ return this;
13
+ }
14
+ static value(x) {
15
+ return typeof x === "number"
16
+ ? x
17
+ : x.x;
18
+ }
19
+ static normalize(x) {
20
+ return Scalar.wrap(x, 0, 2 * Math.PI);
21
+ }
22
+ normalize() {
23
+ this.x = Circular.normalize(this.x);
24
+ return this;
25
+ }
26
+ static difference(x, y) {
27
+ x = this.normalize(x);
28
+ y = this.normalize(y);
29
+ let delta = y - x;
30
+ if (delta > Math.PI)
31
+ delta -= 2 * Math.PI;
32
+ if (delta < -Math.PI)
33
+ delta += 2 * Math.PI;
34
+ return delta;
35
+ }
36
+ difference(y) {
37
+ return Circular.difference(this.x, Circular.value(y));
38
+ }
39
+ static lerp(x, y, fraction, max) {
40
+ const difference = this.difference(x, y);
41
+ let delta = difference * fraction;
42
+ if (max !== undefined && Math.abs(delta) > max)
43
+ delta = Math.sign(delta) * max;
44
+ return this.normalize(x + delta);
45
+ }
46
+ lerp(y, fraction, max) {
47
+ this.x = Circular.lerp(this.x, Circular.value(y), fraction, max);
48
+ return this;
49
+ }
50
+ static step(x, y, delta) {
51
+ const difference = this.difference(x, y);
52
+ return this.normalize(Math.abs(difference) <= delta
53
+ ? y
54
+ : x + (Math.sign(difference) * delta));
55
+ }
56
+ step(y, delta) {
57
+ this.x = Circular.step(this.x, Circular.value(y), delta);
58
+ return this;
59
+ }
60
+ static approach(x, y, speed, deltaTime, speedLimit) {
61
+ const difference = this.difference(x, y);
62
+ const change = Scalar.creep(difference, speed, deltaTime, speedLimit);
63
+ return this.normalize(x + change);
64
+ }
65
+ approach(y, speed, deltaTime, speedLimit) {
66
+ this.x = Circular.approach(this.x, Circular.value(y), speed, deltaTime, speedLimit);
67
+ return this;
68
+ }
69
+ }
70
+ //# sourceMappingURL=circular.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circular.js","sourceRoot":"","sources":["../../s/primitives/circular.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,MAAM,OAAO,QAAQ;IACD;IAAnB,YAAmB,CAAS;QAAT,MAAC,GAAD,CAAC,CAAQ;IAAG,CAAC;IAEhC,KAAK;QACJ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,CAAC,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,KAAa,EAAE,SAAiB,EAAE,UAAmB;QAC1F,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACxC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QACrE,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,CAAA;IAClC,CAAC;IAAC,QAAQ,CAAC,CAAoB,EAAE,KAAa,EAAE,SAAiB,EAAE,UAAmB;QACrF,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QACnF,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -0,0 +1,35 @@
1
+ import { Xyz } from "./vec3.js";
2
+ export type QuatArray = [number, number, number, number];
3
+ export type Xyzw = {
4
+ x: number;
5
+ y: number;
6
+ z: number;
7
+ w: number;
8
+ };
9
+ export declare class Quat {
10
+ x: number;
11
+ y: number;
12
+ z: number;
13
+ w: number;
14
+ constructor(x: number, y: number, z: number, w: number);
15
+ static new(x: number, y: number, z: number, w: number): Quat;
16
+ static identity(): Quat;
17
+ static array(q: QuatArray): Quat;
18
+ static import({ x, y, z, w }: Xyzw): Quat;
19
+ static from(q: QuatArray | Xyzw): Quat;
20
+ static rotate_(pitch: number, yaw: number, roll: number): Quat;
21
+ static rotate(vec: Xyz): Quat;
22
+ array(): QuatArray;
23
+ toString(): string;
24
+ clone(): Quat;
25
+ transform_(x: number, y: number, z: number, w: number, global?: boolean): Quat;
26
+ transform({ x, y, z, w }: Xyzw, global?: boolean): Quat;
27
+ rotate_(pitch: number, yaw: number, roll: number, global?: boolean): Quat;
28
+ rotate({ x: pitch, y: yaw, z: roll }: Xyz, global?: boolean): Quat;
29
+ rotateAroundAxis_(angle: number, axisX: number, axisY: number, axisZ: number, global?: boolean): Quat;
30
+ rotateAroundAxis(angle: number, axis: Xyz, global?: boolean): Quat;
31
+ set_(x: number, y: number, z: number, w: number): this;
32
+ set({ x, y, z, w }: Xyzw): this;
33
+ multiply_(x2: number, y2: number, z2: number, w2: number): Quat;
34
+ multiply(...quats: Quat[]): this;
35
+ }
@@ -0,0 +1,110 @@
1
+ export class Quat {
2
+ x;
3
+ y;
4
+ z;
5
+ w;
6
+ constructor(x, y, z, w) {
7
+ this.x = x;
8
+ this.y = y;
9
+ this.z = z;
10
+ this.w = w;
11
+ }
12
+ static new(x, y, z, w) {
13
+ return new this(x, y, z, w);
14
+ }
15
+ static identity() {
16
+ return new this(0, 0, 0, 1);
17
+ }
18
+ static array(q) {
19
+ return new this(...q);
20
+ }
21
+ static import({ x, y, z, w }) {
22
+ return new this(x, y, z, w);
23
+ }
24
+ static from(q) {
25
+ return Array.isArray(q)
26
+ ? this.array(q)
27
+ : this.import(q);
28
+ }
29
+ static rotate_(pitch, yaw, roll) {
30
+ return this.identity().rotate_(pitch, yaw, roll);
31
+ }
32
+ static rotate(vec) {
33
+ return this.identity().rotate(vec);
34
+ }
35
+ array() {
36
+ const { x, y, z, w } = this;
37
+ return [x, y, z, w];
38
+ }
39
+ toString() {
40
+ return `(Quat x${this.x.toFixed(2)}, y${this.y.toFixed(2)}, z${this.z.toFixed(2)}, w${this.w.toFixed(2)})`;
41
+ }
42
+ clone() {
43
+ return new Quat(...this.array());
44
+ }
45
+ transform_(x, y, z, w, global = false) {
46
+ if (global) {
47
+ const original = this.array();
48
+ return this.set_(x, y, z, w).multiply_(...original);
49
+ }
50
+ else {
51
+ return this.multiply_(x, y, z, w);
52
+ }
53
+ }
54
+ transform({ x, y, z, w }, global = false) {
55
+ return this.transform_(x, y, z, w, global);
56
+ }
57
+ rotate_(pitch, yaw, roll, global = false) {
58
+ const cx = Math.cos(pitch * 0.5), sx = Math.sin(pitch * 0.5);
59
+ const cy = Math.cos(yaw * 0.5), sy = Math.sin(yaw * 0.5);
60
+ const cz = Math.cos(roll * 0.5), sz = Math.sin(roll * 0.5);
61
+ const x = sx * cy * cz + cx * sy * sz;
62
+ const y = cx * sy * cz - sx * cy * sz;
63
+ const z = cx * cy * sz + sx * sy * cz;
64
+ const w = cx * cy * cz - sx * sy * sz;
65
+ return this.transform_(x, y, z, w, global);
66
+ }
67
+ rotate({ x: pitch, y: yaw, z: roll }, global = false) {
68
+ return this.rotate_(pitch, yaw, roll, global);
69
+ }
70
+ rotateAroundAxis_(angle, axisX, axisY, axisZ, global = false) {
71
+ const halfAngle = angle * 0.5;
72
+ const sinHalf = Math.sin(halfAngle);
73
+ const x = axisX * sinHalf;
74
+ const y = axisY * sinHalf;
75
+ const z = axisZ * sinHalf;
76
+ const w = Math.cos(halfAngle);
77
+ return this.transform_(x, y, z, w, global);
78
+ }
79
+ rotateAroundAxis(angle, axis, global = false) {
80
+ return this.rotateAroundAxis_(angle, axis.x, axis.y, axis.z, global);
81
+ }
82
+ set_(x, y, z, w) {
83
+ this.x = x;
84
+ this.y = y;
85
+ this.z = z;
86
+ this.w = w;
87
+ return this;
88
+ }
89
+ set({ x, y, z, w }) {
90
+ this.x = x;
91
+ this.y = y;
92
+ this.z = z;
93
+ this.w = w;
94
+ return this;
95
+ }
96
+ multiply_(x2, y2, z2, w2) {
97
+ const { x, y, z, w } = this;
98
+ this.x = w * x2 + x * w2 + y * z2 - z * y2;
99
+ this.y = w * y2 - x * z2 + y * w2 + z * x2;
100
+ this.z = w * z2 + x * y2 - y * x2 + z * w2;
101
+ this.w = w * w2 - x * x2 - y * y2 - z * z2;
102
+ return this;
103
+ }
104
+ multiply(...quats) {
105
+ for (const { x, y, z, w } of quats)
106
+ this.multiply_(x, y, z, w);
107
+ return this;
108
+ }
109
+ }
110
+ //# sourceMappingURL=quat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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QACV,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACV,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,SAAS,CAAC,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU;QACvD,MAAM,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAC,GAAG,IAAI,CAAA;QACzB,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAA;QAC1C,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,QAAQ,CAAC,GAAG,KAAa;QACxB,KAAK,MAAM,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAC,IAAI,KAAK;YAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAC5D,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -0,0 +1,51 @@
1
+ export declare class Scalar {
2
+ x: number;
3
+ constructor(x: number);
4
+ static new(x: number): Scalar;
5
+ clone(): Scalar;
6
+ set(x: number): this;
7
+ static isBetween(x: number, a?: number, b?: number): boolean;
8
+ isBetween(a?: number, b?: number): boolean;
9
+ static isNear(x: number, y: number, epsilon?: number): boolean;
10
+ isNear(y: number, epsilon?: number): boolean;
11
+ static add(...nums: number[]): number;
12
+ add(...nums: number[]): this;
13
+ subtract(...nums: number[]): this;
14
+ static min(x: number, minimum?: number): number;
15
+ min(minimum?: number): this;
16
+ static max(x: number, maximum?: number): number;
17
+ max(maximum?: number): this;
18
+ static clamp(x: number, a?: number, b?: number): number;
19
+ clamp(a?: number, b?: number): this;
20
+ static lerp(x: number, y: number, fraction: number, max?: number): number;
21
+ lerp(y: number, fraction: number, max?: number): this;
22
+ static step(x: number, y: number, delta: number): number;
23
+ step(y: number, delta: number): this;
24
+ static creep(difference: number, speed: number, deltaTime: number, speedLimit?: number): number;
25
+ static approach(x: number, y: number, speed: number, deltaTime: number, speedLimit?: number): number;
26
+ approach(y: number, speed: number, deltaTime: number, speedLimit?: number): this;
27
+ static wrap(x: number, a?: number, b?: number): number;
28
+ wrap(a?: number, b?: number): this;
29
+ static constrainProximity(x: number, y: number, range: number): number;
30
+ constrainProximity(y: number, range: number): this;
31
+ static inverse(x: number): number;
32
+ inverse(): this;
33
+ static center(x: number): number;
34
+ center(): this;
35
+ static uncenter(x: number): number;
36
+ uncenter(): this;
37
+ static map(x: number, a: number, b: number): number;
38
+ map(a: number, b: number): this;
39
+ static remap(x: number, a1: number, a2: number, b1?: number, b2?: number, clamp?: boolean): number;
40
+ remap(a1: number, a2: number, b1?: number, b2?: number, clamp?: boolean): this;
41
+ static magnify(x: number): number;
42
+ magnify(): this;
43
+ static floor(x: number): number;
44
+ floor(): this;
45
+ static ceil(x: number): number;
46
+ ceil(): this;
47
+ static round(x: number): number;
48
+ round(): this;
49
+ static smooth(x: number, y: number, smoothing: number): number;
50
+ smooth(y: number, smoothing: number): this;
51
+ }
@@ -0,0 +1,219 @@
1
+ export class Scalar {
2
+ x;
3
+ constructor(x) {
4
+ this.x = x;
5
+ }
6
+ static new(x) {
7
+ return new this(x);
8
+ }
9
+ clone() {
10
+ return new Scalar(this.x);
11
+ }
12
+ set(x) {
13
+ this.x = x;
14
+ return this;
15
+ }
16
+ //
17
+ // queries
18
+ //
19
+ static isBetween(x, a = 0, b = 1) {
20
+ const min = Math.min(a, b);
21
+ const max = Math.max(a, b);
22
+ return (x >= min) && (x <= max);
23
+ }
24
+ isBetween(a = 0, b = 1) {
25
+ return Scalar.isBetween(this.x, a, b);
26
+ }
27
+ static isNear(x, y, epsilon = 0.01) {
28
+ return Math.abs(x - y) <= epsilon;
29
+ }
30
+ isNear(y, epsilon = 0.01) {
31
+ return Scalar.isNear(this.x, y, epsilon);
32
+ }
33
+ //
34
+ // chainable transforms
35
+ //
36
+ static add(...nums) {
37
+ let x = 0;
38
+ for (const n of nums)
39
+ x += n;
40
+ return x;
41
+ }
42
+ add(...nums) {
43
+ this.x = Scalar.add(...nums);
44
+ return this;
45
+ }
46
+ subtract(...nums) {
47
+ for (const n of nums)
48
+ this.x -= n;
49
+ return this;
50
+ }
51
+ static min(x, minimum = 0) {
52
+ return Math.max(x, minimum);
53
+ }
54
+ min(minimum = 0) {
55
+ this.x = Scalar.min(this.x, minimum);
56
+ return this;
57
+ }
58
+ static max(x, maximum = 1) {
59
+ return Math.min(x, maximum);
60
+ }
61
+ max(maximum = 1) {
62
+ this.x = Scalar.max(this.x, maximum);
63
+ return this;
64
+ }
65
+ static clamp(x, a = 0, b = 1) {
66
+ x = Scalar.min(x, Math.min(a, b));
67
+ x = Scalar.max(x, Math.max(a, b));
68
+ return x;
69
+ }
70
+ clamp(a = 0, b = 1) {
71
+ this.x = Scalar.clamp(this.x, a, b);
72
+ return this;
73
+ }
74
+ static lerp(x, y, fraction, max) {
75
+ const difference = y - x;
76
+ let delta = difference * fraction;
77
+ if (max !== undefined && Math.abs(delta) > max)
78
+ delta = Math.sign(delta) * max;
79
+ return x + delta;
80
+ }
81
+ lerp(y, fraction, max) {
82
+ this.x = Scalar.lerp(this.x, y, fraction, max);
83
+ return this;
84
+ }
85
+ static step(x, y, delta) {
86
+ const difference = y - x;
87
+ return (Math.abs(difference) <= delta)
88
+ ? y
89
+ : x + (Math.sign(difference) * delta);
90
+ }
91
+ step(y, delta) {
92
+ this.x = Scalar.step(this.x, y, delta);
93
+ return this;
94
+ }
95
+ static creep(difference, speed, deltaTime, speedLimit) {
96
+ let change = (difference * (1 - Math.exp(-speed * deltaTime)));
97
+ if (speedLimit !== undefined) {
98
+ const changeLimit = speedLimit * deltaTime;
99
+ if (Math.abs(change) > changeLimit)
100
+ change = Math.sign(change) * changeLimit;
101
+ }
102
+ return change;
103
+ }
104
+ static approach(x, y, speed, deltaTime, speedLimit) {
105
+ const difference = y - x;
106
+ const change = this.creep(difference, speed, deltaTime, speedLimit);
107
+ return x + change;
108
+ }
109
+ approach(y, speed, deltaTime, speedLimit) {
110
+ this.x = Scalar.approach(this.x, y, speed, deltaTime, speedLimit);
111
+ return this;
112
+ }
113
+ static wrap(x, a = 0, b = 1) {
114
+ const min = Math.min(a, b);
115
+ const max = Math.max(a, b);
116
+ const span = max - min;
117
+ const adjusted = x - min;
118
+ const wrapped = (adjusted < 0)
119
+ ? span - (-adjusted % span)
120
+ : adjusted % span;
121
+ return min + wrapped;
122
+ }
123
+ wrap(a = 0, b = 1) {
124
+ this.x = Scalar.wrap(this.x, a, b);
125
+ return this;
126
+ }
127
+ static constrainProximity(x, y, range) {
128
+ const trueDiff = y - x;
129
+ const positiveDiff = Math.abs(trueDiff);
130
+ const cappedDiff = (positiveDiff > range)
131
+ ? range
132
+ : positiveDiff;
133
+ const newDiff = (trueDiff < 0) ? -cappedDiff : cappedDiff;
134
+ return x + newDiff;
135
+ }
136
+ constrainProximity(y, range) {
137
+ this.x = Scalar.constrainProximity(this.x, y, range);
138
+ return this;
139
+ }
140
+ static inverse(x) {
141
+ return 1 - x;
142
+ }
143
+ inverse() {
144
+ this.x = Scalar.inverse(this.x);
145
+ return this;
146
+ }
147
+ static center(x) {
148
+ return (x * 2) - 1;
149
+ }
150
+ center() {
151
+ this.x = Scalar.center(this.x);
152
+ return this;
153
+ }
154
+ static uncenter(x) {
155
+ return (x + 1) / 2;
156
+ }
157
+ uncenter() {
158
+ this.x = Scalar.uncenter(this.x);
159
+ return this;
160
+ }
161
+ static map(x, a, b) {
162
+ const difference = b - a;
163
+ const value = difference * x;
164
+ return a + value;
165
+ }
166
+ map(a, b) {
167
+ this.x = Scalar.map(this.x, a, b);
168
+ return this;
169
+ }
170
+ static remap(x, a1, a2, b1 = 0, b2 = 1, clamp = false) {
171
+ const fraction = (x - a1) / (a2 - a1);
172
+ const result = (fraction * (b2 - b1)) + b1;
173
+ return clamp
174
+ ? Scalar.clamp(result, b1, b2)
175
+ : result;
176
+ }
177
+ remap(a1, a2, b1 = 0, b2 = 1, clamp = false) {
178
+ this.x = Scalar.remap(this.x, a1, a2, b1, b2, clamp);
179
+ return this;
180
+ }
181
+ static magnify(x) {
182
+ return 4 * Math.pow(x - 0.5, 3) + 0.5;
183
+ }
184
+ magnify() {
185
+ this.x = Scalar.magnify(this.x);
186
+ return this;
187
+ }
188
+ static floor(x) {
189
+ return Math.floor(x);
190
+ }
191
+ floor() {
192
+ this.x = Scalar.floor(this.x);
193
+ return this;
194
+ }
195
+ static ceil(x) {
196
+ return Math.ceil(x);
197
+ }
198
+ ceil() {
199
+ this.x = Scalar.ceil(this.x);
200
+ return this;
201
+ }
202
+ static round(x) {
203
+ return Math.round(x);
204
+ }
205
+ round() {
206
+ this.x = Scalar.round(this.x);
207
+ return this;
208
+ }
209
+ static smooth(x, y, smoothing) {
210
+ return smoothing <= 1
211
+ ? y
212
+ : x + ((y - x) / smoothing);
213
+ }
214
+ smooth(y, smoothing) {
215
+ this.x = Scalar.smooth(this.x, y, smoothing);
216
+ return this;
217
+ }
218
+ }
219
+ //# sourceMappingURL=scalar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.js","sourceRoot":"","sources":["../../s/primitives/scalar.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,MAAM;IACC;IAAnB,YAAmB,CAAS;QAAT,MAA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ACpB,CAAC;IAAC,IAAI;QACL,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,CAAS;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACrB,CAAC;IAAC,KAAK;QACN,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC7B,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,SAAiB;QACpD,OAAO,SAAS,IAAI,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IAC7B,CAAC;IAAC,MAAM,CAAC,CAAS,EAAE,SAAiB;QACpC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;QAC5C,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -0,0 +1,114 @@
1
+ export type Vec2Array = [number, number];
2
+ export type Xy = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ /** https://github.com/microsoft/TypeScript/issues/5863 */
7
+ type TsHack<T> = {
8
+ new (...a: ConstructorParameters<typeof Vec2>): T;
9
+ };
10
+ export declare class Vec2 implements Xy {
11
+ x: number;
12
+ y: number;
13
+ constructor(x: number, y: number);
14
+ static new<T extends Vec2>(this: TsHack<T>, x: number, y: number): T;
15
+ static zero<T extends Vec2>(this: TsHack<T>): T;
16
+ static all<T extends Vec2>(this: TsHack<T>, value: number): T;
17
+ static array<T extends Vec2>(this: TsHack<T>, v: Vec2Array): T;
18
+ static import<T extends Vec2>(this: TsHack<T>, { x, y }: Xy): T;
19
+ static from(v: Vec2Array | Xy): Vec2;
20
+ static magnitudeSquared(x: number, y: number): number;
21
+ static magnitude(x: number, y: number): number;
22
+ static average(...vectors: Xy[]): Vec2;
23
+ static min(...vecs: Vec2[]): Vec2;
24
+ static max(...vecs: Vec2[]): Vec2;
25
+ clone(): Vec2;
26
+ array(): Vec2Array;
27
+ toString(): string;
28
+ /** mutator */
29
+ set_(x: number, y: number): this;
30
+ /** mutator */
31
+ set({ x, y }: Xy): this;
32
+ magnitudeSquared(): number;
33
+ magnitude(): number;
34
+ rotation(): number;
35
+ equals_(x: number, y: number): boolean;
36
+ equals(...vecs: Xy[]): boolean;
37
+ dot_(x: number, y: number): number;
38
+ dot({ x, y }: Xy): number;
39
+ distanceSquared_(x: number, y: number): number;
40
+ distanceSquared({ x, y }: Xy): number;
41
+ distance_(x: number, y: number): number;
42
+ distance({ x, y }: Xy): number;
43
+ angleBetween_(x: number, y: number): number;
44
+ angleBetween({ x, y }: Xy): number;
45
+ /** mutator */
46
+ normalize(): this;
47
+ /** mutator */
48
+ half(): this;
49
+ /** mutator */
50
+ double(): this;
51
+ /** mutator */
52
+ abs(): this;
53
+ /** mutator */
54
+ rotate(radians: number): this;
55
+ /** mutator */
56
+ perpendicular(): this;
57
+ /** mutator */
58
+ clampMagnitude(max: number): this;
59
+ /** mutator */
60
+ floor(): this;
61
+ /** mutator */
62
+ ceil(): this;
63
+ /** mutator */
64
+ round(): this;
65
+ /** mutator */
66
+ map(fn: (a: number, index: number) => number): this;
67
+ /** mutator */
68
+ clamp(min: number, max: number): this;
69
+ /** mutator */
70
+ negate(): this;
71
+ /** mutator */
72
+ addBy(delta: number): this;
73
+ /** mutator */
74
+ subtractBy(delta: number): this;
75
+ /** mutator */
76
+ multiplyBy(coefficient: number): this;
77
+ /** mutator */
78
+ divideBy(divisor: number): this;
79
+ /** mutator */
80
+ add_(x: number, y: number): this;
81
+ /** mutator */
82
+ add(...vecs: Xy[]): this;
83
+ /** mutator */
84
+ subtract_(x: number, y: number): this;
85
+ /** mutator */
86
+ subtract(...vecs: Xy[]): this;
87
+ /** mutator */
88
+ multiply_(x: number, y: number): this;
89
+ /** mutator */
90
+ multiply(...vecs: Xy[]): this;
91
+ /** mutator */
92
+ divide_(x: number, y: number): this;
93
+ /** mutator */
94
+ divide(...vecs: Xy[]): this;
95
+ /** mutator */
96
+ lerp_(x: number, y: number, fraction: number): this;
97
+ /** mutator */
98
+ lerp({ x, y }: Xy, fraction: number): this;
99
+ approach_(x: number, y: number, speed: number, deltaTime: number, speedLimit?: number): this;
100
+ approach({ x, y }: Xy, speed: number, deltaTime: number, speedLimit?: number): this;
101
+ /** mutator */
102
+ reflect_(x: number, y: number): this;
103
+ /** mutator */
104
+ reflect({ x, y }: Xy): this;
105
+ /** mutator */
106
+ rotateAroundPoint_(x: number, y: number, radians: number): this;
107
+ /** mutator */
108
+ rotateAroundPoint({ x, y }: Vec2, radians: number): this;
109
+ /** mutator */
110
+ smooth_(x: number, y: number, smoothing: number): this;
111
+ /** mutator */
112
+ smooth({ x, y }: Xy, smoothing: number): this;
113
+ }
114
+ export {};