mirror of https://github.com/CGAL/cgal
Node parent access is now done through the tree
This commit is contained in:
parent
45244da9e1
commit
6dec072b00
|
|
@ -396,7 +396,7 @@ public:
|
||||||
|
|
||||||
// Skip if this neighbor is a direct sibling (it's guaranteed to be the same depth)
|
// Skip if this neighbor is a direct sibling (it's guaranteed to be the same depth)
|
||||||
// TODO: This check might be redundant, if it doesn't affect performance maybe I could remove it
|
// TODO: This check might be redundant, if it doesn't affect performance maybe I could remove it
|
||||||
if (neighbor->parent() == node->parent())
|
if (&parent(*neighbor) == &parent(*node))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If it's already been split, skip it
|
// If it's already been split, skip it
|
||||||
|
|
@ -639,6 +639,20 @@ public:
|
||||||
/// \name Node Access
|
/// \name Node Access
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief returns this node's parent.
|
||||||
|
\pre `!is_root()`
|
||||||
|
*/
|
||||||
|
const Node& parent(const Node& node) const {
|
||||||
|
CGAL_precondition (!node.is_root());
|
||||||
|
return *node.m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node& parent(Node& node) {
|
||||||
|
CGAL_precondition (!node.is_root());
|
||||||
|
return *node.m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
using Children = typename Node::Children;
|
using Children = typename Node::Children;
|
||||||
|
|
||||||
Children& children(Node& node) {
|
Children& children(Node& node) {
|
||||||
|
|
@ -836,11 +850,11 @@ public:
|
||||||
// Check if this child has the opposite sign along the direction's axis
|
// Check if this child has the opposite sign along the direction's axis
|
||||||
if (node.local_coordinates()[dimension] != sign) {
|
if (node.local_coordinates()[dimension] != sign) {
|
||||||
// This means the adjacent node is a direct sibling, the offset can be applied easily!
|
// This means the adjacent node is a direct sibling, the offset can be applied easily!
|
||||||
return &children(*node.parent())[node.local_coordinates().to_ulong() + offset];
|
return &children(parent(node))[node.local_coordinates().to_ulong() + offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the parent's neighbor in that direction, if it exists
|
// Find the parent's neighbor in that direction, if it exists
|
||||||
const Node* adjacent_node_of_parent = adjacent_node(*node.parent(), direction);
|
const Node* adjacent_node_of_parent = adjacent_node(parent(node), direction);
|
||||||
|
|
||||||
// If the parent has no neighbor, then this node doesn't have one
|
// If the parent has no neighbor, then this node doesn't have one
|
||||||
if (adjacent_node_of_parent == nullptr) return nullptr;
|
if (adjacent_node_of_parent == nullptr) return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -226,20 +226,6 @@ public:
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// \name Adjacency
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief returns this node's parent.
|
|
||||||
\pre `!is_root()`
|
|
||||||
*/
|
|
||||||
const Self* parent() const {
|
|
||||||
CGAL_precondition (!is_root());
|
|
||||||
return m_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
/// \name Point Range
|
/// \name Point Range
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ namespace Orthtrees {
|
||||||
// todo: all of these could be members of Orthtree
|
// todo: all of these could be members of Orthtree
|
||||||
|
|
||||||
template <typename Tree>
|
template <typename Tree>
|
||||||
const typename Tree::Node* next_sibling(const Tree &orthtree, const typename Tree::Node* n) {
|
const typename Tree::Node* next_sibling(const Tree& orthtree, const typename Tree::Node* n) {
|
||||||
|
|
||||||
// Passing null returns the first node
|
// todo: maybe this should take a reference?
|
||||||
if (nullptr == n)
|
if (nullptr == n)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
@ -55,30 +55,29 @@ const typename Tree::Node* next_sibling(const Tree &orthtree, const typename Tre
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// Otherwise, return the next child
|
// Otherwise, return the next child
|
||||||
return &(orthtree.children(*n->parent())[index + 1]);
|
return &(orthtree.children(orthtree.parent(*n))[index + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tree>
|
template <typename Tree>
|
||||||
const typename Tree::Node* next_sibling_up(const Tree &orthtree, const typename Tree::Node* n) {
|
const typename Tree::Node* next_sibling_up(const Tree& orthtree, const typename Tree::Node* n) {
|
||||||
|
|
||||||
if (!n || n->is_root()) return nullptr;
|
if (!n || n->is_root()) return nullptr;
|
||||||
|
|
||||||
auto up = n->parent();
|
auto up = &orthtree.parent(*n);
|
||||||
while (nullptr != up) {
|
while (nullptr != up) {
|
||||||
|
|
||||||
if (nullptr != next_sibling(orthtree, up))
|
if (nullptr != next_sibling(orthtree, up))
|
||||||
return next_sibling(orthtree, up);
|
return next_sibling(orthtree, up);
|
||||||
|
|
||||||
if (up->is_root()) return nullptr;
|
// todo: this could be cleaned up; it's probably not necessary to involve pointers here
|
||||||
|
up = up->is_root() ? nullptr : &orthtree.parent(*up);
|
||||||
up = up->parent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tree>
|
template <typename Tree>
|
||||||
const typename Tree::Node* deepest_first_child(const Tree &orthtree, const typename Tree::Node* n) {
|
const typename Tree::Node* deepest_first_child(const Tree& orthtree, const typename Tree::Node* n) {
|
||||||
|
|
||||||
if (n == nullptr)
|
if (n == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -92,7 +91,7 @@ const typename Tree::Node* deepest_first_child(const Tree &orthtree, const typen
|
||||||
|
|
||||||
|
|
||||||
template <typename Tree>
|
template <typename Tree>
|
||||||
const typename Tree::Node* first_child_at_depth(const Tree &orthtree, const typename Tree::Node* n, std::size_t depth) {
|
const typename Tree::Node* first_child_at_depth(const Tree& orthtree, const typename Tree::Node* n, std::size_t depth) {
|
||||||
|
|
||||||
if (!n)
|
if (!n)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue