QuadTree

class QuadTree

a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.

See: game.world.broadphase

Constructor


new QuadTree(world: World, bounds: Bounds, max_objects: number, max_levels: number, level: number) → {}
Parameters:
Name Type Attributes Default Description
world World

the physic world this QuadTree belongs to

bounds Bounds

bounds of the node

max_objects number

<optional>

4

max objects a node can hold before splitting into 4 subnodes

max_levels number

<optional>

4

total max levels inside root Quadtree

level number

<optional>

0

deepth level, required for subnodes

Public Methods


clear quadtree.js:371
clear(bounds: Bounds) → {}

clear the quadtree

Parameters:
Name Type Attributes Default Description
bounds Bounds

<optional>

this.bounds

the bounds to be cleared

hasChildren quadtree.js:355
hasChildren() → {boolean}

return true if the node has any children

Returns:
Type Description
boolean

true if the node has any children

insert quadtree.js:224
insert(item: object) → {}

Insert the given object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.

Parameters:
Name Type Description
item object

object to be added

insertContainer quadtree.js:196
insertContainer(container: Container) → {}

Insert the given object container into the node.

Parameters:
Name Type Description
container Container

group of objects to be added

isPrunable quadtree.js:345
isPrunable() → {boolean}

return true if the node is prunable

Returns:
Type Description
boolean

true if the node is prunable

remove quadtree.js:304
remove(item: object) → {boolean}

Remove the given item from the quadtree. (this function won't recalculate the impacted node)

Parameters:
Name Type Description
item object

object to be removed

Returns:
Type Description
boolean

true if the item was found and removed.

retrieve quadtree.js:270
retrieve(item: object, fn: object) → {Array<object>}

Return all objects that could collide with the given object

Parameters:
Name Type Attributes Description
item object

object to be checked against

fn object

<optional>

a sorting function for the returned array

Returns:
Type Description
Array<object>

array with all detected objects


Powered by webdoc!