PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::d2::DynamicTree::TreeNode Class Reference

A node in the dynamic tree. More...

#include <DynamicTree.hpp>

Collaboration diagram for playrho::d2::DynamicTree::TreeNode:
[legend]

Public Member Functions

constexpr TreeNode (const TreeNode &other)=default
 Copy constructor.
 
constexpr TreeNode (TreeNode &&other)=default
 Move constructor.
 
constexpr TreeNode (Size other=DynamicTree::GetInvalidSize()) noexcept
 Initializing constructor.
 
constexpr TreeNode (const LeafData &value, AABB aabb, Size other=DynamicTree::GetInvalidSize()) noexcept
 Initializing constructor.
 
constexpr TreeNode (const BranchData &value, AABB aabb, Height height, Size other=DynamicTree::GetInvalidSize()) noexcept
 Initializing constructor.
 
TreeNodeoperator= (const TreeNode &other)=default
 Copy assignment operator.
 
constexpr Height GetHeight () const noexcept
 Gets the node "height".
 
constexpr Size GetOther () const noexcept
 Gets the node's "other" index.
 
constexpr void SetOther (Size other) noexcept
 Sets the node's "other" index to the given value.
 
constexpr AABB GetAABB () const noexcept
 Gets the node's AABB. More...
 
constexpr void SetAABB (AABB value) noexcept
 Sets the node's AABB. More...
 
constexpr UnusedData AsUnused () const noexcept
 Gets the node as an "unused" value. More...
 
constexpr LeafData AsLeaf () const noexcept
 Gets the node as a "leaf" value. More...
 
constexpr BranchData AsBranch () const noexcept
 Gets the node as a "branch" value. More...
 
constexpr void Assign (const UnusedData &v) noexcept
 Gets the node as an "unused" value.
 
constexpr void Assign (const LeafData &v) noexcept
 Gets the node as a "leaf" value.
 
constexpr void Assign (const BranchData &v, const AABB &bb, Height h) noexcept
 Assigns the node as a "branch" value.
 

Private Attributes

AABB m_aabb
 AABB. More...
 
VariantData m_variant {UnusedData{}}
 Variant data for the node.
 
Height m_height = GetInvalidHeight()
 Height. More...
 
Size m_other = DynamicTree::GetInvalidSize()
 Index to "other" node. More...
 

Related Functions

(Note that these are not member functions.)

constexpr bool IsUnused (const DynamicTree::TreeNode &node) noexcept
 Is unused. More...
 
constexpr bool IsLeaf (const DynamicTree::TreeNode &node) noexcept
 Is leaf. More...
 
constexpr bool IsBranch (const DynamicTree::TreeNode &node) noexcept
 Is branch. More...
 
constexpr bool IsUnused (const DynamicTree::TreeNode &node) noexcept
 Whether this node is free (or allocated).
 
constexpr bool IsLeaf (const DynamicTree::TreeNode &node) noexcept
 Whether or not this node is a leaf node. More...
 
constexpr bool IsBranch (const DynamicTree::TreeNode &node) noexcept
 Is branch. More...
 
constexpr AABB GetAABB (const DynamicTree::TreeNode &node) noexcept
 Gets the AABB of the given dynamic tree node.
 
constexpr DynamicTree::Size GetNext (const DynamicTree::TreeNode &node) noexcept
 Gets the next index of the given node. More...
 

Detailed Description

A node in the dynamic tree.

Note
Users do not interact with this directly.
By using indexes to other tree nodes, these don't need to be updated if the memory for other nodes is relocated.
On some 64-bit architectures, pointers are 8-bytes, while indices need only be 4-bytes. So using indices can also save 4-bytes.
This data structure is 48-bytes large on at least one 64-bit platform.

Member Function Documentation

◆ AsBranch()

constexpr BranchData playrho::d2::DynamicTree::TreeNode::AsBranch ( ) const
inlineconstexprnoexcept

Gets the node as a "branch" value.

Warning
Behavior is undefined unless called on a branch node!

◆ AsLeaf()

constexpr LeafData playrho::d2::DynamicTree::TreeNode::AsLeaf ( ) const
inlineconstexprnoexcept

Gets the node as a "leaf" value.

Warning
Behavior is undefined unless called on a leaf node!

◆ AsUnused()

constexpr UnusedData playrho::d2::DynamicTree::TreeNode::AsUnused ( ) const
inlineconstexprnoexcept

Gets the node as an "unused" value.

Warning
Behavior is undefined unless called on a free/unused node!

◆ GetAABB()

constexpr AABB playrho::d2::DynamicTree::TreeNode::GetAABB ( ) const
inlineconstexprnoexcept

Gets the node's AABB.

Warning
Behavior is undefined if called on a free/unused node!

Referenced by playrho::d2::DynamicTree::RebuildBottomUp().

◆ SetAABB()

constexpr void playrho::d2::DynamicTree::TreeNode::SetAABB ( AABB  value)
inlineconstexprnoexcept

Sets the node's AABB.

Warning
Behavior is undefined if called on a free/unused node!

Referenced by playrho::d2::DynamicTree::UpdateLeaf().

Friends And Related Function Documentation

◆ GetNext()

constexpr DynamicTree::Size GetNext ( const DynamicTree::TreeNode node)
related

Gets the next index of the given node.

Warning
Behavior is undefined if the given node is not an "unused" node.

◆ IsBranch() [1/2]

constexpr bool IsBranch ( const DynamicTree::TreeNode node)
related

Is branch.

Determines whether the given dynamic tree node is a branch node. Branch nodes have 2 indices to child nodes.

Referenced by AsBranch(), and Assign().

◆ IsBranch() [2/2]

constexpr bool IsBranch ( const DynamicTree::TreeNode node)
related

Is branch.

Determines whether the given node is a "branch" node.

◆ IsLeaf() [1/2]

constexpr bool IsLeaf ( const DynamicTree::TreeNode node)
related

Is leaf.

Determines whether the given dynamic tree node is a leaf node.

Referenced by AsLeaf().

◆ IsLeaf() [2/2]

constexpr bool IsLeaf ( const DynamicTree::TreeNode node)
related

Whether or not this node is a leaf node.

Note
This has constant complexity.
Returns
true if this is a leaf node, false otherwise.

◆ IsUnused()

constexpr bool IsUnused ( const DynamicTree::TreeNode node)
related

Is unused.

Determines whether the given dynamic tree node is an unused node.

Referenced by AsUnused(), GetAABB(), and SetAABB().

Member Data Documentation

◆ m_aabb

AABB playrho::d2::DynamicTree::TreeNode::m_aabb
private

AABB.

Note
This field is unused for free nodes, else it's the minimally enclosing AABB for the node.

Referenced by Assign(), GetAABB(), and SetAABB().

◆ m_height

Height playrho::d2::DynamicTree::TreeNode::m_height = GetInvalidHeight()
private

Height.

"Height" for tree balancing.

Note
0 if leaf node, DynamicTree::GetInvalidHeight() if free (unallocated) node, else branch node.

Referenced by AsBranch(), AsLeaf(), Assign(), AsUnused(), GetAABB(), GetHeight(), and SetAABB().

◆ m_other

Size playrho::d2::DynamicTree::TreeNode::m_other = DynamicTree::GetInvalidSize()
private

Index to "other" node.

Note
This is an index to the next node for a free node, else this is the index to the parent node. Index of another node.

Referenced by GetOther(), and SetOther().


The documentation for this class was generated from the following file: