Skip to content

Commit

Permalink
feat: change getSATTest and checkAInB to use array lookup instead of …
Browse files Browse the repository at this point in the history
…hashmap
  • Loading branch information
Prozi committed Jul 15, 2024
1 parent dc03e0c commit fd32167
Show file tree
Hide file tree
Showing 150 changed files with 79,185 additions and 16,481 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,12 @@ And that's it! You're now ready to utilize the Detect-Collisions library in your

## Visual Debugging with Rendering

To facilitate debugging, Detect-Collisions allows you to visually represent the collision bodies. By invoking the `draw()` method and supplying a 2D context of a `<canvas>` element, you can draw all the bodies within a collision system.
To facilitate debugging, Detect-Collisions allows you to visually represent the collision bodies. By invoking the `draw()` method and supplying a 2D context of a `<canvas>` element, you can draw all the bodies within a collision system. You can also opt to draw individual bodies.

```ts
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");

context.strokeStyle = "#FFFFFF";
context.beginPath();
system.draw(context);
context.stroke();
```

You can also opt to draw individual bodies.

```ts
context.strokeStyle = "#FFFFFF";
context.beginPath();
// draw specific body
Expand Down
164 changes: 101 additions & 63 deletions dist/base-system.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { Body, BodyOptions, ChildrenData, Data, InTest, Leaf, PotentialVector, RBush, TraverseFunction, Vector } from "./model";
import {
Body,
BodyOptions,
ChildrenData,
Data,
InTest,
Leaf,
PotentialVector,
RBush,
TraverseFunction,
Vector,
} from "./model";
import { Box } from "./bodies/box";
import { Circle } from "./bodies/circle";
import { Ellipse } from "./bodies/ellipse";
Expand All @@ -8,66 +19,93 @@ import { Polygon } from "./bodies/polygon";
/**
* very base collision system (create, insert, update, draw, remove)
*/
export declare class BaseSystem<TBody extends Body = Body> extends RBush implements Data<TBody> {
data: ChildrenData<TBody>;
/**
* create point at position with options and add to system
*/
createPoint(position: PotentialVector, options?: BodyOptions): Point;
/**
* create line at position with options and add to system
*/
createLine(start: Vector, end: Vector, options?: BodyOptions): Line;
/**
* create circle at position with options and add to system
*/
createCircle(position: PotentialVector, radius: number, options?: BodyOptions): Circle;
/**
* create box at position with options and add to system
*/
createBox(position: PotentialVector, width: number, height: number, options?: BodyOptions): Box;
/**
* create ellipse at position with options and add to system
*/
createEllipse(position: PotentialVector, radiusX: number, radiusY?: number, step?: number, options?: BodyOptions): Ellipse;
/**
* create polygon at position with options and add to system
*/
createPolygon(position: PotentialVector, points: PotentialVector[], options?: BodyOptions): Polygon;
/**
* re-insert body into collision tree and update its bbox
* every body can be part of only one system
*/
insert(body: TBody): this;
/**
* updates body in collision tree
*/
updateBody(body: TBody): void;
/**
* update all bodies aabb
*/
update(): void;
/**
* draw exact bodies colliders outline
*/
draw(context: CanvasRenderingContext2D): void;
/**
* draw bounding boxes hierarchy outline
*/
drawBVH(context: CanvasRenderingContext2D): void;
/**
* remove body aabb from collision tree
*/
remove(body: TBody, equals?: InTest<TBody>): this;
/**
* get object potential colliders
* @deprecated because it's slower to use than checkOne() or checkAll()
*/
getPotentials(body: TBody): TBody[];
/**
* used to find body deep inside data with finder function returning boolean found or not
*/
traverse(traverseFunction: TraverseFunction<TBody>, { children }?: {
children?: Leaf<TBody>[];
}): TBody | undefined;
export declare class BaseSystem<TBody extends Body = Body>
extends RBush
implements Data<TBody>
{
data: ChildrenData<TBody>;
/**
* create point at position with options and add to system
*/
createPoint(position: PotentialVector, options?: BodyOptions): Point;
/**
* create line at position with options and add to system
*/
createLine(start: Vector, end: Vector, options?: BodyOptions): Line;
/**
* create circle at position with options and add to system
*/
createCircle(
position: PotentialVector,
radius: number,
options?: BodyOptions,
): Circle;
/**
* create box at position with options and add to system
*/
createBox(
position: PotentialVector,
width: number,
height: number,
options?: BodyOptions,
): Box;
/**
* create ellipse at position with options and add to system
*/
createEllipse(
position: PotentialVector,
radiusX: number,
radiusY?: number,
step?: number,
options?: BodyOptions,
): Ellipse;
/**
* create polygon at position with options and add to system
*/
createPolygon(
position: PotentialVector,
points: PotentialVector[],
options?: BodyOptions,
): Polygon;
/**
* re-insert body into collision tree and update its bbox
* every body can be part of only one system
*/
insert(body: TBody): this;
/**
* updates body in collision tree
*/
updateBody(body: TBody): void;
/**
* update all bodies aabb
*/
update(): void;
/**
* draw exact bodies colliders outline
*/
draw(context: CanvasRenderingContext2D): void;
/**
* draw bounding boxes hierarchy outline
*/
drawBVH(context: CanvasRenderingContext2D): void;
/**
* remove body aabb from collision tree
*/
remove(body: TBody, equals?: InTest<TBody>): this;
/**
* get object potential colliders
* @deprecated because it's slower to use than checkOne() or checkAll()
*/
getPotentials(body: TBody): TBody[];
/**
* used to find body deep inside data with finder function returning boolean found or not
*/
traverse(
traverseFunction: TraverseFunction<TBody>,
{
children,
}?: {
children?: Leaf<TBody>[];
},
): TBody | undefined;
}
Loading

0 comments on commit fd32167

Please sign in to comment.