@woosh/meep-engine 2.89.4 → 2.89.5

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 (24) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/2d/circle/Circle.js +2 -2
  3. package/src/core/geom/2d/circle/circle_compute_circle_intersection.d.ts +14 -0
  4. package/src/core/geom/2d/circle/circle_compute_circle_intersection.d.ts.map +1 -0
  5. package/src/core/geom/2d/circle/circle_compute_circle_intersection.js +64 -0
  6. package/src/core/geom/2d/circle/circle_compute_circle_intersection.spec.d.ts +2 -0
  7. package/src/core/geom/2d/circle/circle_compute_circle_intersection.spec.d.ts.map +1 -0
  8. package/src/core/geom/2d/circle/circle_compute_circle_intersection.spec.js +79 -0
  9. package/src/core/geom/2d/circle/{computeCircleCirclePenetrationDistance.d.ts → circle_compute_circle_penetration.d.ts} +2 -2
  10. package/src/core/geom/2d/circle/circle_compute_circle_penetration.d.ts.map +1 -0
  11. package/src/core/geom/2d/circle/{computeCircleCirclePenetrationDistance.js → circle_compute_circle_penetration.js} +6 -4
  12. package/src/core/geom/2d/circle/{circleIntersectsCircle.d.ts → circle_intersects_circle.d.ts} +2 -2
  13. package/src/core/geom/2d/circle/circle_intersects_circle.d.ts.map +1 -0
  14. package/src/core/geom/2d/circle/{circleIntersectsCircle.js → circle_intersects_circle.js} +1 -1
  15. package/src/core/geom/2d/circle/{circleIntersectsPoint.d.ts → circle_intersects_point.d.ts} +2 -2
  16. package/src/core/geom/2d/circle/circle_intersects_point.d.ts.map +1 -0
  17. package/src/core/geom/2d/circle/{circleIntersectsPoint.js → circle_intersects_point.js} +1 -1
  18. package/src/core/geom/2d/shape/CircleShape.js +4 -4
  19. package/src/core/geom/2d/shape/PointShape.js +2 -2
  20. package/src/generation/markers/MarkerNode.d.ts.map +1 -1
  21. package/src/generation/markers/MarkerNode.js +3 -3
  22. package/src/core/geom/2d/circle/circleIntersectsCircle.d.ts.map +0 -1
  23. package/src/core/geom/2d/circle/circleIntersectsPoint.d.ts.map +0 -1
  24. package/src/core/geom/2d/circle/computeCircleCirclePenetrationDistance.d.ts.map +0 -1
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.89.4",
8
+ "version": "2.89.5",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,4 +1,4 @@
1
- import { circleIntersectsCircle } from "./circleIntersectsCircle.js";
1
+ import { circle_intersects_circle } from "./circle_intersects_circle.js";
2
2
 
