diff options
author | Adrian Kummerlaender | 2021-05-17 00:30:13 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2021-05-17 00:30:13 +0200 |
commit | a92271176a19e06611099c0eccc4e6a6887f4915 (patch) | |
tree | 54067b334bfae7d99c79cfb00da5891334f9514c /src/cuboid.h | |
download | SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar.gz SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar.bz2 SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar.lz SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar.xz SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.tar.zst SweepLB-a92271176a19e06611099c0eccc4e6a6887f4915.zip |
Extract public version of SweepLB
Diffstat (limited to 'src/cuboid.h')
-rw-r--r-- | src/cuboid.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cuboid.h b/src/cuboid.h new file mode 100644 index 0000000..c4ff803 --- /dev/null +++ b/src/cuboid.h @@ -0,0 +1,37 @@ +#pragma once + +#include <array> + +class Cuboid { +private: + const std::array<std::size_t,3> _size; + const std::size_t _volume; + +public: + Cuboid(std::size_t nX, std::size_t nY, std::size_t nZ): + _size{nX, nY, nZ}, + _volume(nX*nY*nZ) { } + + std::size_t volume() const { + return _volume; + } + + std::size_t index(unsigned iX, unsigned iY, unsigned iZ) const { + return iX*_size[1]*_size[2] + iY*_size[2] + iZ; + } + + int operator[](unsigned i) const { + return _size[i]; + } + + template <typename F> + void traverse(F f) { + for (int iX = 0; iX < _size[0]; ++iX) { + for (int iY = 0; iY < _size[1]; ++iY) { + for (int iZ = 0; iZ < _size[2]; ++iZ) { + f(iX, iY, iZ, index(iX,iY,iZ)); + } + } + } + } +}; |