Skip to content

Commit

Permalink
feat: publish pull/76
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Pietal committed May 30, 2024
1 parent be0dc9c commit aa2fa3b
Show file tree
Hide file tree
Showing 39 changed files with 1,034 additions and 305 deletions.
2 changes: 1 addition & 1 deletion dist/bodies/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Circle extends sat_1.Circle {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
this._group = (0, utils_1.getGroup)(group);
}
/**
* update position
Expand Down
2 changes: 1 addition & 1 deletion dist/bodies/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Polygon extends sat_1.Polygon {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
this._group = (0, utils_1.getGroup)(group);
}
/**
* update position
Expand Down
60 changes: 39 additions & 21 deletions dist/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ class Circle extends sat_1.Circle {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
this._group = (0, utils_1.getGroup)(group);
}
/**
* update position
Expand Down Expand Up @@ -2878,7 +2878,7 @@ class Polygon extends sat_1.Polygon {
return this._group;
}
set group(group) {
this._group = (0, model_1.getGroup)(group);
this._group = (0, utils_1.getGroup)(group);
}
/**
* update position
Expand Down Expand Up @@ -3317,7 +3317,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.BodyGroup = exports.getGroup = exports.BodyType = exports.SATCircle = exports.SATPolygon = exports.SATVector = exports.Response = exports.RBush = exports.isSimple = void 0;
exports.BodyGroup = exports.BodyType = exports.SATCircle = exports.SATPolygon = exports.SATVector = exports.Response = exports.RBush = exports.isSimple = void 0;
const rbush_1 = __importDefault(__webpack_require__(/*! rbush */ "./node_modules/rbush/rbush.min.js"));
Object.defineProperty(exports, "RBush", ({ enumerable: true, get: function () { return rbush_1.default; } }));
const sat_1 = __webpack_require__(/*! sat */ "./node_modules/sat/SAT.js");
Expand All @@ -3339,14 +3339,6 @@ var BodyType;
BodyType["Line"] = "Line";
BodyType["Point"] = "Point";
})(BodyType = exports.BodyType || (exports.BodyType = {}));
/**
* for groups
*/
function getGroup(group) {
const limited = Math.max(0, Math.min(group, 0x7FFFFFFF));
return (limited << 16) | limited;
}
exports.getGroup = getGroup;
/**
* for groups
*/
Expand Down Expand Up @@ -3550,7 +3542,7 @@ class System extends base_system_1.BaseSystem {
const { bbox: bboxA } = bodyA;
const { bbox: bboxB } = bodyA;
// assess the bodies real aabb without padding
if (!(0, utils_1.areSameGroup)(bodyA, bodyB) ||
if (!(0, utils_1.canInteract)(bodyA, bodyB) ||
!bboxA ||
!bboxB ||
(0, utils_1.notIntersectAABB)(bboxA, bboxB)) {
Expand Down Expand Up @@ -3640,7 +3632,7 @@ exports.System = System;
"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.bin2dec = exports.returnTrue = exports.cloneResponse = exports.drawBVH = exports.drawPolygon = exports.dashLineTo = exports.getSATTest = exports.getBounceDirection = exports.mapArrayToVector = exports.mapVectorToArray = exports.clonePointsArray = exports.checkAInB = exports.areSameGroup = exports.intersectAABB = exports.notIntersectAABB = exports.bodyMoved = exports.extendBody = exports.clockwise = exports.distance = exports.ensurePolygonPoints = exports.ensureVectorPoint = exports.createBox = exports.createEllipse = exports.rad2deg = exports.deg2rad = exports.RAD2DEG = exports.DEG2RAD = void 0;
exports.groupBits = exports.ensureNumber = exports.bin2dec = exports.getGroup = exports.returnTrue = exports.cloneResponse = exports.drawBVH = exports.drawPolygon = exports.dashLineTo = exports.getSATTest = exports.getBounceDirection = exports.mapArrayToVector = exports.mapVectorToArray = exports.clonePointsArray = exports.checkAInB = exports.canInteract = exports.intersectAABB = exports.notIntersectAABB = exports.bodyMoved = exports.extendBody = exports.clockwise = exports.distance = exports.ensurePolygonPoints = exports.ensureVectorPoint = exports.createBox = exports.createEllipse = exports.rad2deg = exports.deg2rad = exports.RAD2DEG = exports.DEG2RAD = void 0;
const sat_1 = __webpack_require__(/*! sat */ "./node_modules/sat/SAT.js");
const intersect_1 = __webpack_require__(/*! ./intersect */ "./src/intersect.ts");
const model_1 = __webpack_require__(/*! ./model */ "./src/model.ts");
Expand Down Expand Up @@ -3790,11 +3782,11 @@ exports.intersectAABB = intersectAABB;
/**
* checks if two bodies can interact (for collision filtering)
*/
function areSameGroup(bodyA, bodyB) {
function canInteract(bodyA, bodyB) {
return (((bodyA.group >> 16) & (bodyB.group & 0xFFFF) &&
(bodyB.group >> 16) & (bodyA.group & 0xFFFF)) !== 0);
}
exports.areSameGroup = areSameGroup;
exports.canInteract = canInteract;
/**
* checks if body a is in body b
*/
Expand Down Expand Up @@ -3927,13 +3919,39 @@ function returnTrue() {
return true;
}
exports.returnTrue = returnTrue;
/**
* for groups
*/
function getGroup(group) {
return Math.max(0, Math.min(group, 0x7FFFFFFF));
}
exports.getGroup = getGroup;
/**
* binary string to decimal number
*/
function bin2dec(binary) {
return Number(`0b${binary}`.replace(/\s/g, ""));
}
exports.bin2dec = bin2dec;
/**
* helper for groupBits()
*
* @param input - number or binary string
*/
function ensureNumber(input) {
return typeof input === "number" ? input : bin2dec(input);
}
exports.ensureNumber = ensureNumber;
/**
* create group bits from category and mask
*
* @param category - category bits
* @param mask - mask bits (default: category)
*/
function groupBits(category, mask = category) {
return (ensureNumber(category) << 16) | ensureNumber(mask);
}
exports.groupBits = groupBits;


/***/ }),
Expand Down Expand Up @@ -4049,7 +4067,7 @@ module.exports.height = height;

const { BodyGroup } = __webpack_require__(/*! ../model */ "./src/model.ts");
const { System } = __webpack_require__(/*! ../system */ "./src/system.ts");
const { getBounceDirection } = __webpack_require__(/*! ../utils */ "./src/utils.ts");
const { getBounceDirection, groupBits } = __webpack_require__(/*! ../utils */ "./src/utils.ts");
const { width, height, loop } = __webpack_require__(/*! ./canvas */ "./src/demo/canvas.js");
const seededRandom = (__webpack_require__(/*! random-seed */ "./node_modules/random-seed/index.js").create)("@Prozi").random;

Expand Down Expand Up @@ -4236,7 +4254,7 @@ class Stress {
switch (variant) {
case 0:
if (this.enableFiltering) {
options.group = BodyGroup.Circle;
options.group = groupBits(BodyGroup.Circle);
}
body = this.physics.createCircle(
{ x, y },
Expand All @@ -4251,7 +4269,7 @@ class Stress {
const width = random(minSize, maxSize);
const height = random(minSize, maxSize);
if (this.enableFiltering) {
options.group = BodyGroup.Ellipse;
options.group = groupBits(BodyGroup.Ellipse);
console.log();
}
body = this.physics.createEllipse({ x, y }, width, height, 2, options);
Expand All @@ -4261,7 +4279,7 @@ class Stress {

case 2:
if (this.enableFiltering) {
options.group = BodyGroup.Box;
options.group = groupBits(BodyGroup.Box);
}
body = this.physics.createBox(
{ x, y },
Expand All @@ -4275,7 +4293,7 @@ class Stress {

case 3:
if (this.enableFiltering) {
options.group = BodyGroup.Line;
options.group = groupBits(BodyGroup.Line);
}
body = this.physics.createLine(
{ x, y },
Expand All @@ -4291,7 +4309,7 @@ class Stress {

default:
if (this.enableFiltering) {
options.group = BodyGroup.Polygon;
options.group = groupBits(BodyGroup.Polygon);
}
body = this.physics.createPolygon(
{ x, y },
Expand Down
12 changes: 6 additions & 6 deletions dist/demo/stress.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
const { BodyGroup } = require("../model");
const { System } = require("../system");
const { getBounceDirection } = require("../utils");
const { getBounceDirection, groupBits } = require("../utils");
const { width, height, loop } = require("./canvas");
const seededRandom = require("random-seed").create("@Prozi").random;
function random(min, max) {
Expand Down Expand Up @@ -155,7 +155,7 @@ class Stress {
switch (variant) {
case 0:
if (this.enableFiltering) {
options.group = BodyGroup.Circle;
options.group = groupBits(BodyGroup.Circle);
}
body = this.physics.createCircle({ x, y }, random(minSize, maxSize) / 2, options);
++this.circles;
Expand All @@ -164,22 +164,22 @@ class Stress {
const width = random(minSize, maxSize);
const height = random(minSize, maxSize);
if (this.enableFiltering) {
options.group = BodyGroup.Ellipse;
options.group = groupBits(BodyGroup.Ellipse);
console.log();
}
body = this.physics.createEllipse({ x, y }, width, height, 2, options);
++this.ellipses;
break;
case 2:
if (this.enableFiltering) {
options.group = BodyGroup.Box;
options.group = groupBits(BodyGroup.Box);
}
body = this.physics.createBox({ x, y }, random(minSize, maxSize), random(minSize, maxSize), options);
++this.boxes;
break;
case 3:
if (this.enableFiltering) {
options.group = BodyGroup.Line;
options.group = groupBits(BodyGroup.Line);
}
body = this.physics.createLine({ x, y }, {
x: x + random(minSize, maxSize),
Expand All @@ -189,7 +189,7 @@ class Stress {
break;
default:
if (this.enableFiltering) {
options.group = BodyGroup.Polygon;
options.group = groupBits(BodyGroup.Polygon);
}
body = this.physics.createPolygon({ x, y }, [
{ x: -random(minSize, maxSize), y: random(minSize, maxSize) },
Expand Down
4 changes: 0 additions & 4 deletions dist/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export declare enum BodyType {
Line = "Line",
Point = "Point"
}
/**
* for groups
*/
export declare function getGroup(group: number): number;
/**
* for groups
*/
Expand Down
10 changes: 1 addition & 9 deletions dist/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BodyGroup = exports.getGroup = exports.BodyType = exports.SATCircle = exports.SATPolygon = exports.SATVector = exports.Response = exports.RBush = exports.isSimple = void 0;
exports.BodyGroup = exports.BodyType = exports.SATCircle = exports.SATPolygon = exports.SATVector = exports.Response = exports.RBush = exports.isSimple = void 0;
const rbush_1 = __importDefault(require("rbush"));
Object.defineProperty(exports, "RBush", { enumerable: true, get: function () { return rbush_1.default; } });
const sat_1 = require("sat");
Expand All @@ -25,14 +25,6 @@ var BodyType;
BodyType["Line"] = "Line";
BodyType["Point"] = "Point";
})(BodyType = exports.BodyType || (exports.BodyType = {}));
/**
* for groups
*/
function getGroup(group) {
const limited = Math.max(0, Math.min(group, 0x7FFFFFFF));
return (limited << 16) | limited;
}
exports.getGroup = getGroup;
/**
* for groups
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class System extends base_system_1.BaseSystem {
const { bbox: bboxA } = bodyA;
const { bbox: bboxB } = bodyA;
// assess the bodies real aabb without padding
if (!(0, utils_1.areSameGroup)(bodyA, bodyB) ||
if (!(0, utils_1.canInteract)(bodyA, bodyB) ||
!bboxA ||
!bboxB ||
(0, utils_1.notIntersectAABB)(bboxA, bboxB)) {
Expand Down
19 changes: 18 additions & 1 deletion dist/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export declare function intersectAABB(bodyA: BBox, bodyB: BBox): boolean;
/**
* checks if two bodies can interact (for collision filtering)
*/
export declare function areSameGroup(bodyA: Body, bodyB: Body): boolean;
export declare function canInteract(bodyA: Body, bodyB: Body): boolean;
/**
* checks if body a is in body b
*/
Expand Down Expand Up @@ -103,7 +103,24 @@ export declare function cloneResponse(response: Response): Response;
* dummy fn used as default, for optimization
*/
export declare function returnTrue(): boolean;
/**
* for groups
*/
export declare function getGroup(group: number): number;
/**
* binary string to decimal number
*/
export declare function bin2dec(binary: string): number;
/**
* helper for groupBits()
*
* @param input - number or binary string
*/
export declare function ensureNumber(input: number | string): number;
/**
* create group bits from category and mask
*
* @param category - category bits
* @param mask - mask bits (default: category)
*/
export declare function groupBits(category: number | string, mask?: number | string): number;
32 changes: 29 additions & 3 deletions dist/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bin2dec = exports.returnTrue = exports.cloneResponse = exports.drawBVH = exports.drawPolygon = exports.dashLineTo = exports.getSATTest = exports.getBounceDirection = exports.mapArrayToVector = exports.mapVectorToArray = exports.clonePointsArray = exports.checkAInB = exports.areSameGroup = exports.intersectAABB = exports.notIntersectAABB = exports.bodyMoved = exports.extendBody = exports.clockwise = exports.distance = exports.ensurePolygonPoints = exports.ensureVectorPoint = exports.createBox = exports.createEllipse = exports.rad2deg = exports.deg2rad = exports.RAD2DEG = exports.DEG2RAD = void 0;
exports.groupBits = exports.ensureNumber = exports.bin2dec = exports.getGroup = exports.returnTrue = exports.cloneResponse = exports.drawBVH = exports.drawPolygon = exports.dashLineTo = exports.getSATTest = exports.getBounceDirection = exports.mapArrayToVector = exports.mapVectorToArray = exports.clonePointsArray = exports.checkAInB = exports.canInteract = exports.intersectAABB = exports.notIntersectAABB = exports.bodyMoved = exports.extendBody = exports.clockwise = exports.distance = exports.ensurePolygonPoints = exports.ensureVectorPoint = exports.createBox = exports.createEllipse = exports.rad2deg = exports.deg2rad = exports.RAD2DEG = exports.DEG2RAD = void 0;
const sat_1 = require("sat");
const intersect_1 = require("./intersect");
const model_1 = require("./model");
Expand Down Expand Up @@ -150,11 +150,11 @@ exports.intersectAABB = intersectAABB;
/**
* checks if two bodies can interact (for collision filtering)
*/
function areSameGroup(bodyA, bodyB) {
function canInteract(bodyA, bodyB) {
return (((bodyA.group >> 16) & (bodyB.group & 0xFFFF) &&
(bodyB.group >> 16) & (bodyA.group & 0xFFFF)) !== 0);
}
exports.areSameGroup = areSameGroup;
exports.canInteract = canInteract;
/**
* checks if body a is in body b
*/
Expand Down Expand Up @@ -287,10 +287,36 @@ function returnTrue() {
return true;
}
exports.returnTrue = returnTrue;
/**
* for groups
*/
function getGroup(group) {
return Math.max(0, Math.min(group, 0x7FFFFFFF));
}
exports.getGroup = getGroup;
/**
* binary string to decimal number
*/
function bin2dec(binary) {
return Number(`0b${binary}`.replace(/\s/g, ""));
}
exports.bin2dec = bin2dec;
/**
* helper for groupBits()
*
* @param input - number or binary string
*/
function ensureNumber(input) {
return typeof input === "number" ? input : bin2dec(input);
}
exports.ensureNumber = ensureNumber;
/**
* create group bits from category and mask
*
* @param category - category bits
* @param mask - mask bits (default: category)
*/
function groupBits(category, mask = category) {
return (ensureNumber(category) << 16) | ensureNumber(mask);
}
exports.groupBits = groupBits;
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aa2fa3b

Please sign in to comment.