3
3
  /**
4
4
  * A circle or a 2-dimensional sphere. Represented as a position (x,y) and radius (r)
@@ -59,7 +59,7 @@ Circle.prototype.overlaps = function (other) {
59
59
  const y1 = other.y;
60
60
  const r1 = other.r;
61
61
 
62
- return circleIntersectsCircle(x0, y0, r0, x1, y1, r1);
62
+ return circle_intersects_circle(x0, y0, r0, x1, y1, r1);
63
63
  };
64
64
 
65
65
  /**
@@ -0,0 +1,14 @@
1
+ /**
2
+ *
3
+ * @param {number[]} result
4
+ * @param {number} result_offset
5
+ * @param {number} a_center_x
6
+ * @param {number} a_center_y
7
+ * @param {number} a_radius
8
+ * @param {number} b_center_x
9
+ * @param {number} b_center_y
10
+ * @param {number} b_radius
11
+ * @returns {boolean} if intersection exists, false otherwise
12
+ */
13
+ export function circle_compute_circle_intersection(result: number[], result_offset: number, a_center_x: number, a_center_y: number, a_radius: number, b_center_x: number, b_center_y: number, b_radius: number): boolean;
14
+ //# sourceMappingURL=circle_compute_circle_intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle_compute_circle_intersection.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circle_compute_circle_intersection.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,2DAVW,MAAM,EAAE,iBACR,MAAM,cACN,MAAM,cACN,MAAM,YACN,MAAM,cACN,MAAM,cACN,MAAM,YACN,MAAM,GACJ,OAAO,CAqDnB"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ *
3
+ * @param {number[]} result
4
+ * @param {number} result_offset
5
+ * @param {number} a_center_x
6
+ * @param {number} a_center_y
7
+ * @param {number} a_radius
8
+ * @param {number} b_center_x
9
+ * @param {number} b_center_y
10
+ * @param {number} b_radius
11
+ * @returns {boolean} if intersection exists, false otherwise
12
+ */
13
+ export function circle_compute_circle_intersection(
14
+ result,
15
+ result_offset,
16
+ a_center_x, a_center_y, a_radius,
17
+ b_center_x, b_center_y, b_radius
18
+ ) {
19
+
20
+ // see https://math.stackexchange.com/a/1033561
21
+
22
+ const abx = a_center_x - b_center_x;
23
+ const aby = a_center_y - b_center_y;
24
+
25
+ const d2 = abx * abx + aby * aby;
26
+
27
+ if (d2 === 0) {
28
+ // centers are at the same coordinate, no intersection possible except for full overlap
29
+ // Continuing would lead to division by 0, so we treat this as no-intersection
30
+ return false;
31
+ }
32
+
33
+ const d = Math.sqrt(d2);
34
+
35
+ if (d > a_radius + b_radius) {
36
+ // no intersection
37
+ return false;
38
+ }
39
+
40
+ if (d < Math.abs(a_radius - b_radius)) {
41
+ // one circle is fully within another
42
+ return false;
43
+ }
44
+
45
+ const a_radius2 = a_radius * a_radius;
46
+ const l = (a_radius2 - b_radius * b_radius + d * d) / (2 * d);
47
+ const h = Math.sqrt(a_radius2 - l * l)
48
+
49
+ const l_d = l / d;
50
+ const h_d = h / d;
51
+
52
+ const bax = b_center_x - a_center_x;
53
+ const bay = b_center_y - a_center_y;
54
+
55
+ // compute first root
56
+ result[result_offset] = l_d * bax + h_d * bay + a_center_x;
57
+ result[result_offset + 1] = l_d * bay - h_d * bax + a_center_y;
58
+
59
+ // second root
60
+ result[result_offset + 2] = l_d * bax - h_d * bay + a_center_x;
61
+ result[result_offset + 3] = l_d * bay + h_d * bax + a_center_y;
62
+
63
+ return true;
64
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=circle_compute_circle_intersection.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle_compute_circle_intersection.spec.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circle_compute_circle_intersection.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,79 @@
1
+ import { circle_compute_circle_intersection } from "./circle_compute_circle_intersection.js";
2
+
3
+ test("non-intersecting point circles", () => {
4
+ expect(
5
+ circle_compute_circle_intersection(
6
+ [], 0,
7
+ 0, 0, 0,
8
+ 1, 0, 0
9
+ )
10
+ ).toBe(false);
11
+
12
+ expect(
13
+ circle_compute_circle_intersection(
14
+ [], 0,
15
+ 1, 0, 0,
16
+ 0, 0, 0
17
+ )
18
+ ).toBe(false);
19
+
20
+ expect(
21
+ circle_compute_circle_intersection(
22
+ [], 0,
23
+ 0, 1, 0,
24
+ 0, 0, 0
25
+ )
26
+ ).toBe(false);
27
+
28
+ expect(
29
+ circle_compute_circle_intersection(
30
+ [], 0,
31
+ 0, 0, 0,
32
+ 0, 1, 0
33
+ )
34
+ ).toBe(false);
35
+ });
36
+
37
+ test("circle inside circle", () => {
38
+
39
+
40
+ expect(
41
+ circle_compute_circle_intersection(
42
+ [], 0,
43
+ 2, 3, 5,
44
+ 3, 4, 11
45
+ )
46
+ ).toBe(false);
47
+
48
+
49
+ });
50
+
51
+ test("touching case", () => {
52
+
53
+ const result = [];
54
+
55
+ expect(
56
+ circle_compute_circle_intersection(
57
+ result, 0,
58
+ 1, 3, 5,
59
+ 7, 3, 1
60
+ )
61
+ ).toBe(true);
62
+
63
+ expect(result).toEqual([6, 3, 6, 3]);
64
+ });
65
+
66
+ test("2 intersection points", () => {
67
+
68
+ const result = [];
69
+
70
+ expect(
71
+ circle_compute_circle_intersection(
72
+ result, 0,
73
+ -0.5, 0, 1,
74
+ 0.5, 0, 1
75
+ )
76
+ ).toBe(true);
77
+
78
+ expect(result).toEqual([0, -0.5 * Math.sqrt(3), 0, +0.5 * Math.sqrt(3)]);
79
+ });
@@ -8,5 +8,5 @@
8
8
  * @param {number} br Radius of second circle
9
9
  * @returns {number} positive value means that there is penetration, negative means that circles are separated
10
10
  */
11
- export function computeCircleCirclePenetrationDistance(ax: number, ay: number, ar: number, bx: number, by: number, br: number): number;
12
- //# sourceMappingURL=computeCircleCirclePenetrationDistance.d.ts.map
11
+ export function circle_compute_circle_penetration(ax: number, ay: number, ar: number, bx: number, by: number, br: number): number;
12
+ //# sourceMappingURL=circle_compute_circle_penetration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle_compute_circle_penetration.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circle_compute_circle_penetration.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,sDARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAuBlB"}
@@ -8,7 +8,11 @@
8
8
  * @param {number} br Radius of second circle
9
9
  * @returns {number} positive value means that there is penetration, negative means that circles are separated
10
10
  */
11
- export function computeCircleCirclePenetrationDistance(ax, ay, ar, bx, by, br) {
11
+ export function circle_compute_circle_penetration(
12
+ ax, ay, ar,
13
+ bx, by, br
14
+ ) {
15
+
12
16
  const dx = bx - ax;
13
17
  const dy = by - ax;
14
18
 
@@ -24,7 +28,5 @@ export function computeCircleCirclePenetrationDistance(ax, ay, ar, bx, by, br) {
24
28
  */
25
29
  const minSeparation = ar + br;
26
30
 
27
- const result = minSeparation - distance;
28
-
29
- return result;
31
+ return minSeparation - distance;
30
32
  }
@@ -8,5 +8,5 @@
8
8
  * @param {number} r1 Radius is second circle
9
9
  * @returns {boolean}
10
10
  */
11
- export function circleIntersectsCircle(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): boolean;
12
- //# sourceMappingURL=circleIntersectsCircle.d.ts.map
11
+ export function circle_intersects_circle(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): boolean;
12
+ //# sourceMappingURL=circle_intersects_circle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle_intersects_circle.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circle_intersects_circle.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,6CARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,OAAO,CAQnB"}
@@ -10,7 +10,7 @@ import { v2_distance } from "../../vec2/v2_distance.js";
10
10
  * @param {number} r1 Radius is second circle
11
11
  * @returns {boolean}
12
12
  */
13
- export function circleIntersectsCircle(x0, y0, r0, x1, y1, r1) {
13
+ export function circle_intersects_circle(x0, y0, r0, x1, y1, r1) {
14
14
  const minSeparation = r0 + r1;
15
15
 
16
16
  const distance = v2_distance(x0, y0, x1, y1);
@@ -7,5 +7,5 @@
7
7
  * @param {number} py Point coordinate Y
8
8
  * @returns {boolean}
9
9
  */
10
- export function circleIntersectsPoint(cx: number, cy: number, cr: number, px: number, py: number): boolean;
11
- //# sourceMappingURL=circleIntersectsPoint.d.ts.map
10
+ export function circle_intersects_point(cx: number, cy: number, cr: number, px: number, py: number): boolean;
11
+ //# sourceMappingURL=circle_intersects_point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle_intersects_point.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circle_intersects_point.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,4CAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,OAAO,CAMnB"}
@@ -9,7 +9,7 @@ import { v2_distance } from "../../vec2/v2_distance.js";
9
9
  * @param {number} py Point coordinate Y
10
10
  * @returns {boolean}
11
11
  */
12
- export function circleIntersectsPoint(cx, cy, cr, px, py) {
12
+ export function circle_intersects_point(cx, cy, cr, px, py) {
13
13
  const distance = v2_distance(cx, cx, px, py);
14
14
 
15
15
  return distance < cr;
@@ -1,5 +1,5 @@
1
- import { circleIntersectsCircle } from "../circle/circleIntersectsCircle.js";
2
- import { circleIntersectsPoint } from "../circle/circleIntersectsPoint.js";
1
+ import { circle_intersects_circle } from "../circle/circle_intersects_circle.js";
2
+ import { circle_intersects_point } from "../circle/circle_intersects_point.js";
3
3
  import { AbstractShape } from "./AbstractShape.js";
4
4
 
5
5
  export class CircleShape extends AbstractShape {
@@ -52,11 +52,11 @@ export class CircleShape extends AbstractShape {
52
52
  }
53
53
 
54
54
  intersectsPoint(x, y) {
55
- return circleIntersectsPoint(this.x, this.y, this.radius, x, y);
55
+ return circle_intersects_point(this.x, this.y, this.radius, x, y);
56
56
  }
57
57
 
58
58
  intersectsCircle(x, y, radius) {
59
- return circleIntersectsCircle(x, y, radius, this.x, this.y, this.radius);
59
+ return circle_intersects_circle(x, y, radius, this.x, this.y, this.radius);
60
60
  }
61
61
  }
62
62
 
@@ -1,4 +1,4 @@
1
- import { circleIntersectsPoint } from "../circle/circleIntersectsPoint.js";
1
+ import { circle_intersects_point } from "../circle/circle_intersects_point.js";
2
2
  import { AbstractShape } from "./AbstractShape.js";
3
3
 
4
4
  export class PointShape extends AbstractShape {
@@ -23,7 +23,7 @@ export class PointShape extends AbstractShape {
23
23
  }
24
24
 
25
25
  intersectsCircle(x, y, radius) {
26
- return circleIntersectsPoint(x, y, radius, this.x, this.y);
26
+ return circle_intersects_point(x, y, radius, this.x, this.y);
27
27
  }
28
28
  }
29
29
 
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerNode.d.ts","sourceRoot":"","sources":["../../../../src/generation/markers/MarkerNode.js"],"names":[],"mappings":"AAKA;IAEI;;;OAGG;IACH,UAFU,MAAM,CAEH;IAEb;;;OAGG;IACH,aAAY;IAEZ;;;OAGG;IACH,MAFU,QAAQ,CAER;IAEV;;;OAGG;IACH,UAFU,OAAO,CAEQ;IAEzB;;;OAGG;IACH,WAFU,SAAS,CAES;IAE5B;;;;OAIG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,gBAAgB;IAGhB;;;;OAIG;IACH,YAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;OAIG;IACH,iBAHW,MAAM,EAAE,GACN,OAAO,CAanB;IAED;;;OAGG;IACH,SAFa,UAAU,CAQtB;IAED;;;OAGG;IACH,YAFW,UAAU,QAcpB;IAED;;;;OAIG;IACH,gBAHW,UAAU,GACR,OAAO,CAOnB;IAIL;;;OAGG;IACH,uBAFU,OAAO,CAEgB;CANhC;oBAxHmB,4BAA4B;0BACtB,yCAAyC"}
1
+ {"version":3,"file":"MarkerNode.d.ts","sourceRoot":"","sources":["../../../../src/generation/markers/MarkerNode.js"],"names":[],"mappings":"AAKA;IAEI;;;OAGG;IACH,UAFU,MAAM,CAEH;IAEb;;;OAGG;IACH,aAAY;IAEZ;;;OAGG;IACH,MAFU,QAAQ,CAER;IAEV;;;OAGG;IACH,UAFU,OAAO,CAEQ;IAEzB;;;OAGG;IACH,WAFU,SAAS,CAES;IAE5B;;;;OAIG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,gBAAgB;IAGhB;;;;OAIG;IACH,YAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;OAIG;IACH,iBAHW,MAAM,EAAE,GACN,OAAO,CAanB;IAED;;;OAGG;IACH,SAFa,UAAU,CAQtB;IAED;;;OAGG;IACH,YAFW,UAAU,QAcpB;IAED;;;;OAIG;IACH,gBAHW,UAAU,GACR,OAAO,CAOnB;IAIL;;;OAGG;IACH,uBAFU,OAAO,CAEgB;CANhC;oBAtHmB,4BAA4B;0BACtB,yCAAyC"}
@@ -1,7 +1,7 @@
1
+ import { array_copy_entire } from "../../core/collection/array/array_copy_entire.js";
2
+ import { circle_intersects_circle } from "../../core/geom/2d/circle/circle_intersects_circle.js";
1
3
  import Vector2 from "../../core/geom/Vector2.js";
2
4
  import { Transform } from "../../engine/ecs/transform/Transform.js";
3
- import { circleIntersectsCircle } from "../../core/geom/2d/circle/circleIntersectsCircle.js";
4
- import { array_copy_entire } from "../../core/collection/array/array_copy_entire.js";
5
5
 
6
6
  export class MarkerNode {
7
7
 
@@ -115,7 +115,7 @@ export class MarkerNode {
115
115
  const p0 = this.transform.position;
116
116
  const p1 = other.transform.position;
117
117
 
118
- return circleIntersectsCircle(p0.x, p0.y, this.size, p1.x, p1.y, other.size);
118
+ return circle_intersects_circle(p0.x, p0.y, this.size, p1.x, p1.y, other.size);
119
119
  }
120
120
 
121
121
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"circleIntersectsCircle.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circleIntersectsCircle.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,2CARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,OAAO,CAQnB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"circleIntersectsPoint.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/circleIntersectsPoint.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,0CAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,OAAO,CAMnB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"computeCircleCirclePenetrationDistance.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/circle/computeCircleCirclePenetrationDistance.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,2DARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAqBlB"}