![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A random binary space partionning tree. More...
#include <gf/RandomBinaryTree.h>
Classes | |
| class | Node |
| A node of the random binary space partionning tree. More... | |
Public Types | |
| using | Callback = std::function< bool(const RandomBinaryTree &, const Node &)> |
| A callback function for traversing the tree. More... | |
Public Member Functions | |
| RandomBinaryTree (const RectI &area) | |
| Constructor. More... | |
| void | create (Random &random, int levelMax, Vector2i minSize, Vector2i maxSize, float maxRatio=1.5f) |
| Create the BSP tree. More... | |
| const Node & | getRoot () const |
| Get the root node of the tree. More... | |
| const Node & | getLeftChild (const Node &node) const |
| Get the left child of a node. More... | |
| const Node & | getRightChild (const Node &node) const |
| Get the right child of a node. More... | |
| const Node & | getParent (const Node &node) const |
| Get the parent of the node. More... | |
| bool | contains (Vector2i position) const |
| Check if the tree contains a position. More... | |
| const Node & | 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... | |
A random binary space partionning tree.
| using gf::RandomBinaryTree::Callback = std::function<bool(const RandomBinaryTree&, const Node&)> |
A callback function for traversing the tree.
The function returns a boolean indicating if the traversal can continue.
| gf::RandomBinaryTree::RandomBinaryTree | ( | const RectI & | area | ) |
Constructor.
| area | The area to split for this node |
|
inline |
Check if the tree contains a position.
| position | The position to check |
| void gf::RandomBinaryTree::create | ( | Random & | random, |
| int | levelMax, | ||
| Vector2i | minSize, | ||
| Vector2i | maxSize, | ||
| float | maxRatio = 1.5f |
||
| ) |
Create the BSP tree.
| 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 |
Find the deepest node containing a position.
An exception is thrown if the position is outside the tree.
| position | The position to find |
Get the left child of a node.
Get the parent of the node.
The root ot the tree is its own parent.
Get the right child of a node.
| const Node & gf::RandomBinaryTree::getRoot | ( | ) | const |
Get the root node of the tree.
The root node always exist.
| bool gf::RandomBinaryTree::traverseInOrder | ( | Callback | callback | ) | const |
Traverse the nodes in in-order.
| callback | A function to call on each node |
| bool gf::RandomBinaryTree::traverseInvertedLevelOrder | ( | Callback | callback | ) | const |
Traverse the nodes in inverted level-order.
| callback | A function to call on each node |
| bool gf::RandomBinaryTree::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::RandomBinaryTree::traversePostOrder | ( | Callback | callback | ) | const |
Traverse the nodes in post-order.
| callback | A function to call on each node |
| bool gf::RandomBinaryTree::traversePreOrder | ( | Callback | callback | ) | const |
Traverse the nodes in pre-order.
| callback | A function to call on each node |