@ue-too/dynamics 0.6.0 → 0.7.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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # dynamics
2
+
3
+ This is a library that provides a 2D physics engine with collision detection, rigid bodies, and constraints.
4
+
5
+ Please _**DO NOT**_ use this in production.
6
+
7
+ Detailed information would be added in the future.
package/benchmark.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { Point } from "@ue-too/math";
2
+ interface MockRigidBody {
3
+ AABB: {
4
+ min: Point;
5
+ max: Point;
6
+ };
7
+ id: number;
8
+ velocity: Point;
9
+ isStatic(): boolean;
10
+ }
11
+ declare class MockStaticBody implements MockRigidBody {
12
+ AABB: {
13
+ min: Point;
14
+ max: Point;
15
+ };
16
+ id: number;
17
+ velocity: Point;
18
+ constructor(id: number, x: number, y: number, width: number, height: number);
19
+ isStatic(): boolean;
20
+ }
21
+ declare class MockDynamicBody implements MockRigidBody {
22
+ AABB: {
23
+ min: Point;
24
+ max: Point;
25
+ };
26
+ id: number;
27
+ velocity: Point;
28
+ constructor(id: number, x: number, y: number, width: number, height: number, vx?: number, vy?: number);
29
+ isStatic(): boolean;
30
+ update(dt: number): void;
31
+ }
32
+ declare class SpatialIndexBenchmark {
33
+ private scenarios;
34
+ constructor();
35
+ private setupScenarios;
36
+ private createDenseCluster;
37
+ private createRandomDistribution;
38
+ private createMovingObjects;
39
+ private createLineFormation;
40
+ private createMixedSizes;
41
+ private benchmarkQuadTree;
42
+ private benchmarkDynamicTree;
43
+ private benchmarkSweepAndPrune;
44
+ run(): void;
45
+ }
46
+ export { SpatialIndexBenchmark, MockRigidBody, MockDynamicBody, MockStaticBody };
47
+ export declare function runBenchmark(): void;
@@ -0,0 +1,17 @@
1
+ export interface CollisionFilter {
2
+ category: number;
3
+ mask: number;
4
+ group: number;
5
+ }
6
+ export declare const DEFAULT_COLLISION_FILTER: CollisionFilter;
7
+ export declare function canCollide(filterA: CollisionFilter, filterB: CollisionFilter): boolean;
8
+ export declare const CollisionCategory: {
9
+ readonly STATIC: 1;
10
+ readonly DYNAMIC: 2;
11
+ readonly PLAYER: 4;
12
+ readonly ENEMY: 8;
13
+ readonly PROJECTILE: 16;
14
+ readonly SENSOR: 32;
15
+ readonly PICKUP: 64;
16
+ readonly PLATFORM: 128;
17
+ };
package/collision.d.ts CHANGED
@@ -26,11 +26,32 @@ export declare function narrowPhase(bodies: BaseRigidBody[], combinationsToCheck
26
26
  bodyAIndex: number;
27
27
  bodyBIndex: number;
28
28
  }[], resolveCollisionFlag: boolean): void;
29
- export declare function broadPhaseWithRigidBodyReturned(quadTree: QuadTree, bodies: RigidBody[]): {
29
+ export declare function broadPhaseWithRigidBodyReturned(quadTree: QuadTree<RigidBody>, bodies: RigidBody[]): {
30
30
  bodyA: RigidBody;
31
31
  bodyB: RigidBody;
32
32
  }[];
33
- export declare function broadPhase(quadTree: QuadTree, bodies: BaseRigidBody[]): {
33
+ export declare function broadPhaseWithSpatialIndex(spatialIndex: import("./dynamic-tree").SpatialIndex<RigidBody>, bodies: RigidBody[]): {
34
+ bodyA: RigidBody;
35
+ bodyB: RigidBody;
36
+ }[];
37
+ export declare function broadPhase(quadTree: QuadTree<RigidBody>, bodies: BaseRigidBody[]): {
34
38
  bodyAIndex: number;
35
39
  bodyBIndex: number;
36
40
  }[];
41
+ export declare function broadPhaseWithSpatialIndexFiltered(spatialIndex: import("./dynamic-tree").SpatialIndex<RigidBody>, bodies: RigidBody[]): {
42
+ bodyA: RigidBody;
43
+ bodyB: RigidBody;
44
+ }[];
45
+ export declare function narrowPhaseWithRigidBodyAndPairs(bodies: RigidBody[], combinationsToCheck: {
46
+ bodyA: RigidBody;
47
+ bodyB: RigidBody;
48
+ }[], resolveCollisionFlag: boolean): {
49
+ contactPoints: Point[];
50
+ collisions: {
51
+ bodyA: RigidBody;
52
+ bodyB: RigidBody;
53
+ contactPoints: Point[];
54
+ normal?: Point;
55
+ depth?: number;
56
+ }[];
57
+ };
@@ -0,0 +1,57 @@
1
+ import { Point } from "@ue-too/math";
2
+ export interface SpatialIndexObject {
3
+ AABB: {
4
+ min: Point;
5
+ max: Point;
6
+ };
7
+ }
8
+ export interface SpatialIndex<T extends SpatialIndexObject> {
9
+ clear(): void;
10
+ insert(object: T): void;
11
+ retrieve(object: T): T[];
12
+ draw?(context: CanvasRenderingContext2D): void;
13
+ }
14
+ export declare class SweepAndPrune<T extends SpatialIndexObject> implements SpatialIndex<T> {
15
+ private xEndpoints;
16
+ private objects;
17
+ private nextId;
18
+ clear(): void;
19
+ insert(object: T): void;
20
+ update(object: T): void;
21
+ remove(object: T): void;
22
+ retrieve(queryObject: T): T[];
23
+ findAllOverlaps(): Array<{
24
+ a: T;
25
+ b: T;
26
+ }>;
27
+ private insertEndpointSorted;
28
+ private removeEndpoint;
29
+ private aabbIntersects;
30
+ draw?(context: CanvasRenderingContext2D): void;
31
+ getStats(): {
32
+ endpointCount: number;
33
+ objectCount: number;
34
+ };
35
+ }
36
+ export declare class DynamicTree<T extends SpatialIndexObject> implements SpatialIndex<T> {
37
+ private root;
38
+ private nodeCount;
39
+ private margin;
40
+ clear(): void;
41
+ insert(object: T): void;
42
+ private insertNode;
43
+ private findBestSibling;
44
+ private balance;
45
+ private rotateLeft;
46
+ private rotateRight;
47
+ retrieve(object: T): T[];
48
+ draw(context: CanvasRenderingContext2D): void;
49
+ private drawNode;
50
+ private getArea;
51
+ private combineAABB;
52
+ private aabbIntersects;
53
+ getStats(): {
54
+ nodeCount: number;
55
+ height: number;
56
+ };
57
+ }