diff --git a/Orthtree/include/CGAL/Orthtree.h b/Orthtree/include/CGAL/Orthtree.h index 4ee5f787650..dce5637e089 100644 --- a/Orthtree/include/CGAL/Orthtree.h +++ b/Orthtree/include/CGAL/Orthtree.h @@ -247,7 +247,7 @@ public: // save orthtree attributes m_bbox_min = construct_point_d_from_array(bbox_min); m_side_per_depth.push_back(bbox_max[0] - bbox_min[0]); - points(index(root())) = {point_range.begin(), point_range.end()}; + points(root()) = {point_range.begin(), point_range.end()}; } /// @} @@ -436,15 +436,8 @@ public: \return a const reference to the root node of the tree. */ - const Node& root() const { return m_nodes[0]; } - - /*! - \brief provides read-write access to the root node, and by - extension the rest of the tree. - - \return a reference to the root node of the tree. - */ - Node& root() { return m_nodes[0]; } + // todo: return index instead of ref + Node_index root() const { return 0; } Node_index index(const Node& node) const { return std::distance(m_nodes.data(), &node); @@ -571,7 +564,7 @@ public: CGAL_precondition (CGAL::do_intersect(point, bbox(root()))); // Start at the root node - Node_index node_for_point = index(root()); + Node_index node_for_point = root(); // Descend the tree until reaching a leaf node while (!is_leaf(node_for_point)) { @@ -643,7 +636,7 @@ public: */ template OutputIterator intersected_nodes(const Query& query, OutputIterator output) const { - return intersected_nodes_recursive(query, index(root()), output); + return intersected_nodes_recursive(query, root(), output); } /// @} @@ -716,16 +709,6 @@ public: \brief returns this node's parent. \pre `!is_root()` */ - const Node& parent(const Node& node) const { - CGAL_precondition (!node.is_root()); - return m_nodes[node.m_parent_index.get()]; - } - - Node& parent(Node& node) { - CGAL_precondition (!node.is_root()); - return m_nodes[node.m_parent_index.get()]; - } - Node_index parent(Node_index node) const { CGAL_precondition (!is_root(node)); return m_nodes[node].m_parent_index.get(); @@ -736,10 +719,6 @@ public: return m_nodes[node].m_children_index.get() + i; } - // todo: these types can probably be moved out of Node - using Children = typename Node::Children; - using Children_const = typename Node::Children_const; - const boost::optional next_sibling(Node_index n) const { // Root node has no siblings @@ -883,7 +862,7 @@ public: } static bool is_topology_equal(const Self& lhs, const Self& rhs) { - return is_topology_equal(lhs.index(lhs.root()), lhs, rhs.index(rhs.root()), rhs); + return is_topology_equal(lhs.root(), lhs, rhs.root(), rhs); } /*! @@ -1176,7 +1155,7 @@ private: // functions : points_list.reserve(k); // Invoking the recursive function adds those points to the vector (passed by reference) - nearest_k_neighbors_recursive(query_sphere, index(root()), points_list); + nearest_k_neighbors_recursive(query_sphere, root(), points_list); // Add all the points found to the output for (auto& item: points_list) diff --git a/Orthtree/include/CGAL/Orthtree/Traversals.h b/Orthtree/include/CGAL/Orthtree/Traversals.h index ab224840442..3c5cf2dc43f 100644 --- a/Orthtree/include/CGAL/Orthtree/Traversals.h +++ b/Orthtree/include/CGAL/Orthtree/Traversals.h @@ -52,11 +52,11 @@ public: Preorder_traversal(const Tree& orthtree) : m_orthtree(orthtree) {} const Node* first() const { - return &m_orthtree.root(); + return &m_orthtree[m_orthtree.root()]; } typename Tree::Node_index first_index() const { - return m_orthtree.index(first()).get(); + return m_orthtree.root(); } const Node* next(const Node* n) const { @@ -210,7 +210,7 @@ public: typename Tree::Node_index first_index() const { // assumes the tree has at least one child at m_depth - return m_orthtree.first_child_at_depth(m_orthtree.index(m_orthtree.root()), m_depth).get(); + return m_orthtree.first_child_at_depth(m_orthtree.root(), m_depth).get(); } template diff --git a/Orthtree/test/Orthtree/test_node_adjacent.cpp b/Orthtree/test/Orthtree/test_node_adjacent.cpp index cb248b0425a..a150f458121 100644 --- a/Orthtree/test/Orthtree/test_node_adjacent.cpp +++ b/Orthtree/test/Orthtree/test_node_adjacent.cpp @@ -42,37 +42,37 @@ int main(void) { std::cout << octree << std::endl; // Root node should have no siblings - 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)); + assert(!octree.adjacent_node(octree.root(), 0)); + assert(!octree.adjacent_node(octree.root(), 1)); + assert(!octree.adjacent_node(octree.root(), 2)); + assert(!octree.adjacent_node(octree.root(), 3)); + assert(!octree.adjacent_node(octree.root(), 4)); + assert(!octree.adjacent_node(octree.root(), 5)); // Left Top Front node should have siblings to the Right, Down, and Back - auto left_top_back = octree.child(octree.index(octree.root()), Traits::LEFT_TOP_BACK); + auto left_top_back = octree.child(octree.root(), Traits::LEFT_TOP_BACK); - assert(octree.child(octree.index(octree.root()), Traits::RIGHT_TOP_BACK) == + assert(octree.child(octree.root(), Traits::RIGHT_TOP_BACK) == octree.adjacent_node(left_top_back, Traits::RIGHT).get()); - assert(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK) == + assert(octree.child(octree.root(), Traits::LEFT_BOTTOM_BACK) == octree.adjacent_node(left_top_back, Traits::DOWN).get()); - assert(octree.child(octree.index(octree.root()), Traits::LEFT_TOP_FRONT) == + assert(octree.child(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[octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK)] << std::endl; + std::cout << octree[octree.child(octree.root(), Traits::LEFT_BOTTOM_BACK)] << std::endl; auto right_top_back_of_left_bottom_back = - octree.child(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK), Traits::RIGHT_TOP_BACK); + octree.child(octree.child(octree.root(), Traits::LEFT_BOTTOM_BACK), Traits::RIGHT_TOP_BACK); assert( - octree.child(octree.child(octree.index(octree.root()), Traits::LEFT_BOTTOM_BACK), Traits::LEFT_TOP_BACK) == + octree.child(octree.child(octree.root(), Traits::LEFT_BOTTOM_BACK), Traits::LEFT_TOP_BACK) == octree.adjacent_node(right_top_back_of_left_bottom_back, Traits::LEFT) ); assert( - octree.child(octree.index(octree.root()), Traits::RIGHT_BOTTOM_BACK) == + octree.child(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()); diff --git a/Orthtree/test/Orthtree/test_node_index.cpp b/Orthtree/test/Orthtree/test_node_index.cpp index db4c8ca2170..34e6f24f5c6 100644 --- a/Orthtree/test/Orthtree/test_node_index.cpp +++ b/Orthtree/test/Orthtree/test_node_index.cpp @@ -37,11 +37,11 @@ int main(void) { Octree octree(points, points.point_map()); octree.refine(10, 1); - std::cout << "root: " << octree.local_coordinates(octree.index(octree.root())) << std::endl; - std::cout << "first child: " << octree.local_coordinates(octree.child(octree.index(octree.root()), 0)) << std::endl; - std::cout << "fifth child: " << octree.local_coordinates(octree.child(octree.index(octree.root()), 4)) << std::endl; + std::cout << "root: " << octree.local_coordinates(octree.root()) << std::endl; + std::cout << "first child: " << octree.local_coordinates(octree.child(octree.root(), 0)) << std::endl; + std::cout << "fifth child: " << octree.local_coordinates(octree.child(octree.root(), 4)) << std::endl; std::cout << "fifth child of first child: " - << octree.local_coordinates(octree.child(octree.child(octree.index(octree.root()), 0), 4)) << std::endl; + << octree.local_coordinates(octree.child(octree.child(octree.root(), 0), 4)) << std::endl; // TODO diff --git a/Orthtree/test/Orthtree/test_octree_bbox.cpp b/Orthtree/test/Orthtree/test_octree_bbox.cpp index 4f3a4f3dabb..8c324de951a 100644 --- a/Orthtree/test/Orthtree/test_octree_bbox.cpp +++ b/Orthtree/test/Orthtree/test_octree_bbox.cpp @@ -42,14 +42,14 @@ void test_9_nodes() { assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 1.1, 1.1, 1.1)); // Compare the child nodes - assert(octree.bbox(octree.child(octree.index(octree.root()), 0)) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 0, 0, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 1)) == CGAL::Bbox_3(0, -1.1, -1.1, 1.1, 0, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 2)) == CGAL::Bbox_3(-1.1, 0, -1.1, 0, 1.1, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 3)) == CGAL::Bbox_3(0, 0, -1.1, 1.1, 1.1, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 4)) == CGAL::Bbox_3(-1.1, -1.1, 0, 0, 0, 1.1)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 5)) == CGAL::Bbox_3(0, -1.1, 0, 1.1, 0, 1.1)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 6)) == CGAL::Bbox_3(-1.1, 0, 0, 0, 1.1, 1.1)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 7)) == CGAL::Bbox_3(0, 0, 0, 1.1, 1.1, 1.1)); + assert(octree.bbox(octree.child(octree.root(), 0)) == CGAL::Bbox_3(-1.1, -1.1, -1.1, 0, 0, 0)); + assert(octree.bbox(octree.child(octree.root(), 1)) == CGAL::Bbox_3(0, -1.1, -1.1, 1.1, 0, 0)); + assert(octree.bbox(octree.child(octree.root(), 2)) == CGAL::Bbox_3(-1.1, 0, -1.1, 0, 1.1, 0)); + assert(octree.bbox(octree.child(octree.root(), 3)) == CGAL::Bbox_3(0, 0, -1.1, 1.1, 1.1, 0)); + assert(octree.bbox(octree.child(octree.root(), 4)) == CGAL::Bbox_3(-1.1, -1.1, 0, 0, 0, 1.1)); + assert(octree.bbox(octree.child(octree.root(), 5)) == CGAL::Bbox_3(0, -1.1, 0, 1.1, 0, 1.1)); + assert(octree.bbox(octree.child(octree.root(), 6)) == CGAL::Bbox_3(-1.1, 0, 0, 0, 1.1, 1.1)); + assert(octree.bbox(octree.child(octree.root(), 7)) == CGAL::Bbox_3(0, 0, 0, 1.1, 1.1, 1.1)); } void test_25_nodes() { @@ -69,49 +69,49 @@ void test_25_nodes() { assert(octree.bbox(octree.root()) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5)); // Compare the child nodes - assert(octree.bbox(octree.child(octree.index(octree.root()), 0)) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 0, 0, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 1)) == CGAL::Bbox_3(0, -1.5, -1.5, 1.5, 0, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 2)) == CGAL::Bbox_3(-1.5, 0, -1.5, 0, 1.5, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 3)) == CGAL::Bbox_3(0, 0, -1.5, 1.5, 1.5, 0)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 4)) == CGAL::Bbox_3(-1.5, -1.5, 0, 0, 0, 1.5)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 5)) == CGAL::Bbox_3(0, -1.5, 0, 1.5, 0, 1.5)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 6)) == CGAL::Bbox_3(-1.5, 0, 0, 0, 1.5, 1.5)); - assert(octree.bbox(octree.child(octree.index(octree.root()), 7)) == CGAL::Bbox_3(0, 0, 0, 1.5, 1.5, 1.5)); + assert(octree.bbox(octree.child(octree.root(), 0)) == CGAL::Bbox_3(-1.5, -1.5, -1.5, 0, 0, 0)); + assert(octree.bbox(octree.child(octree.root(), 1)) == CGAL::Bbox_3(0, -1.5, -1.5, 1.5, 0, 0)); + assert(octree.bbox(octree.child(octree.root(), 2)) == CGAL::Bbox_3(-1.5, 0, -1.5, 0, 1.5, 0)); + assert(octree.bbox(octree.child(octree.root(), 3)) == CGAL::Bbox_3(0, 0, -1.5, 1.5, 1.5, 0)); + assert(octree.bbox(octree.child(octree.root(), 4)) == CGAL::Bbox_3(-1.5, -1.5, 0, 0, 0, 1.5)); + assert(octree.bbox(octree.child(octree.root(), 5)) == CGAL::Bbox_3(0, -1.5, 0, 1.5, 0, 1.5)); + assert(octree.bbox(octree.child(octree.root(), 6)) == CGAL::Bbox_3(-1.5, 0, 0, 0, 1.5, 1.5)); + assert(octree.bbox(octree.child(octree.root(), 7)) == CGAL::Bbox_3(0, 0, 0, 1.5, 1.5, 1.5)); // Compare children of the first child - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 0)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 0)) == CGAL::Bbox_3(-1.5, -1.5, -1.5, -0.75, -0.75, -0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 1)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 1)) == CGAL::Bbox_3(-0.75, -1.5, -1.5, 0, -0.75, -0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 2)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 2)) == CGAL::Bbox_3(-1.5, -0.75, -1.5, -0.75, 0, -0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 3)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 3)) == CGAL::Bbox_3(-0.75, -0.75, -1.5, 0, 0, -0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 4)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 4)) == CGAL::Bbox_3(-1.5, -1.5, -0.75, -0.75, -0.75, 0)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 5)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 5)) == CGAL::Bbox_3(-0.75, -1.5, -0.75, 0, -0.75, 0)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 6)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 6)) == CGAL::Bbox_3(-1.5, -0.75, -0.75, -0.75, 0, 0)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 0), 7)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 0), 7)) == CGAL::Bbox_3(-0.75, -0.75, -0.75, 0, 0, 0)); // Compare children of the last child - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 0)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 0)) == CGAL::Bbox_3(0, 0, 0, 0.75, 0.75, 0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 1)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 1)) == CGAL::Bbox_3(0.75, 0, 0, 1.5, 0.75, 0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 2)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 2)) == CGAL::Bbox_3(0, 0.75, 0, 0.75, 1.5, 0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 3)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 3)) == CGAL::Bbox_3(0.75, 0.75, 0, 1.5, 1.5, 0.75)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 4)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 4)) == CGAL::Bbox_3(0, 0, 0.75, 0.75, 0.75, 1.5)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 5)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 5)) == CGAL::Bbox_3(0.75, 0, 0.75, 1.5, 0.75, 1.5)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 6)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 6)) == CGAL::Bbox_3(0, 0.75, 0.75, 0.75, 1.5, 1.5)); - assert(octree.bbox(octree.child(octree.child(octree.index(octree.root()), 7), 7)) == + assert(octree.bbox(octree.child(octree.child(octree.root(), 7), 7)) == CGAL::Bbox_3(0.75, 0.75, 0.75, 1.5, 1.5, 1.5)); } diff --git a/Orthtree/test/Orthtree/test_octree_copy_move_constructors.cpp b/Orthtree/test/Orthtree/test_octree_copy_move_constructors.cpp index ae6272fe149..2b4dd730e47 100644 --- a/Orthtree/test/Orthtree/test_octree_copy_move_constructors.cpp +++ b/Orthtree/test/Orthtree/test_octree_copy_move_constructors.cpp @@ -25,26 +25,27 @@ int main(void) points.insert(*(generator++)); Octree base (points, points.point_map()); - assert (base.root().is_leaf()); // base is not refined yet + assert (base.is_leaf(base.root())); // base is not refined yet Octree copy1 (base); - assert (copy1.root().is_leaf()); // copy1 is thus not refined either + assert (copy1.is_leaf(copy1.root())); // copy1 is thus not refined either assert (base == copy1); // base should be equal to copy1 base.refine(); - assert (!base.root().is_leaf()); // base is now refined - assert (copy1.root().is_leaf()); // copy1 should be unaffected and still unrefined + assert (!base.is_leaf(base.root())); // base is now refined + assert (copy1.is_leaf(copy1.root())); // copy1 should be unaffected and still unrefined assert (base != copy1); // base should be different from copy1 Octree copy2 (base); - assert (!copy2.root().is_leaf()); // copy2 should be refined + assert (!copy2.is_leaf(copy2.root())); // copy2 should be refined assert (base == copy2); // base should be equal to copy2 Octree move (std::move(base)); - assert (!move.root().is_leaf()); // move should be refined - assert (base.root().is_leaf()); // base should be back to init state (unrefined) - assert (copy1.root().is_leaf()); // copy1 still unaffected and still unrefined - assert (!copy2.root().is_leaf()); // copy2 unaffected by move and still refined + assert (!move.is_leaf(move.root())); // move should be refined + // fixme: my linter isn't happy about use-after-move + assert (base.is_leaf(base.root())); // base should be back to init state (unrefined) + assert (copy1.is_leaf(copy1.root())); // copy1 still unaffected and still unrefined + assert (!copy2.is_leaf(copy2.root())); // copy2 unaffected by move and still refined assert (move == copy2); // move should be equal to copy2 return EXIT_SUCCESS; diff --git a/Orthtree/test/Orthtree/test_octree_intersecting.cpp b/Orthtree/test/Orthtree/test_octree_intersecting.cpp index 17df0fd1fec..3470ee68b38 100644 --- a/Orthtree/test/Orthtree/test_octree_intersecting.cpp +++ b/Orthtree/test/Orthtree/test_octree_intersecting.cpp @@ -68,10 +68,10 @@ int main(void) { // Check the results assert(4 == nodes.size()); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_BACK) == nodes[0]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[1]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_FRONT) == nodes[2]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_FRONT) == nodes[3]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_TOP_BACK) == nodes[0]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[1]); + assert(octree.child(octree.root(), Octree::Traits::LEFT_TOP_FRONT) == nodes[2]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_TOP_FRONT) == nodes[3]); } // Intersection with a ray @@ -86,19 +86,19 @@ int main(void) { // Check the results assert(8 == nodes.size()); - assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_BOTTOM_BACK) == nodes[0]); + assert(octree.child(octree.root(), Octree::Traits::LEFT_BOTTOM_BACK) == nodes[0]); assert( - octree.child(octree.child(octree.index(octree.root()), + octree.child(octree.child(octree.root(), Octree::Traits::RIGHT_BOTTOM_BACK), Octree::Traits::LEFT_TOP_FRONT) == nodes[1] ); - assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_BACK) == nodes[2]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_BACK) == nodes[3]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_BOTTOM_FRONT) == nodes[4]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[5]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::LEFT_TOP_FRONT) == nodes[6]); - assert(octree.child(octree.index(octree.root()), Octree::Traits::RIGHT_TOP_FRONT) == nodes[7]); + assert(octree.child(octree.root(), Octree::Traits::LEFT_TOP_BACK) == nodes[2]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_TOP_BACK) == nodes[3]); + assert(octree.child(octree.root(), Octree::Traits::LEFT_BOTTOM_FRONT) == nodes[4]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_BOTTOM_FRONT) == nodes[5]); + assert(octree.child(octree.root(), Octree::Traits::LEFT_TOP_FRONT) == nodes[6]); + assert(octree.child(octree.root(), Octree::Traits::RIGHT_TOP_FRONT) == nodes[7]); } return EXIT_SUCCESS; diff --git a/Orthtree/test/Orthtree/test_octree_locate.cpp b/Orthtree/test/Orthtree/test_octree_locate.cpp index a43593deeeb..e3214a8ab11 100644 --- a/Orthtree/test/Orthtree/test_octree_locate.cpp +++ b/Orthtree/test/Orthtree/test_octree_locate.cpp @@ -26,7 +26,7 @@ void test_1_point() { octree.refine(10, 1); // Because there's only the root node, any point should be placed in it - assert(octree.index(octree.root()) == octree.locate(Point(-1, -1, -1))); + assert(octree.root() == octree.locate(Point(-1, -1, -1))); // These points would be placed outside the root node // assert(octree.root() == octree.locate({0, 0, 0})); @@ -52,24 +52,24 @@ void test_8_points() { octree.refine(10, 1); // Existing points should end up in the same place - assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1, -1, -1})); - assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1, -1, -1})); - assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1, 1, -1})); - assert(octree.child(octree.index(octree.root()), 3) == octree.locate({1, 1, -1})); - assert(octree.child(octree.index(octree.root()), 4) == octree.locate({-1, -1, 1})); - assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1, -1, 1})); - assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1, 1, 1})); - assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1, 1, 1})); + assert(octree.child(octree.root(), 0) == octree.locate({-1, -1, -1})); + assert(octree.child(octree.root(), 1) == octree.locate({1, -1, -1})); + assert(octree.child(octree.root(), 2) == octree.locate({-1, 1, -1})); + assert(octree.child(octree.root(), 3) == octree.locate({1, 1, -1})); + assert(octree.child(octree.root(), 4) == octree.locate({-1, -1, 1})); + assert(octree.child(octree.root(), 5) == octree.locate({1, -1, 1})); + assert(octree.child(octree.root(), 6) == octree.locate({-1, 1, 1})); + assert(octree.child(octree.root(), 7) == octree.locate({1, 1, 1})); // Points adjacent to the existing points should also end up in the same place - assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1.1, -1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1.1, -1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1.1, 1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 3) == octree.locate({1.1, 1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 4) == octree.locate({-1.1, -1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1.1, -1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1.1, 1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1.1, 1.1, 1.1})); + assert(octree.child(octree.root(), 0) == octree.locate({-1.1, -1.1, -1.1})); + assert(octree.child(octree.root(), 1) == octree.locate({1.1, -1.1, -1.1})); + assert(octree.child(octree.root(), 2) == octree.locate({-1.1, 1.1, -1.1})); + assert(octree.child(octree.root(), 3) == octree.locate({1.1, 1.1, -1.1})); + assert(octree.child(octree.root(), 4) == octree.locate({-1.1, -1.1, 1.1})); + assert(octree.child(octree.root(), 5) == octree.locate({1.1, -1.1, 1.1})); + assert(octree.child(octree.root(), 6) == octree.locate({-1.1, 1.1, 1.1})); + assert(octree.child(octree.root(), 7) == octree.locate({1.1, 1.1, 1.1})); } @@ -93,28 +93,28 @@ void test_10_points() { octree.refine(10, 1); // Existing points should end up in the same place - assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1, -1, -1})); - assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1, -1, -1})); - assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1, 1, -1})); - assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 3), 3), 3) == + assert(octree.child(octree.root(), 0) == octree.locate({-1, -1, -1})); + assert(octree.child(octree.root(), 1) == octree.locate({1, -1, -1})); + assert(octree.child(octree.root(), 2) == octree.locate({-1, 1, -1})); + assert(octree.child(octree.child(octree.child(octree.root(), 3), 3), 3) == octree.locate({1, 1, -1})); - assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 4), 4), 4) == + assert(octree.child(octree.child(octree.child(octree.root(), 4), 4), 4) == octree.locate({-1, -1, 1})); - assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1, -1, 1})); - assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1, 1, 1})); - assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1, 1, 1})); + assert(octree.child(octree.root(), 5) == octree.locate({1, -1, 1})); + assert(octree.child(octree.root(), 6) == octree.locate({-1, 1, 1})); + assert(octree.child(octree.root(), 7) == octree.locate({1, 1, 1})); // Points adjacent to the existing points might end up in different places - assert(octree.child(octree.index(octree.root()), 0) == octree.locate({-1.1, -1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 1) == octree.locate({1.1, -1.1, -1.1})); - assert(octree.child(octree.index(octree.root()), 2) == octree.locate({-1.1, 1.1, -1.1})); - assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 3), 3), 3) == + assert(octree.child(octree.root(), 0) == octree.locate({-1.1, -1.1, -1.1})); + assert(octree.child(octree.root(), 1) == octree.locate({1.1, -1.1, -1.1})); + assert(octree.child(octree.root(), 2) == octree.locate({-1.1, 1.1, -1.1})); + assert(octree.child(octree.child(octree.child(octree.root(), 3), 3), 3) == octree.locate({1.1, 1.1, -1.1})); - assert(octree.child(octree.child(octree.child(octree.index(octree.root()), 4), 4), 4) == + assert(octree.child(octree.child(octree.child(octree.root(), 4), 4), 4) == octree.locate({-1.1, -1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 5) == octree.locate({1.1, -1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 6) == octree.locate({-1.1, 1.1, 1.1})); - assert(octree.child(octree.index(octree.root()), 7) == octree.locate({1.1, 1.1, 1.1})); + assert(octree.child(octree.root(), 5) == octree.locate({1.1, -1.1, 1.1})); + assert(octree.child(octree.root(), 6) == octree.locate({-1.1, 1.1, 1.1})); + assert(octree.child(octree.root(), 7) == octree.locate({1.1, 1.1, 1.1})); } diff --git a/Orthtree/test/Orthtree/test_octree_refine.cpp b/Orthtree/test/Orthtree/test_octree_refine.cpp index 63ca3a31fa7..543c99a5a6e 100644 --- a/Orthtree/test/Orthtree/test_octree_refine.cpp +++ b/Orthtree/test/Orthtree/test_octree_refine.cpp @@ -37,7 +37,7 @@ void test_1_point() { octree.refine(10, 1); // Check that the root node was never split - assert(octree.root().is_leaf()); + assert(octree.is_leaf(octree.root())); assert(0 == octree.depth()); } @@ -54,7 +54,7 @@ void test_2_points() { // The octree should have been split once Octree other(points, points.point_map()); - other.split(other.index(other.root())); + other.split(other.root()); assert(Octree::is_topology_equal(other, octree)); assert(1 == octree.depth()); } @@ -73,15 +73,15 @@ void test_4_points() { // The octree should have been split once on the first level, and twice on the second Octree other(points, points.point_map()); - other.split(other.index(other.root())); - other.split(other.child(other.index(other.root()), 3)); - other.split(other.child(other.index(other.root()), 7)); + other.split(other.root()); + other.split(other.child(other.root(), 3)); + other.split(other.child(other.root(), 7)); assert(Octree::is_topology_equal(other, octree)); assert(2 == octree.depth()); // Applying another splitting criterion shouldn't reset the tree. octree.refine(Split_nth_child_of_root(2)); - other.split(other.child(other.index(other.root()), 2)); + other.split(other.child(other.root(), 2)); assert(Octree::is_topology_equal(other, octree)); } diff --git a/Orthtree/test/Orthtree/test_octree_traverse.cpp b/Orthtree/test/Orthtree/test_octree_traverse.cpp index 82abb26b12a..f26625db46a 100644 --- a/Orthtree/test/Orthtree/test_octree_traverse.cpp +++ b/Orthtree/test/Orthtree/test_octree_traverse.cpp @@ -30,7 +30,7 @@ bool test_preorder_1_node() { // Check each item in the range auto iter = nodes.begin(); - assert(*iter == octree.index(octree.root())); + assert(*iter == octree.root()); return true; } @@ -51,10 +51,10 @@ bool test_preorder_9_nodes() { // Check each item in the range auto iter = nodes.begin(); - assert(*iter == octree.index(octree.root())); + assert(*iter == octree.root()); for (int i = 0; i < 8; ++i) { iter++; - assert(*iter == octree.child(octree.index(octree.root()), i)); + assert(*iter == octree.child(octree.root(), i)); } return true; @@ -77,7 +77,7 @@ bool test_level_9_nodes() { // Check each item in the range auto iter = nodes.begin(); for (int i = 0; i < 8; ++i) { - assert(*iter == octree.child(octree.index(octree.root()), i)); + assert(*iter == octree.child(octree.root(), i)); iter++; } @@ -102,30 +102,30 @@ bool test_preorder_25_nodes() { // Check each item in the range auto iter = nodes.begin(); - assert(*iter == octree.index(octree.root())); + assert(*iter == octree.root()); iter++; - assert(*iter == octree.child(octree.index(octree.root()), 0)); + assert(*iter == octree.child(octree.root(), 0)); iter++; - assert(*iter == octree.child(octree.index(octree.root()), 1)); + assert(*iter == octree.child(octree.root(), 1)); iter++; - assert((*iter == octree.child(octree.index(octree.root()), 2))); + assert((*iter == octree.child(octree.root(), 2))); iter++; - assert(*iter == octree.child(octree.index(octree.root()), 3)); + assert(*iter == octree.child(octree.root(), 3)); for (int i = 0; i < 8; ++i) { iter++; - assert(*iter == octree.child(octree.child(octree.index(octree.root()), 3), i)); + assert(*iter == octree.child(octree.child(octree.root(), 3), i)); } iter++; - assert((*iter == octree.child(octree.index(octree.root()), 4))); + assert((*iter == octree.child(octree.root(), 4))); iter++; - assert((*iter == octree.child(octree.index(octree.root()), 5))); + assert((*iter == octree.child(octree.root(), 5))); iter++; - assert((*iter == octree.child(octree.index(octree.root()), 6))); + assert((*iter == octree.child(octree.root(), 6))); iter++; - assert((*iter == octree.child(octree.index(octree.root()), 7))); + assert((*iter == octree.child(octree.root(), 7))); for (int i = 0; i < 8; ++i) { iter++; - assert(*iter == octree.child(octree.child(octree.index(octree.root()), 7), i)); + assert(*iter == octree.child(octree.child(octree.root(), 7), i)); } return true;