![]() |
Gamedev Framework (gf)
0.6.0
A C++11 framework for 2D games
|
Binary space random partionning tree. More...
#include <gf/SpaceTree.h>
Public Types | |
| using | Callback = std::function< bool(const SpaceTree &)> |
| A callback function for traversing the tree. More... | |
Public Member Functions | |
| SpaceTree (const RectI &area) | |
| Constructor. More... | |
| const RectI & | getArea () const |
| Get the area of the node. More... | |
| int | getLevel () const |
| Get the level of the node in the tree. More... | |
| void | removeChildren () |
| Remove the children of the node. More... | |
| bool | splitOnce (Random &random, Vector2i minSize, float maxRatio=1.5f) |
| Split the node once. More... | |
| void | splitRecursive (Random &random, int levelMax, Vector2i minSize, Vector2i maxSize, float maxRatio=1.5f) |
| Split a node recursively. More... | |
| bool | isLeaf () const |
| Check if a node is a leaf. More... | |
| const SpaceTree * | getLeftChild () const |
| Get the left child. More... | |
| const SpaceTree * | getRightChild () const |
| Get the right child. More... | |
| const SpaceTree * | getFather () const |
| Get the father of the node. More... | |
| bool | contains (Vector2i position) const |
| Check if the area of the node contains a position. More... | |
| const SpaceTree * | find (Vector2i position) const |
| Find the deepest node containing a position. More... | |
| bool | traversePreOrder (Callback callback) const |
| Traverse the nodes in pre-order. More... | |
| bool | traverseInOrder (Callback callback) const |
| Traverse the nodes in in-order. More... | |
| bool | traversePostOrder (Callback callback) const |
| Traverse the nodes in post-order. More... | |
| bool | traverseLevelOrder (Callback callback) const |
| Traverse the nodes in level-order. More... | |
| bool | traverseInvertedLevelOrder (Callback callback) const |
| Traverse the nodes in inverted level-order. More... | |
Binary space random partionning tree.
This class implements a random binary space partitioning tree. More precisely, this class is a node in the tree.
| using gf::SpaceTree::Callback = std::function<bool(const SpaceTree&)> |
A callback function for traversing the tree.
The function returns a boolean indicating if the traversal can continue.
| gf::SpaceTree::SpaceTree | ( | const RectI & | area | ) |
Constructor.
| area | The area to split for this node |
| bool gf::SpaceTree::contains | ( | Vector2i | position | ) | const |
Check if the area of the node contains a position.
| position | The position to check |
Find the deepest node containing a position.
| position | The position to find |
nullptr if the position is outside the tree
|
inline |
Get the area of the node.
|
inline |
Get the father of the node.
The root of the tree has no father.
|
inline |
Get the left child.
nullptr
|
inline |
Get the level of the node in the tree.
The root of the tree is at level 0, its children at level 1, etc.
|
inline |
Get the right child.
nullptr
|
inline |
Check if a node is a leaf.
A leaf has no children.
| void gf::SpaceTree::removeChildren | ( | ) |
Remove the children of the node.
Split the node once.
This function may create two children if the conditions are met.
| random | A random generator |
| minSize | The minimum size under which a node cannot be split |
| maxRatio | The maximum ratio between the width and height |
| void gf::SpaceTree::splitRecursive | ( | Random & | random, |
| int | levelMax, | ||
| Vector2i | minSize, | ||
| Vector2i | maxSize, | ||
| float | maxRatio = 1.5f |
||
| ) |
Split a node recursively.
| random | A random generator |
| levelMax | The maximum level of a node |
| minSize | The minimum size under which a node cannot be split |
| maxSize | The maximum size over which a node must be split |
| maxRatio | The maximum ratio between the width and height |
| bool gf::SpaceTree::traverseInOrder | ( | Callback | callback | ) | const |
Traverse the nodes in in-order.
| callback | A function to call on each node |
| bool gf::SpaceTree::traverseInvertedLevelOrder | ( | Callback | callback | ) | const |
Traverse the nodes in inverted level-order.
| callback | A function to call on each node |
| bool gf::SpaceTree::traverseLevelOrder | ( | Callback | callback | ) | const |
Traverse the nodes in level-order.
Level-order is also known as breadth first search
| callback | A function to call on each node |
| bool gf::SpaceTree::traversePostOrder | ( | Callback | callback | ) | const |
Traverse the nodes in post-order.
| callback | A function to call on each node |
| bool gf::SpaceTree::traversePreOrder | ( | Callback | callback | ) | const |
Traverse the nodes in pre-order.
| callback | A function to call on each node |
1.8.13