From a92271176a19e06611099c0eccc4e6a6887f4915 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 May 2021 00:30:13 +0200 Subject: Extract public version of SweepLB --- src/cuboid.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/cuboid.h (limited to 'src/cuboid.h') 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 + +class Cuboid { +private: + const std::array _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 + 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)); + } + } + } + } +}; -- cgit v1.2.3