Skip to content

Commit

Permalink
Add Self typedef to Node
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 13, 2020
1 parent f622683 commit 6eb55ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Octree/include/CGAL/Octree/Node.h
Expand Up @@ -41,10 +41,12 @@ class Node {
/// \name Types
/// @{

typedef Node<Point_index> Self;

/*!
* \brief array for containing the child nodes of this node
*/
typedef std::array<Node<Point_index>, 8> Children;
typedef std::array<Self, 8> Children;

/*!
* \brief set of bits representing this node's relationship to its parent
Expand Down Expand Up @@ -78,7 +80,7 @@ class Node {

Point_range m_points;

const Node<Point_index> *m_parent;
const Self *m_parent;

uint8_t m_depth;

Expand All @@ -104,7 +106,7 @@ class Node {
* \param parent A reference to the node containing this one
* \param index This node's relationship to its parent
*/
explicit Node(Node<Point_index> *parent = nullptr, Index index = 0) : m_parent(parent), m_depth(0),
explicit Node(Self *parent = nullptr, Index index = 0) : m_parent(parent), m_depth(0),
m_location({0, 0, 0}) {

if (parent) {
Expand Down Expand Up @@ -138,7 +140,7 @@ class Node {
m_children = std::make_unique<Children>();
for (int index = 0; index < 8; index++) {

(*m_children)[index] = std::move(Node<Point_index>(this, {Index(index)}));
(*m_children)[index] = std::move(Self(this, {Index(index)}));
}
}

Expand Down Expand Up @@ -172,7 +174,7 @@ class Node {
* \param index The index of the child node, as an int
* \return A reference to the node
*/
Node<Point_index> &operator[](int index) {
Self &operator[](int index) {

assert(!is_leaf());
assert(0 <= index && index < 8);
Expand All @@ -186,7 +188,7 @@ class Node {
* \param index The index of the child node, as an int
* \return A const reference to the node
*/
const Node<Point_index> &operator[](int index) const {
const Self &operator[](int index) const {

assert(!is_leaf());
assert(0 <= index && index < 8);
Expand All @@ -211,7 +213,7 @@ class Node {
*
* \return A const pointer to the parent of this node (possibly nullptr)
*/
const Node<Point_index> *parent() const { return m_parent; }
const Self *parent() const { return m_parent; }

/*!
* \brief retrieve this node's depth in the tree
Expand Down Expand Up @@ -336,7 +338,7 @@ class Node {
return !operator==(rhs);
}

const Node<Point_index> *adjacent(std::bitset<3> direction) const {
const Self *adjacent(std::bitset<3> direction) const {

// Nodes only have up to 6 different adjacent nodes (since cubes have 6 sides)
assert(direction.to_ulong() < 6);
Expand Down
6 changes: 6 additions & 0 deletions Octree/test/Octree/test_node_adjacent.cpp
Expand Up @@ -50,6 +50,12 @@ int main(void) {
assert(nullptr == octree.root().adjacent(5));

// Left Top Front node should have siblings to the Right, Down, and Back
auto &left_top_front = octree.root()[2];
assert(nullptr != left_top_front.adjacent(1));
assert(nullptr != left_top_front.adjacent(2));
assert(nullptr != left_top_front.adjacent(4));

std::cout << left_top_front;

return 0;
}

0 comments on commit 6eb55ec

Please sign in to comment.