summaryrefslogtreecommitdiff
path: root/octree.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'octree.hpp')
-rw-r--r--octree.hpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/octree.hpp b/octree.hpp
index 1be6e0a..bb13242 100644
--- a/octree.hpp
+++ b/octree.hpp
@@ -5,6 +5,8 @@
#include <set>
#include <unordered_map>
+#include <iostream>
+
#include "spin.hpp"
#include "vector.hpp"
@@ -31,16 +33,16 @@ private:
std::unordered_map<std::array<signed, D>, std::set<Spin<T, D, S>*>> data;
public:
- Octree(T L, unsigned N) {
- L = L;
- N = N;
+ Octree(T L_tmp, unsigned N_tmp) {
+ L = L_tmp;
+ N = N_tmp;
}
std::array<signed, D> ind(Vector<T, D> x) const {
std::array<signed, D> ind;
for (unsigned i = 0; i < D; i++) {
- ind[i] = (signed)std::floor(N * x(i) / L);
+ ind[i] = std::floor(N * x(i) / L);
}
return ind;
@@ -55,6 +57,15 @@ public:
}
};
+ std::set<Spin<T, D, S>*> at(const Vector<T, D>& x) const {
+ auto it = data.find(ind(x));
+ if (it == data.end()) {
+ return {};
+ } else {
+ return it->second;
+ }
+ }
+
std::set<Spin<T, D, S>*> neighbors(const Vector<T, D>& x) const {
std::array<signed, D> i0 = ind(x);
std::set<Spin<T, D, S>*> ns;