21#ifndef GF_RANDOM_BINARY_TREE_H
22#define GF_RANDOM_BINARY_TREE_H
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
56 Node(
const RectI& area, std::size_t parent,
int level)
85 return m_left == 0 && m_right == 0;
132 return m_area.contains(position);
147 std::size_t m_parent;
218 return getRoot().contains(position);
281 std::vector<Node> m_nodes;
284#ifndef DOXYGEN_SHOULD_SKIP_THIS
A node of the random binary space partionning tree.
Definition: RandomBinaryTree.h:47
int getLevel() const
Get the level of the node in the tree.
Definition: RandomBinaryTree.h:73
bool contains(Vector2i position) const
Check if the area of the node contains a position.
Definition: RandomBinaryTree.h:131
const RectI & getArea() const
Get the area of the node.
Definition: RandomBinaryTree.h:122
std::size_t getParentIndex() const
Get the parent's indes of the node.
Definition: RandomBinaryTree.h:95
bool isLeaf() const
Check if a node is a leaf.
Definition: RandomBinaryTree.h:84
std::size_t getRightChildIndex() const
Get the right child's index.
Definition: RandomBinaryTree.h:113
std::size_t getLeftChildIndex() const
Get the left child's index.
Definition: RandomBinaryTree.h:104
void setChildrenIndices(std::size_t left, std::size_t right)
Set the children indices of the node.
Definition: RandomBinaryTree.h:141
Node(const RectI &area, std::size_t parent, int level)
Constructor.
Definition: RandomBinaryTree.h:56
A random binary space partionning tree.
Definition: RandomBinaryTree.h:41
const Node & getRoot() const
Get the root node of the tree.
bool traverseInOrder(Callback callback) const
Traverse the nodes in in-order.
bool traverseLevelOrder(Callback callback) const
Traverse the nodes in level-order.
const Node & find(Vector2i position) const
Find the deepest node containing a position.
bool traverseInvertedLevelOrder(Callback callback) const
Traverse the nodes in inverted level-order.
const Node & getParent(const Node &node) const
Get the parent of the node.
bool traversePreOrder(Callback callback) const
Traverse the nodes in pre-order.
std::function< bool(const RandomBinaryTree &, const Node &)> Callback
A callback function for traversing the tree.
Definition: RandomBinaryTree.h:160
bool traversePostOrder(Callback callback) const
Traverse the nodes in post-order.
RandomBinaryTree(const RectI &area)
Constructor.
void create(Random &random, int levelMax, Vector2i minSize, Vector2i maxSize, float maxRatio=1.5f)
Create the BSP tree.
const Node & getRightChild(const Node &node) const
Get the right child of a node.
const Node & getLeftChild(const Node &node) const
Get the left child of a node.
bool contains(Vector2i position) const
Check if the tree contains a position.
Definition: RandomBinaryTree.h:217
A set of random utilities.
Definition: Random.h:83
The namespace for gf classes.