From 52179046e04270d26404d3372e41c499c58476f2 Mon Sep 17 00:00:00 2001 From: Quentin Khan Date: Tue, 28 Mar 2017 11:52:57 +0200 Subject: [PATCH] Change FBox min and max corner accessors The accessors were references to private members, they are changed to standard member function accessors. --- Src/Adaptive/FAdaptiveSequential.hpp | 2 +- Src/Adaptive/FAdaptiveTask.hpp | 2 +- Src/Adaptive/FBox.hpp | 23 +++++----- Src/Adaptive/FNode.hpp | 4 +- Src/Adaptive/FTree.hpp | 2 +- Tests/noDist/Adaptive/test_FBox.cpp | 46 +++++++++---------- .../noDist/Adaptive/test_FUnifFlopsKernel.cpp | 2 +- 7 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Src/Adaptive/FAdaptiveSequential.hpp b/Src/Adaptive/FAdaptiveSequential.hpp index 74d14878..008f0469 100644 --- a/Src/Adaptive/FAdaptiveSequential.hpp +++ b/Src/Adaptive/FAdaptiveSequential.hpp @@ -414,7 +414,7 @@ public: other_node = other_node->getParent(); } - typename node_t::FReal box_width = (node->getBox().c2 - node->getBox().c1)[0]; + typename node_t::FReal box_width = node->getBox().width(0); auto center_offset = other_node->getBox().center() - node->getBox().center(); std::size_t other_node_index = 0; diff --git a/Src/Adaptive/FAdaptiveTask.hpp b/Src/Adaptive/FAdaptiveTask.hpp index cd47d63d..58e79d1c 100644 --- a/Src/Adaptive/FAdaptiveTask.hpp +++ b/Src/Adaptive/FAdaptiveTask.hpp @@ -1146,7 +1146,7 @@ public: other_node = other_node->getParent(); } - typename node_t::FReal box_width = (node->getBox().c2 - node->getBox().c1)[0]; + typename node_t::FReal box_width = node->getBox().width(0); auto center_offset = other_node->getBox().center() - node->getBox().center(); std::size_t other_node_index = 0; diff --git a/Src/Adaptive/FBox.hpp b/Src/Adaptive/FBox.hpp index 2db5058a..9c60f609 100644 --- a/Src/Adaptive/FBox.hpp +++ b/Src/Adaptive/FBox.hpp @@ -2,6 +2,7 @@ #define SCALFMM_BOX_HPP_ #include +#include #include "FZCurve.hpp" @@ -46,22 +47,22 @@ private: } public: /// Accessor for the minimum corner - const position_t& c1 = _c1; + const position_t& c1() const noexcept { + return _c1; + } /// Accessor for the maximum corner - const position_t& c2 = _c2; + const position_t& c2() const noexcept { + return _c2; + } /** Builds an empty box at the origin */ FBox() = default; + /** Copies an existing box */ - FBox(const FBox& other) : _c1(other._c1), _c2(other._c2), _center(other._center) {} + FBox(const FBox&) = default; /** Copies an other box */ - FBox& operator=(const FBox& other) { - this->_c1 = other._c1; - this->_c2 = other._c2; - this->_center = other._center; - return *this; - } + FBox& operator=(const FBox& other) = default; /** Builds a cube from the lower corner and its side length * @@ -216,7 +217,7 @@ public: /** Tests two boxes equality */ bool operator==(const FBox& other) const { - return c1 == other.c1 && c2 == other.c2; + return c1() == other.c1() && c2() == other.c2(); } /** Tests two boxes inequality */ bool operator!=(const FBox& other) const { @@ -224,7 +225,7 @@ public: } friend std::ostream& operator<<(std::ostream& os, const FBox& box) { - return os << "[" << box.c1 << "," << box.c2 << "]"; + return os << "[" << box.c1() << "," << box.c2() << "]"; } }; diff --git a/Src/Adaptive/FNode.hpp b/Src/Adaptive/FNode.hpp index 2c8478c6..bf9cff01 100644 --- a/Src/Adaptive/FNode.hpp +++ b/Src/Adaptive/FNode.hpp @@ -454,8 +454,8 @@ public: bool is_adjacent(const FNode& other) const noexcept { // Sum of the half side lengh of the two nodes boxes. // Boxes are cubes, we only need one side. - FReal centers_distance = getBox().center()[0] - getBox().c1[0] - + other.getBox().center()[0] - other.getBox().c1[0]; + FReal centers_distance = getBox().center()[0] - getBox().c1()[0] + + other.getBox().center()[0] - other.getBox().c1()[0]; // Used to check that the other box isn't overlapping with this box bool one_axis_is_at_exact_distance = false; diff --git a/Src/Adaptive/FTree.hpp b/Src/Adaptive/FTree.hpp index 7814e841..9bdab8ac 100644 --- a/Src/Adaptive/FTree.hpp +++ b/Src/Adaptive/FTree.hpp @@ -196,7 +196,7 @@ public: } FReal getBoxWidth() const { - return _box.c2[0] - _box.c1[0]; + return _box.width(0); } /** \brief Leaf list accessor diff --git a/Tests/noDist/Adaptive/test_FBox.cpp b/Tests/noDist/Adaptive/test_FBox.cpp index e1b9b75f..fed37f30 100644 --- a/Tests/noDist/Adaptive/test_FBox.cpp +++ b/Tests/noDist/Adaptive/test_FBox.cpp @@ -36,8 +36,8 @@ namespace scalfmm { void test_constructor_1() { box_t b; position_t p {0,0,0}; - assert(b.c1 == p); - assert(b.c2 == p); + assert(b.c1() == p); + assert(b.c2() == p); } /// Test constructor with minimum and maximum corners @@ -46,8 +46,8 @@ namespace scalfmm { position_t p2 = {100,100,100}; box_t b(p1, p2); - assert(b.c1 == p1); - assert(b.c2 == p2); + assert(b.c1() == p1); + assert(b.c2() == p2); } /// Test constructor with initializer lists @@ -55,8 +55,8 @@ namespace scalfmm { position_t p {0,0,0}; box_t d({0,0,0},{0,0,0}); - assert(d.c1 == p); - assert(d.c2 == p); + assert(d.c1() == p); + assert(d.c2() == p); } /// Test copy constructor @@ -66,14 +66,14 @@ namespace scalfmm { box_t c(p1, p2); box_t e(c); - assert(c.c1 == e.c1); - assert(c.c2 == e.c2); + assert(c.c1() == e.c1()); + assert(c.c2() == e.c2()); // test deep copy c.set(p2, p1 + position_t{-1,0,0}); - assert(c.c1 != e.c1); - assert(c.c2 == e.c2); + assert(c.c1() != e.c1()); + assert(c.c2() == e.c2()); } void test_constructor_5() { @@ -82,8 +82,8 @@ namespace scalfmm { box_t c(p1, p2); for(std::size_t i = 0; i < Dim; ++i) { - assert(Ffeq(c.c1[i], std::fmin(p1[i], p2[i]))); - assert(Ffeq(c.c2[i], std::fmax(p1[i], p2[i]))); + assert(Ffeq(c.c1()[i], std::fmin(p1[i], p2[i]))); + assert(Ffeq(c.c2()[i], std::fmax(p1[i], p2[i]))); } } @@ -94,8 +94,8 @@ namespace scalfmm { box_t b; b = a; - assert(a.c1 == b.c1); - assert(a.c2 == b.c2); + assert(a.c1() == b.c1()); + assert(a.c2() == b.c2()); assert(a.center() == b.center()); } @@ -106,8 +106,8 @@ namespace scalfmm { box_t b; b = std::move(a); - assert(a.c1 == b.c1); - assert(a.c2 == b.c2); + assert(a.c1() == b.c1()); + assert(a.c2() == b.c2()); } @@ -150,17 +150,17 @@ namespace scalfmm { assert(b.corner(7) == p7); b.corner(0, {1,1,1}); - assert(b.corner(0) == b.c1); + assert(b.corner(0) == b.c1()); assert(b.corner(0) == position_t(1,1,1)); b.corner(0, {0,0,0}); b.corner(2, {20, 80, 30}); - assert(b.c1 == position_t(20, 0, 30)); - assert(b.c2 == position_t(100, 80, 100)); + assert(b.c1() == position_t(20, 0, 30)); + assert(b.c2() == position_t(100, 80, 100)); b.corner(5, {0, 20, 25}); - assert(b.c1 == position_t(0, 20, 25)); - assert(b.c2 == position_t(20, 80, 30)); + assert(b.c1() == position_t(0, 20, 25)); + assert(b.c2() == position_t(20, 80, 30)); } struct DummyObject { @@ -171,8 +171,8 @@ namespace scalfmm { void test_contains() { box_t b = {{0,0,0}, {100,100,100}}; - assert(b.contains(b.c1)); - assert(b.contains(b.c2)); + assert(b.contains(b.c1())); + assert(b.contains(b.c2())); assert(b.contains({50,50,50})); assert(! b.contains({150,50,50})); assert(! b.contains({50,150,50})); diff --git a/Tests/noDist/Adaptive/test_FUnifFlopsKernel.cpp b/Tests/noDist/Adaptive/test_FUnifFlopsKernel.cpp index 22b7830f..4b7bf947 100644 --- a/Tests/noDist/Adaptive/test_FUnifFlopsKernel.cpp +++ b/Tests/noDist/Adaptive/test_FUnifFlopsKernel.cpp @@ -53,7 +53,7 @@ struct FRandomPositionGenerator { using param = typename std::uniform_real_distribution::param_type; // Set each dimension limits for(auto i = 0uL; i < Dim; ++i) { - random_real[i].param(param(box.c1[i], box.c2[i])); + random_real[i].param(param(box.c1()[i], box.c2()[i])); } } -- 2.22.0