Skip to content

Commit

Permalink
Merge pull request #28 from maxakuru/master
Browse files Browse the repository at this point in the history
check index before remove, check bbox exists in non-updating methods
  • Loading branch information
davidfig authored Feb 5, 2022
2 parents d8eb780 + f4f171e commit 09d1fb6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions code/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export class Simple {
* @return {Array} array
*/
removeList(array: DisplayObjectWithCullingArray): DisplayObjectWithCullingArray {
this.lists.splice(this.lists.indexOf(array), 1)
const index = this.lists.indexOf(array)
if(index === -1){
return array
}
this.lists.splice(index, 1)
return array
}

Expand Down Expand Up @@ -92,7 +96,11 @@ export class Simple {
* @return {DisplayObjectWithCulling} object
*/
remove(object: DisplayObjectWithCulling): DisplayObjectWithCulling {
this.lists[0].splice(this.lists[0].indexOf(object), 1)
const index = this.lists[0].indexOf(object)
if(index === -1){
return object
}
this.lists[0].splice(index, 1)
return object
}

Expand Down Expand Up @@ -174,7 +182,8 @@ export class Simple {
for (let list of this.lists) {
for (let object of list) {
const box = object.AABB
if (box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
if (box &&
box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
box.y + box.height > bounds.y && box.y - box.height < bounds.y + bounds.height) {
results.push(object)
}
Expand All @@ -194,7 +203,8 @@ export class Simple {
for (let list of this.lists) {
for (let object of list) {
const box = object.AABB
if (box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
if (box &&
box.x + box.width > bounds.x && box.x - box.width < bounds.x + bounds.width &&
box.y + box.height > bounds.y && box.y - box.height < bounds.y + bounds.height) {
if (callback(object)) {
return true
Expand Down

0 comments on commit 09d1fb6

Please sign in to comment.