Skip to content

Commit

Permalink
fix: Issue with sparse hash grid not using the correct bounds sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 27, 2024
1 parent 4f995c5 commit 94f38fa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/engine/Collision/Detection/SparseHashGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export class HashGridProxy<T extends { bounds: BoundingBox }> {
}
}

/**
* Update bounds of the proxy
*/
updateBounds(): void {
this.bounds = this.object.bounds;
}

/**
* Updates the hashed bounds coordinates
*/
Expand Down Expand Up @@ -153,6 +160,7 @@ export class SparseHashGrid<TObject extends { bounds: BoundingBox }, TProxy exte
const cell = this.sparseHashGrid.get(key);
if (cell) {
for (let i = 0; i < cell.proxies.length; i++) {
cell.proxies[i].updateBounds();
if (cell.proxies[i].bounds.intersect(bounds)) {
results.add(cell.proxies[i].object);
}
Expand All @@ -167,6 +175,7 @@ export class SparseHashGrid<TObject extends { bounds: BoundingBox }, TProxy exte
const cell = this.sparseHashGrid.get(key);
if (cell) {
for (let i = 0; i < cell.proxies.length; i++) {
cell.proxies[i].updateBounds();
if (cell.proxies[i].bounds.contains(point)) {
results.add(cell.proxies[i].object);
}
Expand Down

0 comments on commit 94f38fa

Please sign in to comment.