Skip to content

Commit

Permalink
Make local variables and method parameters const where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ACapo committed Nov 20, 2015
1 parent 76ddb5d commit e51be56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Magnum/Octree/Octree.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class /* MAGNUM_OCTREE_EXPORT */Octree {
* @param maxDepth The maximal depth of the octree
* @return Reference to self (for method chaining)
*/
Octree<T>& build(const std::vector<Shapes::AxisAlignedBox3D>& entries, std::vector<T>& data, const Int maxDepth) {
Octree<T>& build(const std::vector<Shapes::AxisAlignedBox3D>& entries, const std::vector<T>& data, const Int maxDepth) {
CORRADE_ASSERT(data.size() == entries.size(), "Entries and data need to be same size.", *this);

auto entryItor = entries.begin();
Expand Down
24 changes: 12 additions & 12 deletions src/Magnum/Octree/Octree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Magnum { namespace Octree {

/* Function is called for the root node only, to create the initial bounding box */
template <typename T>
Octree<T>& Octree<T>::createInitialBounds(const std::vector<Shapes::AxisAlignedBox3D>& points, Int maxDepth) {
Octree<T>& Octree<T>::createInitialBounds(const std::vector<Shapes::AxisAlignedBox3D>& points, const Int maxDepth) {

_center = {0, 0, 0};
_radius = 0.f;
Expand Down Expand Up @@ -64,7 +64,7 @@ Octree<T>& Octree<T>::createInitialBounds(const std::vector<Shapes::AxisAlignedB

/* insert operation. At the moment every leaf has exactly one data point. Depth is unlimited. */
template <typename T>
Octree<T>& Octree<T>::insert(const Shapes::AxisAlignedBox3D& point, T data) {
Octree<T>& Octree<T>::insert(const Shapes::AxisAlignedBox3D& point, const T data) {

/*
* Use a simple code for making traversion simple, by using bitwise or operations
Expand Down Expand Up @@ -106,13 +106,13 @@ Octree<T>& Octree<T>::insert(const Shapes::AxisAlignedBox3D& point, T data) {
* {+0.5, +0.5, -0.5},
* {+0.5, +0.5, +0.5}
*/
Int octContainingBox = getOctantContainingBox(point);
Int octContainingOldBox = getOctantContainingBox(oldPoint);
const Int octContainingBox = getOctantContainingBox(point);
const Int octContainingOldBox = getOctantContainingBox(oldPoint);

if((octContainingOldBox != -1) || (octContainingBox != -1)) {

for(UnsignedByte i = 0; i < 8; ++i) {
Vector3 l = Math::lerp(Vector3{0.5f}, Vector3{-0.5f}, Math::BoolVector<3>{i});
const Vector3 l = Math::lerp(Vector3{0.5f}, Vector3{-0.5f}, Math::BoolVector<3>{i});

_children[i] = new Octree{
_center + (_radius * l),
Expand Down Expand Up @@ -143,7 +143,7 @@ Octree<T>& Octree<T>::insert(const Shapes::AxisAlignedBox3D& point, T data) {
} else {
/* Node is an inner node. Insert recursively into the appropriate child octant */

Int octContainingBox = getOctantContainingBox(point);
const Int octContainingBox = getOctantContainingBox(point);

if(octContainingBox != -1) {
_children[octContainingBox]->insert(point, data);
Expand Down Expand Up @@ -201,8 +201,8 @@ Octree<T>& Octree<T>::points(std::vector<T>& resultData, const Vector3& min, con
if(!isLeafNode()) {
for(UnsignedInt i = 0; i < 8; ++i) {
/* Compute the min/max corners of this child octant */
Vector3 cmin = _children[i]->_center - Vector3{_children[i]->_radius};
Vector3 cmax = _children[i]->_center + Vector3{_children[i]->_radius};
const Vector3 cmin = _children[i]->_center - Vector3{_children[i]->_radius};
const Vector3 cmax = _children[i]->_center + Vector3{_children[i]->_radius};

/* If query rectangle doesn't intersect this child octants bounding box, continue. */
if(Math::max(max, cmin) != max) {
Expand All @@ -225,14 +225,14 @@ template <typename T>
Octree<T>& Octree<T>::points(std::vector<T>& resultData, const Vector4 (&frustum)[6]) {

// 0: no corners inside frustum, 1: part of the corners inside, 2: all corners inside
Int octantStatus = cubeInFrustum(frustum);
const Int octantStatus = cubeInFrustum(frustum);
if(octantStatus == 2) {
if(isLeafNode()) {
resultData.insert(resultData.end(), data().begin(), data().end());
} else {
//traverse to leafnode or maybe just call points(found, min, max) with bounds of current octant as min, max?
Vector3 min {(center().x() - radius()), (center().y() - radius()), (center().z() - radius())};
Vector3 max {(center().x() + radius()), (center().y() + radius()), (center().z() + radius())};
const Vector3 min {(center().x() - radius()), (center().y() - radius()), (center().z() - radius())};
const Vector3 max {(center().x() + radius()), (center().y() + radius()), (center().z() + radius())};
points(resultData, min, max);
}
} else if(octantStatus == 1) {
Expand Down Expand Up @@ -274,7 +274,7 @@ Int Octree<T>::cubeInFrustum(const Vector4 (&frustum)[6]) {
cornersInsideFrustumCount = 0;

for(UnsignedByte i = 0; i < 8; ++i) {
Vector3 corner = Math::lerp(Vector3{center().x() + radius(), center().y() + radius(), center().z() + radius()},
const Vector3 corner = Math::lerp(Vector3{center().x() + radius(), center().y() + radius(), center().z() + radius()},
Vector3{center().x() - radius(), center().y() - radius(), center().z() - radius()},
Math::BoolVector<3>{i});

Expand Down

0 comments on commit e51be56

Please sign in to comment.