Skip to content

Commit

Permalink
feat: yarn install node@18 + update benchmark node version to 18 (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacek Pietal <[email protected]>
  • Loading branch information
Prozi and Jacek Pietal authored Mar 23, 2024
1 parent 296c93a commit aa92f61
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- run: |
npm install
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ Check collisions for all bodies or a single body:

```ts
// check if any body collides, end after first collision and return true
const collided = system.checkAll(() => true)
const collided = system.checkAll()

// check if 1 body collides, end after first collision and return true
const collided = system.checkOne(body, () => true)
const collided = system.checkOne(body)
```

For a direct collision check without broad-phase search, use `system.checkCollision(body1, body2)`. However, this isn't recommended due to efficiency loss.
Expand Down Expand Up @@ -222,7 +222,7 @@ const testCollision = ({ x, y }, radius = 10) => {
// create and add to tree
const circle = system.createCircle({ x, y }, radius)
// init as false
const collided = system.checkOne(circle, () => true)
const collided = system.checkOne(circle)

// remove from tree
system.remove(circle)
Expand Down
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">// 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>
<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><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>
</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><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>
<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><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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "detect-collisions",
"version": "9.4.2",
"version": "9.4.3",
"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

0 comments on commit aa92f61

Please sign in to comment.