@woosh/meep-engine 2.121.4 → 2.121.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.121.4",
8
+ "version": "2.121.6",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  *
3
- * @param {number} x0
4
- * @param {number} y0
5
- * @param {number} x1
6
- * @param {number} y1
7
- * @returns {number}
3
+ * @param {number} x0 first vector X
4
+ * @param {number} y0 first vector Y
5
+ * @param {number} x1 second vector X
6
+ * @param {number} y1 second vector Y
7
+ * @returns {number} in radians
8
8
  */
9
9
  export function v2_angle_between(x0: number, y0: number, x1: number, y1: number): number;
10
10
  //# sourceMappingURL=v2_angle_between.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"v2_angle_between.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec2/v2_angle_between.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CASlB"}
1
+ {"version":3,"file":"v2_angle_between.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec2/v2_angle_between.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAkBlB"}
@@ -4,15 +4,24 @@ import { v2_length } from "./v2_length.js";
4
4
 
5
5
  /**
6
6
  *
7
- * @param {number} x0
8
- * @param {number} y0
9
- * @param {number} x1
10
- * @param {number} y1
11
- * @returns {number}
7
+ * @param {number} x0 first vector X
8
+ * @param {number} y0 first vector Y
9
+ * @param {number} x1 second vector X
10
+ * @param {number} y1 second vector Y
11
+ * @returns {number} in radians
12
12
  */
13
13
  export function v2_angle_between(x0, y0, x1, y1) {
14
14
  const d = v2_dot(x0, y0, x1, y1);
15
- const l = v2_length(x0, y0) * v2_length(x1, y1);
15
+
16
+ const magnitude_0 = v2_length(x0, y0);
17
+ const magnitude_1 = v2_length(x1, y1);
18
+
19
+ const l = magnitude_0 * magnitude_1;
20
+
21
+ if (l === 0) {
22
+ // collective magnitude is 0, provide arbitrary result to avoid division by 0
23
+ return 0;
24
+ }
16
25
 
17
26
  const theta = clamp(d / l, -1, 1);
18
27
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * Vector DOT product in 2D
3
3
  * @param {number} x0
4
4
  * @param {number} y0
5
5
  * @param {number} x1
@@ -1,7 +1,7 @@
1
1
  import { assert } from "../../assert.js";
2
2
 
3
3
  /**
4
- *
4
+ * Vector DOT product in 2D
5
5
  * @param {number} x0
6
6
  * @param {number} y0
7
7
  * @param {number} x1
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Decomposes a floating-point number into a normalized fraction and an integer power of 2.
3
+ * Similar to C's frexp function.
4
+ * @param {number} value - The floating-point number to decompose
5
+ * @param {number[]} exponent where to write exponent to
6
+ * @param {number} [offset_into_exponent]
7
+ * @returns {number} mantissa
8
+ */
9
+ export function frexp(value: number, exponent: number[], offset_into_exponent?: number): number;
10
+ //# sourceMappingURL=frexp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frexp.d.ts","sourceRoot":"","sources":["../../../../src/core/math/frexp.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,6BALW,MAAM,YACN,MAAM,EAAE,yBACR,MAAM,GACJ,MAAM,CAqClB"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Decomposes a floating-point number into a normalized fraction and an integer power of 2.
3
+ * Similar to C's frexp function.
4
+ * @param {number} value - The floating-point number to decompose
5
+ * @param {number[]} exponent where to write exponent to
6
+ * @param {number} [offset_into_exponent]
7
+ * @returns {number} mantissa
8
+ */
9
+ export function frexp(value, exponent, offset_into_exponent = 0) {
10
+ if (value === 0 || Number.isFinite(value) === false) {
11
+ exponent[offset_into_exponent] = 0;
12
+ return value;
13
+ }
14
+
15
+ let abs_value = Math.abs(value);
16
+
17
+ // Get the exponent using Math.log2 and floor it
18
+ let exp = Math.max(
19
+ -1023,
20
+ Math.floor(Math.log2(abs_value)) + 1
21
+ );
22
+
23
+ // Calculate the mantissa by dividing by 2^exp
24
+ let mantissa = abs_value * Math.pow(2, -exp);
25
+
26
+ // These while loops compensate for rounding errors that sometimes occur because of ECMAScript's Math.log2's undefined precision
27
+ // and also works around the issue of Math.pow(2, -exp) === Infinity when exp <= -1024
28
+ while (mantissa < 0.5) {
29
+ mantissa *= 2;
30
+ exp--;
31
+ }
32
+ while (mantissa >= 1) {
33
+ mantissa *= 0.5;
34
+ exp++;
35
+ }
36
+
37
+ if (value < 0) {
38
+ mantissa = -mantissa;
39
+ }
40
+
41
+ exponent[offset_into_exponent] = exp;
42
+
43
+ return mantissa;
44
+ }