The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  Game::Collisions::AABB

METHODS

new

  new({
      x => 0,
      y => 0,
      length => 4,
      height => 6,
      user_data => ...,
  })

Constructor. user_data can be arbitrary data. Often, this will be the more complex object associated with this AABB.

If user_data inherits from Game::Collisions::UserData, then it will be called whenever the AABB is moved. This will happen after the AABB moves, but before the rest of the tree is updated.

Accessors

Basic accessors for all the data.

x

y

length

height

left_node

right_node

parent

user_data

set_left_node

Pass in the AABB object that will become the left node in the tree. Automatically sets the parent.

set_right_node

Pass in the AABB object that will become the right node in the tree. Automatically sets the parent.

set_user_data

Sets the user data.

set_parent

Pass in the AABB object that will become the parent of this one. Does not set the left or right node on the parent.

resize_all_parents

Walks up the tree from this node to ensure all the parents are big enough to contain their children.

does_collide

Pass in another AABB object. Returns true if it collides with this one.

does_fully_enclose

Pass in another AABB object. Returns true if this object is big enough to completely enclose that object.

find_best_sibling_node

Pass in another AABB object that you plan to add to the tree. Searches the tree from this point down to find the best sibling for that object and returns it.

The definition of "best" is based on the surface area of each node. Less surface area is considered better as we're walking down the tree. In the future, this might take a subref that provides its own definition of "best".

Generally, this is only called on the root of the tree.

is_branch_node

Returns true if this has either a left or right node.

dump_tree

Returns a string that textually represents the tree. Mainly for debugging.

move

Moves the AABB, making sure everything is still consistent in the tree after the move is done.

insert_new_aabb

Passed a new AABB object that we want to add to the tree. Finds the best place for it (see find_best_sibling_node()) and puts it there.

suggested_rotation

Walks the tree to see if we'd be more in balance if it were rotated. Returns -1 if we should be left-rotated, 1 if we should be right-rotated, and 0 if we're in balance and should stay how we are.

remove

Removes this AABB from the tree. As long as you use this method to remove nodes, you shouldn't run into any memory leaks due to circular references.