Skip to content

Commit

Permalink
feat: introduce Body.typeGroup = BodyGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Pietal committed May 24, 2024
1 parent 4625dfd commit d11a84d
Show file tree
Hide file tree
Showing 121 changed files with 4,858 additions and 1,396 deletions.
2 changes: 1 addition & 1 deletion dist/base-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class BaseSystem extends model_1.RBush {
if (!body) {
return false;
}
if (body.type && traverseFunction(body, children, index)) {
if (body.typeGroup && traverseFunction(body, children, index)) {
return true;
}
// if callback returns true, ends forEach
Expand Down
6 changes: 5 additions & 1 deletion dist/bodies/box.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BodyOptions, BodyType, PotentialVector } from "../model";
import { BodyGroup, BodyOptions, BodyType, PotentialVector } from "../model";
import { Polygon } from "./polygon";
/**
* collider - box
Expand All @@ -8,6 +8,10 @@ export declare class Box extends Polygon {
* type of body
*/
readonly type: BodyType.Box | BodyType.Point;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Box | BodyGroup.Point;
/**
* boxes are convex
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Box extends polygon_1.Polygon {
* type of body
*/
this.type = model_1.BodyType.Box;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Box;
/**
* boxes are convex
*/
Expand Down
15 changes: 14 additions & 1 deletion dist/bodies/circle.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BBox } from "rbush";
import { Circle as SATCircle } from "sat";
import { BaseSystem } from "../base-system";
import { BodyOptions, BodyProps, BodyType, PotentialVector, SATVector, Vector } from "../model";
import { BodyGroup, BodyOptions, BodyProps, BodyType, PotentialVector, SATVector, Vector } from "../model";
/**
* collider - circle
*/
Expand Down Expand Up @@ -63,10 +63,18 @@ export declare class Circle extends SATCircle implements BBox, BodyProps {
* circle type
*/
readonly type: BodyType.Circle;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Circle;
/**
* always centered
*/
readonly isCentered = true;
/**
* group for collision filtering
*/
protected _group: number;
/**
* saved initial radius - internal
*/
Expand Down Expand Up @@ -107,6 +115,11 @@ export declare class Circle extends SATCircle implements BBox, BodyProps {
* scaleY = scale in case of Circles
*/
get scaleY(): number;
/**
* group for collision filtering
*/
get group(): number;
set group(group: number);
/**
* update position
*/
Expand Down
13 changes: 13 additions & 0 deletions dist/bodies/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Circle extends sat_1.Circle {
* circle type
*/
this.type = model_1.BodyType.Circle;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Circle;
/**
* always centered
*/
Expand Down Expand Up @@ -86,6 +90,15 @@ class Circle extends sat_1.Circle {
get scaleY() {
return this.scale;
}
/**
* group for collision filtering
*/
get group() {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
}
/**
* update position
*/
Expand Down
6 changes: 5 additions & 1 deletion dist/bodies/ellipse.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BodyOptions, BodyType, PotentialVector } from "../model";
import { BodyGroup, BodyOptions, BodyType, PotentialVector } from "../model";
import { Polygon } from "./polygon";
/**
* collider - ellipse
Expand All @@ -8,6 +8,10 @@ export declare class Ellipse extends Polygon {
* ellipse type
*/
readonly type: BodyType.Ellipse;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Ellipse;
/**
* ellipses are convex
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Ellipse extends polygon_1.Polygon {
* ellipse type
*/
this.type = model_1.BodyType.Ellipse;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Ellipse;
/**
* ellipses are convex
*/
Expand Down
6 changes: 5 additions & 1 deletion dist/bodies/line.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vector as SATVector } from "sat";
import { BodyOptions, BodyType, Vector } from "../model";
import { BodyGroup, BodyOptions, BodyType, Vector } from "../model";
import { Polygon } from "./polygon";
/**
* collider - line
Expand All @@ -9,6 +9,10 @@ export declare class Line extends Polygon {
* line type
*/
readonly type: BodyType.Line;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Line;
/**
* line is convex
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Line extends polygon_1.Polygon {
* line type
*/
this.type = model_1.BodyType.Line;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Line;
/**
* line is convex
*/
Expand Down
6 changes: 5 additions & 1 deletion dist/bodies/point.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BodyOptions, BodyType, PotentialVector } from "../model";
import { BodyGroup, BodyOptions, BodyType, PotentialVector } from "../model";
import { Box } from "./box";
/**
* collider - point (very tiny box)
Expand All @@ -8,6 +8,10 @@ export declare class Point extends Box {
* point type
*/
readonly type: BodyType.Point;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Point;
/**
* collider - point (very tiny box)
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Point extends box_1.Box {
* point type
*/
this.type = model_1.BodyType.Point;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Point;
}
}
exports.Point = Point;
15 changes: 14 additions & 1 deletion dist/bodies/polygon.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSimple } from "poly-decomp-es";
import { BBox } from "rbush";
import { Polygon as SATPolygon } from "sat";
import { BodyOptions, BodyProps, BodyType, DecompPolygon, PotentialVector, SATVector, Vector } from "../model";
import { BodyGroup, BodyOptions, BodyProps, BodyType, DecompPolygon, PotentialVector, SATVector, Vector } from "../model";
import { System } from "../system";
export { isSimple };
/**
Expand Down Expand Up @@ -60,6 +60,10 @@ export declare class Polygon extends SATPolygon implements BBox, BodyProps {
* type of body
*/
readonly type: BodyType.Polygon | BodyType.Box | BodyType.Point | BodyType.Ellipse | BodyType.Line;
/**
* faster than type
*/
readonly typeGroup: BodyGroup.Polygon | BodyGroup.Box | BodyGroup.Point | BodyGroup.Ellipse | BodyGroup.Line;
/**
* backup of points used for scaling
*/
Expand All @@ -68,6 +72,10 @@ export declare class Polygon extends SATPolygon implements BBox, BodyProps {
* is body centered
*/
protected centered: boolean;
/**
* group for collision filtering
*/
protected _group: number;
/**
* scale Vector of body
*/
Expand Down Expand Up @@ -110,6 +118,11 @@ export declare class Polygon extends SATPolygon implements BBox, BodyProps {
* allow easier setting of scale
*/
set scale(scale: number);
/**
* group for collision filtering
*/
get group(): number;
set group(group: number);
/**
* update position
*/
Expand Down
15 changes: 14 additions & 1 deletion dist/bodies/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Polygon extends sat_1.Polygon {
* type of body
*/
this.type = model_1.BodyType.Polygon;
/**
* faster than type
*/
this.typeGroup = model_1.BodyGroup.Polygon;
/**
* is body centered
*/
Expand Down Expand Up @@ -102,6 +106,15 @@ class Polygon extends sat_1.Polygon {
set scale(scale) {
this.setScale(scale);
}
/**
* group for collision filtering
*/
get group() {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
}
/**
* update position
*/
Expand Down Expand Up @@ -254,7 +267,7 @@ class Polygon extends sat_1.Polygon {
* returns body split into convex polygons, or empty array for convex bodies
*/
getConvex() {
if ((this.type && this.type !== model_1.BodyType.Polygon) ||
if ((this.typeGroup && this.typeGroup !== model_1.BodyGroup.Polygon) ||
this.points.length < 4) {
return [];
}
Expand Down
Loading

0 comments on commit d11a84d

Please sign in to comment.