mirror of https://github.com/CGAL/cgal
adjacent_node() now returns an optional index
This commit is contained in:
parent
825abd1727
commit
d761f6ebc0
|
|
@ -392,7 +392,7 @@ public:
|
|||
for (int direction = 0; direction < 6; ++direction) {
|
||||
|
||||
// Get the neighbor
|
||||
auto neighbor = index(adjacent_node(node, direction));
|
||||
auto neighbor = adjacent_node(node, direction);
|
||||
|
||||
// If it doesn't exist, skip it
|
||||
if (!neighbor)
|
||||
|
|
@ -977,8 +977,8 @@ public:
|
|||
|
||||
}
|
||||
|
||||
const Node* adjacent_node(Node_index n, typename Node::Local_coordinates direction) const {
|
||||
return adjacent_node(m_nodes[n], direction);
|
||||
boost::optional<Node_index> adjacent_node(Node_index n, typename Node::Local_coordinates direction) const {
|
||||
return {index(adjacent_node(m_nodes[n], direction))};
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -988,10 +988,6 @@ public:
|
|||
return adjacent_node(node, std::bitset<Dimension::value>(static_cast<int>(adjacency)));
|
||||
}
|
||||
|
||||
const Node* adjacent_node(Node_index n, typename Node::Adjacency adjacency) const {
|
||||
return adjacent_node(m_nodes[n], adjacency);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief equivalent to adjacent_node, except non-const
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -42,39 +42,47 @@ int main(void) {
|
|||
std::cout << octree << std::endl;
|
||||
|
||||
// Root node should have no siblings
|
||||
assert(octree.adjacent_node(octree.root(), 0) == nullptr);
|
||||
assert(octree.adjacent_node(octree.root(), 1) == nullptr);
|
||||
assert(octree.adjacent_node(octree.root(), 2) == nullptr);
|
||||
assert(octree.adjacent_node(octree.root(), 3) == nullptr);
|
||||
assert(octree.adjacent_node(octree.root(), 4) == nullptr);
|
||||
assert(octree.adjacent_node(octree.root(), 5) == nullptr);
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 0));
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 1));
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 2));
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 3));
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 4));
|
||||
assert(!octree.adjacent_node(octree.index(octree.root()), 5));
|
||||
|
||||
// Left Top Front node should have siblings to the Right, Down, and Back
|
||||
auto left_top_back = octree.children(octree.root())[Traits::LEFT_TOP_BACK];
|
||||
auto left_top_back = octree.index(octree.children(octree.root())[Traits::LEFT_TOP_BACK]);
|
||||
|
||||
assert(&octree.children(octree.root())[Traits::RIGHT_TOP_BACK] == octree.adjacent_node(left_top_back, Traits::RIGHT));
|
||||
assert(octree.index(&octree.children(octree.root())[Traits::RIGHT_TOP_BACK]) ==
|
||||
octree.adjacent_node(left_top_back, Traits::RIGHT));
|
||||
assert(
|
||||
&octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK] == octree.adjacent_node(left_top_back, Traits::DOWN));
|
||||
assert(&octree.children(octree.root())[Traits::LEFT_TOP_FRONT] == octree.adjacent_node(left_top_back, Traits::FRONT));
|
||||
assert(octree.adjacent_node(left_top_back, Traits::LEFT) == nullptr);
|
||||
assert(octree.adjacent_node(left_top_back, Traits::UP) == nullptr);
|
||||
assert(octree.adjacent_node(left_top_back, Traits::BACK) == nullptr);
|
||||
octree.index(&octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK]) ==
|
||||
octree.adjacent_node(left_top_back, Traits::DOWN));
|
||||
assert(octree.index(&octree.children(octree.root())[Traits::LEFT_TOP_FRONT]) ==
|
||||
octree.adjacent_node(left_top_back, Traits::FRONT));
|
||||
assert(!octree.adjacent_node(left_top_back, Traits::LEFT));
|
||||
assert(!octree.adjacent_node(left_top_back, Traits::UP));
|
||||
assert(!octree.adjacent_node(left_top_back, Traits::BACK));
|
||||
|
||||
std::cout << octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK] << std::endl;
|
||||
|
||||
auto right_top_back_of_left_bottom_back =
|
||||
octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::RIGHT_TOP_BACK];
|
||||
assert(&octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::LEFT_TOP_BACK] ==
|
||||
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::LEFT));
|
||||
assert(&octree.children(octree.root())[Traits::RIGHT_BOTTOM_BACK] ==
|
||||
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT));
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT) != nullptr);
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::UP) != nullptr);
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::DOWN) != nullptr);
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::FRONT) != nullptr);
|
||||
octree.index(octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::RIGHT_TOP_BACK]);
|
||||
|
||||
assert(
|
||||
octree.index(&octree.children(octree.children(octree.root())[Traits::LEFT_BOTTOM_BACK])[Traits::LEFT_TOP_BACK]) ==
|
||||
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::LEFT)
|
||||
);
|
||||
assert(
|
||||
octree.index(&octree.children(octree.root())[Traits::RIGHT_BOTTOM_BACK]) ==
|
||||
octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT)
|
||||
);
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::RIGHT).has_value());
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::UP).has_value());
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::DOWN).has_value());
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::FRONT).has_value());
|
||||
|
||||
// A node at the back of the tree should have no neighbor to its back
|
||||
assert(octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::BACK) == nullptr);
|
||||
assert(!octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::BACK));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue