Skip to content

Commit

Permalink
feat: bump version after few minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Pietal committed Mar 1, 2024
1 parent d41c1fa commit 7ecb34b
Show file tree
Hide file tree
Showing 8 changed files with 1,168 additions and 1,404 deletions.
4 changes: 2 additions & 2 deletions dist/bodies/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Polygon extends sat_1.Polygon {
* scale Vector of body
*/
this.scaleVector = { x: 1, y: 1 };
if (!(points === null || points === void 0 ? void 0 : points.length)) {
if (!points.length) {
throw new Error("No points in polygon");
}
(0, utils_1.extendBody)(this, options);
Expand Down Expand Up @@ -92,7 +92,7 @@ class Polygon extends sat_1.Polygon {
* allow approx getting of scale
*/
get scale() {
return this.scaleVector.x;
return (this.scaleVector.x + this.scaleVector.y) / 2;
}
/**
* allow easier setting of scale
Expand Down
4 changes: 2 additions & 2 deletions dist/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ class Polygon extends sat_1.Polygon {
* scale Vector of body
*/
this.scaleVector = { x: 1, y: 1 };
if (!(points === null || points === void 0 ? void 0 : points.length)) {
if (!points.length) {
throw new Error("No points in polygon");
}
(0, utils_1.extendBody)(this, options);
Expand Down Expand Up @@ -766,7 +766,7 @@ class Polygon extends sat_1.Polygon {
* allow approx getting of scale
*/
get scale() {
return this.scaleVector.x;
return (this.scaleVector.x + this.scaleVector.y) / 2;
}
/**
* allow easier setting of scale
Expand Down
2 changes: 1 addition & 1 deletion dist/intersect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Point } from "./bodies/point";
/**
* replace body with array of related convex polygons
*/
export declare function ensureConvex<T extends Body = Circle | Point | Polygon>(body: T): (T | SATPolygon)[];
export declare function ensureConvex<TBody extends Body = Circle | Point | Polygon>(body: TBody): (TBody | SATPolygon)[];
export declare function polygonInCircle(polygon: Polygon, circle: Pick<Circle, "pos" | "r">): boolean;
export declare function pointInPolygon(point: Vector, polygon: Polygon): boolean;
export declare function polygonInPolygon(polygonA: Polygon, polygonB: Polygon): boolean;
Expand Down
4 changes: 2 additions & 2 deletions docs/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ class Polygon extends sat_1.Polygon {
* scale Vector of body
*/
this.scaleVector = { x: 1, y: 1 };
if (!(points === null || points === void 0 ? void 0 : points.length)) {
if (!points.length) {
throw new Error("No points in polygon");
}
(0, utils_1.extendBody)(this, options);
Expand Down Expand Up @@ -766,7 +766,7 @@ class Polygon extends sat_1.Polygon {
* allow approx getting of scale
*/
get scale() {
return this.scaleVector.x;
return (this.scaleVector.x + this.scaleVector.y) / 2;
}
/**
* allow easier setting of scale
Expand Down
4 changes: 2 additions & 2 deletions docs/functions/ensureConvex.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</li>
</ul>
<a id="md:step-5-collision-detection-and-resolution" class="tsd-anchor"></a><h3><a href="#md:step-5-collision-detection-and-resolution">Step 5: Collision Detection and Resolution</a></h3><p>Check collisions for all bodies or a single body:</p>
<pre><code class="language-ts"><span class="hl-7">// all bodies</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkAll</span><span class="hl-1">((</span><span class="hl-5">response</span><span class="hl-1">: </span><span class="hl-8">Response</span><span class="hl-1">) </span><span class="hl-3">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-7">// if you want to end after first collision</span><br/><span class="hl-1"> </span><span class="hl-9">return</span><span class="hl-1"> </span><span class="hl-3">true</span><br/><span class="hl-1">})</span><br/><br/><span class="hl-7">// check for one `body`</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkOne</span><span class="hl-1">(</span><span class="hl-5">body</span><span class="hl-1">, (</span><span class="hl-5">response</span><span class="hl-1">: </span><span class="hl-8">Response</span><span class="hl-1">) </span><span class="hl-3">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-7">// if you want to end after first collision</span><br/><span class="hl-1"> </span><span class="hl-9">return</span><span class="hl-1"> </span><span class="hl-3">true</span><br/><span class="hl-1">})</span>
<pre><code class="language-ts"><span class="hl-7">// check if any body collides, end after first collision and return true</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkAll</span><span class="hl-1">(() </span><span class="hl-3">=&gt;</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">)</span><br/><br/><span class="hl-7">// check if 1 body collides, end after first collision and return true</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkOne</span><span class="hl-1">(</span><span class="hl-5">body</span><span class="hl-1">, () </span><span class="hl-3">=&gt;</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">)</span>
</code><button>Copy</button></pre>
<p>For a direct collision check without broad-phase search, use <code>system.checkCollision(body1, body2)</code>. However, this isn&#39;t recommended due to efficiency loss.</p>
<p>Access detailed collision information in the system.response object, which includes properties like <code>a, b, overlap, overlapN, overlapV, aInB, and bInA</code>.</p>
Expand All @@ -110,7 +110,7 @@
<p>This will remove the body from the system&#39;s internal data structures, preventing it from being included in future collision checks. If you keep a reference to the body, you can insert it again later with <code>system.insert(body)</code>.</p>
<p>Remember to always keep your collision system as clean as possible. This means removing bodies when they&#39;re not needed, and avoiding unnecessary updates. Following these guidelines will help ensure your project runs smoothly and efficiently.</p>
<p>And that&#39;s it! You&#39;re now ready to use the Detect-Collisions library in your project. Whether you&#39;re making a game, a simulation, or any other kind of interactive experience, Detect-Collisions provides a robust, efficient, and easy-to-use solution for collision detection. Happy coding!</p>
<a id="md:detecting-collision-after-insertion" class="tsd-anchor"></a><h2><a href="#md:detecting-collision-after-insertion">Detecting collision after insertion</a></h2><pre><code class="language-ts"><span class="hl-7">// create self-destructing collider</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-0">testCollision</span><span class="hl-1"> = ({ </span><span class="hl-5">x</span><span class="hl-1">, </span><span class="hl-5">y</span><span class="hl-1"> }, </span><span class="hl-5">radius</span><span class="hl-1"> = </span><span class="hl-6">10</span><span class="hl-1">) </span><span class="hl-3">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-7">// create and add to tree</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">circle</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">createCircle</span><span class="hl-1">({ </span><span class="hl-5">x</span><span class="hl-1">, </span><span class="hl-5">y</span><span class="hl-1"> }, </span><span class="hl-5">radius</span><span class="hl-1">)</span><br/><span class="hl-1"> </span><span class="hl-7">// init as false</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkOne</span><span class="hl-1">(</span><span class="hl-5">circle</span><span class="hl-1">, () </span><span class="hl-3">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-7">// ends iterating after first collision</span><br/><span class="hl-1"> </span><span class="hl-9">return</span><span class="hl-1"> </span><span class="hl-3">true</span><br/><span class="hl-1"> })</span><br/><br/><span class="hl-1"> </span><span class="hl-7">// remove from tree</span><br/><span class="hl-1"> </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">remove</span><span class="hl-1">(</span><span class="hl-5">circle</span><span class="hl-1">)</span><br/><br/><span class="hl-1"> </span><span class="hl-9">return</span><span class="hl-1"> </span><span class="hl-5">collided</span><span class="hl-1"> ? </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-5">response</span><span class="hl-1"> : </span><span class="hl-3">null</span><br/><span class="hl-1">}</span>
<a id="md:detecting-collision-after-insertion" class="tsd-anchor"></a><h2><a href="#md:detecting-collision-after-insertion">Detecting collision after insertion</a></h2><pre><code class="language-ts"><span class="hl-7">// create self-destructing collider</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-0">testCollision</span><span class="hl-1"> = ({ </span><span class="hl-5">x</span><span class="hl-1">, </span><span class="hl-5">y</span><span class="hl-1"> }, </span><span class="hl-5">radius</span><span class="hl-1"> = </span><span class="hl-6">10</span><span class="hl-1">) </span><span class="hl-3">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-7">// create and add to tree</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">circle</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">createCircle</span><span class="hl-1">({ </span><span class="hl-5">x</span><span class="hl-1">, </span><span class="hl-5">y</span><span class="hl-1"> }, </span><span class="hl-5">radius</span><span class="hl-1">)</span><br/><span class="hl-1"> </span><span class="hl-7">// init as false</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-4">collided</span><span class="hl-1"> = </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">checkOne</span><span class="hl-1">(</span><span class="hl-5">circle</span><span class="hl-1">, () </span><span class="hl-3">=&gt;</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">)</span><br/><br/><span class="hl-1"> </span><span class="hl-7">// remove from tree</span><br/><span class="hl-1"> </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">remove</span><span class="hl-1">(</span><span class="hl-5">circle</span><span class="hl-1">)</span><br/><br/><span class="hl-1"> </span><span class="hl-9">return</span><span class="hl-1"> </span><span class="hl-5">collided</span><span class="hl-1"> ? </span><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-5">response</span><span class="hl-1"> : </span><span class="hl-3">null</span><br/><span class="hl-1">}</span>
</code><button>Copy</button></pre>
<a id="md:handling-concave-polygons" class="tsd-anchor"></a><h2><a href="#md:handling-concave-polygons">Handling Concave Polygons</a></h2><p>As of version 6.8.0, Detect-Collisions fully supports non-convex or hollow polygons*, provided they are valid. Learn more about this feature from <a href="https://github.com/Prozi/detect-collisions/issues/45">GitHub Issue #45</a> or experiment with it on <a href="https://stackblitz.com/edit/detect-collisions">Stackblitz</a>.</p>
<a id="md:visual-debugging-with-rendering" class="tsd-anchor"></a><h2><a href="#md:visual-debugging-with-rendering">Visual Debugging with Rendering</a></h2><p>To facilitate debugging, Detect-Collisions allows you to visually represent the collision bodies. By invoking the <code>draw()</code> method and supplying a 2D context of a <code>&lt;canvas&gt;</code> element, you can draw all the bodies within a collision system.</p>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "detect-collisions",
"version": "9.3.1",
"version": "9.3.2",
"description": "detecting collisions between bodies: Points, Lines, Boxes, Polygons (Concave too), Ellipses and Circles. Also RayCasting. All bodies can have offset, rotation, scale, bounding box padding, can be static (non moving) or be trigger bodies (non colliding).",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -66,7 +66,7 @@
"sat": "^0.9.0"
},
"devDependencies": {
"@types/node": "^20.11.21",
"@types/node": "^20.11.24",
"chef-express": "^2.1.3",
"html-webpack-plugin": "^5.6.0",
"husky": "^9.0.11",
Expand Down
Loading

0 comments on commit 7ecb34b

Please sign in to comment.