Skip to content

Commit

Permalink
chore: rebuild and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Pietal committed Jul 1, 2023
1 parent 9e93259 commit e1fc3d2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
13 changes: 5 additions & 8 deletions dist/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,20 +1310,17 @@ class System extends base_system_1.BaseSystem {
return super.insert(body);
}
/**
* alias for insert, updates body in collision tree
* updates body in collision tree
*/
updateBody(body) {
this.insert(body);
body.updateBody();
}
/**
* update all bodies aabb
*/
update() {
(0, optimized_1.forEach)(this.all(), (body) => {
// no need to every cycle update static body aabb
if (!body.isStatic) {
this.insert(body);
}
this.updateBody(body);
});
}
/**
Expand All @@ -1342,8 +1339,6 @@ class System extends base_system_1.BaseSystem {
* check one collider collisions with callback
*/
checkOne(body, callback = () => true, response = this.response) {
// first, lazy update body bbox if needed
body.updateBody();
// no need to check static body collision
if (body.isStatic) {
return false;
Expand Down Expand Up @@ -3999,6 +3994,8 @@ class Stress {
body.y + body.directionY * timeScale
);

body.updateBody();

this.physics.checkOne(body, this.checkBounce.bind(this));
}

Expand Down
2 changes: 1 addition & 1 deletion dist/system.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export declare class System<TBody extends Body = Body> extends BaseSystem<TBody>
*/
insert(body: TBody): RBush<TBody>;
/**
* alias for insert, updates body in collision tree
* updates body in collision tree
*/
updateBody(body: TBody): void;
/**
Expand Down
11 changes: 3 additions & 8 deletions dist/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,17 @@ class System extends base_system_1.BaseSystem {
return super.insert(body);
}
/**
* alias for insert, updates body in collision tree
* updates body in collision tree
*/
updateBody(body) {
this.insert(body);
body.updateBody();
}
/**
* update all bodies aabb
*/
update() {
(0, optimized_1.forEach)(this.all(), (body) => {
// no need to every cycle update static body aabb
if (!body.isStatic) {
this.insert(body);
}
this.updateBody(body);
});
}
/**
Expand All @@ -82,8 +79,6 @@ class System extends base_system_1.BaseSystem {
* check one collider collisions with callback
*/
checkOne(body, callback = () => true, response = this.response) {
// first, lazy update body bbox if needed
body.updateBody();
// no need to check static body collision
if (body.isStatic) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions docs/classes/System.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</
<h5><span class="tsd-kind-parameter">response</span>: <a href="Response.html" class="tsd-signature-type tsd-kind-class">Response</a><span class="tsd-signature-symbol"> = ...</span></h5></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L145">src/system.ts:145</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L139">src/system.ts:139</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="checkCollision" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>check<wbr/>Collision</span><a href="#checkCollision" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand All @@ -188,7 +188,7 @@ <h5><span class="tsd-kind-parameter">bodyB</span>: <span class="tsd-signature-ty
<h5><span class="tsd-kind-parameter">response</span>: <a href="Response.html" class="tsd-signature-type tsd-kind-class">Response</a><span class="tsd-signature-symbol"> = ...</span></h5></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L169">src/system.ts:169</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L163">src/system.ts:163</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="checkOne" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>check<wbr/>One</span><a href="#checkOne" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand All @@ -207,7 +207,7 @@ <h5><span class="tsd-kind-parameter">callback</span>: <a href="../types/CheckCol
<h5><span class="tsd-kind-parameter">response</span>: <a href="Response.html" class="tsd-signature-type tsd-kind-class">Response</a><span class="tsd-signature-symbol"> = ...</span></h5></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L116">src/system.ts:116</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L113">src/system.ts:113</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><a id="clear" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>clear</span><a href="#clear" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures tsd-is-inherited tsd-is-external">
Expand Down Expand Up @@ -497,7 +497,7 @@ <h4 class="tsd-parameters-title">Parameters</h4>
<h5><span class="tsd-kind-parameter">body</span>: <span class="tsd-signature-type tsd-kind-type-parameter">TBody</span></h5></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type tsd-kind-type-parameter">TBody</span><span class="tsd-signature-symbol">[]</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L161">src/system.ts:161</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L155">src/system.ts:155</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="insert" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>insert</span><a href="#insert" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand Down Expand Up @@ -570,7 +570,7 @@ <h5><span class="tsd-kind-parameter">body</span>: <span class="tsd-signature-typ
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></li></ul></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><a href="../interfaces/RaycastHit.html" class="tsd-signature-type tsd-kind-interface">RaycastHit</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type tsd-kind-type-parameter">TBody</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L224">src/system.ts:224</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L218">src/system.ts:218</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="remove" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>remove</span><a href="#remove" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand Down Expand Up @@ -631,7 +631,7 @@ <h3 class="tsd-anchor-link"><span>separate</span><a href="#separate" aria-label=
</div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L102">src/system.ts:102</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L99">src/system.ts:99</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member tsd-is-inherited tsd-is-external"><a id="toBBox" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>toBBox</span><a href="#toBBox" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures tsd-is-inherited tsd-is-external">
Expand Down Expand Up @@ -708,7 +708,7 @@ <h5><span class="tsd-kind-parameter">__namedParameters</span>: <span class="tsd-
<h5><code class="tsd-tag ts-flagOptional">Optional</code> <span class="tsd-kind-property">children</span><span class="tsd-signature-symbol">?: </span><a href="../types/Leaf.html" class="tsd-signature-type tsd-kind-type-alias">Leaf</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type tsd-kind-type-parameter">TBody</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">[]</span></h5></li></ul></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type tsd-kind-type-parameter">TBody</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L269">src/system.ts:269</a></li></ul></aside></li></ul></section>
<li>Defined in <a href="https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L263">src/system.ts:263</a></li></ul></aside></li></ul></section>
<section class="tsd-panel tsd-member"><a id="update" class="tsd-anchor"></a>
<h3 class="tsd-anchor-link"><span>update</span><a href="#update" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></h3>
<ul class="tsd-signatures">
Expand All @@ -724,7 +724,7 @@ <h3 class="tsd-anchor-link"><span>update<wbr/>Body</span><a href="#updateBody" a
<ul class="tsd-signatures">
<li class="tsd-signature tsd-anchor-link" id="updateBody.updateBody-1"><span class="tsd-kind-call-signature">update<wbr/>Body</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">body</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span><a href="#updateBody.updateBody-1" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><use href="#icon-anchor-a"></use><use href="#icon-anchor-b"></use><use href="#icon-anchor-c"></use></svg></a></li>
<li class="tsd-description">
<div class="tsd-comment tsd-typography"><p>alias for insert, updates body in collision tree</p>
<div class="tsd-comment tsd-typography"><p>updates body in collision tree</p>
</div>
<div class="tsd-parameters">
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
13 changes: 5 additions & 8 deletions docs/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,20 +1310,17 @@ class System extends base_system_1.BaseSystem {
return super.insert(body);
}
/**
* alias for insert, updates body in collision tree
* updates body in collision tree
*/
updateBody(body) {
this.insert(body);
body.updateBody();
}
/**
* update all bodies aabb
*/
update() {
(0, optimized_1.forEach)(this.all(), (body) => {
// no need to every cycle update static body aabb
if (!body.isStatic) {
this.insert(body);
}
this.updateBody(body);
});
}
/**
Expand All @@ -1342,8 +1339,6 @@ class System extends base_system_1.BaseSystem {
* check one collider collisions with callback
*/
checkOne(body, callback = () => true, response = this.response) {
// first, lazy update body bbox if needed
body.updateBody();
// no need to check static body collision
if (body.isStatic) {
return false;
Expand Down Expand Up @@ -3999,6 +3994,8 @@ class Stress {
body.y + body.directionY * timeScale
);

body.updateBody();

this.physics.checkOne(body, this.checkBounce.bind(this));
}

Expand Down
12 changes: 10 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2>Detect-Collisions</h2></div>
</code><button>Copy</button></pre>
<a id="md:step-2-understand-body-attributes" class="tsd-anchor"></a><h3><a href="#md:step-2-understand-body-attributes">Step 2: Understand Body Attributes</a></h3><p>Bodies have various properties:</p>
<ul>
<li><p><strong>Position Attributes</strong>: <code>pos: Vector</code>, <code>x: number</code>, <code>y: number</code>. Setting <code>body.pos.x</code> or <code>body.pos.y</code> doesn&#39;t update the bounding box while setting <code>body.x</code> or <code>body.y</code> directly does. To set position and update bounding box use <code>setPosition(x, y)</code>.</p>
<li><p><strong>Position Attributes</strong>: <code>pos: Vector</code>, <code>x: number</code>, <code>y: number</code>. Setting <code>body.pos.x</code> or <code>body.pos.y</code> doesn&#39;t update the bounding box while setting <code>body.x</code> or <code>body.y</code> directly does. To set both at the same time, use <code>setPosition(x, y)</code>.</p>
</li>
<li><p><strong>Scale, Offset</strong>: Bodies have <code>scale: number</code> shorthand property and <code>setScale(x, y)</code> method for scaling. The <code>offset: Vector</code> property and <code>setOffset({ x, y }: Vector)</code> method are for offset from body center for rotation purposes.</p>
</li>
Expand Down Expand Up @@ -84,8 +84,16 @@ <h2>Detect-Collisions</h2></div>
<li>Used to position the body&#39;s collision shape more accurately.</li>
</ul>
</li>
<li><p><code>updateBody()</code>:</p>
<ul>
<li>Updates body AABB in collision tree, please call this after all manipulations are done</li>
</ul>
</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>
<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>If you decide to go with <code>body.updateBody()</code> approach just make sure every body has it called after any manipulations, but maybe an easier route is just to call <code>system.update()</code> which will iterate over all bodies and update their bounding box.</p>
<pre><code class="language-ts"><span class="hl-5">system</span><span class="hl-1">.</span><span class="hl-0">update</span><span class="hl-1">()</span>
</code><button>Copy</button></pre>
<p>Check collisions for all bodies or a single body:</p>
<pre><code class="language-ts"><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">/* ... */</span><br/><span class="hl-1">})</span><br/><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">/* ... */</span><br/><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>
Expand Down

0 comments on commit e1fc3d2

Please sign in to comment.