Commit 52179046 authored by Quentin Khan's avatar Quentin Khan

Change FBox min and max corner accessors

The accessors were references to private members, they are changed to
standard member function accessors.
parent 6dca7b39
......@@ -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;
......
......@@ -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;
......
......@@ -2,6 +2,7 @@
#define SCALFMM_BOX_HPP_
#include <ostream>
#include <cmath>
#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() << "]";
}
};
......
......@@ -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;
......
......@@ -196,7 +196,7 @@ public:
}
FReal getBoxWidth() const {
return _box.c2[0] - _box.c1[0];
return _box.width(0);
}
/** \brief Leaf list accessor
......
......@@ -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}));
......
......@@ -53,7 +53,7 @@ struct FRandomPositionGenerator {
using param = typename std::uniform_real_distribution<FReal>::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]));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment