cosmotool/src/replicateGenerator.hpp

63 lines
1.0 KiB
C++
Raw Normal View History

#ifndef __REPLICATE_GENERATOR_HPP
#define __REPLICATE_GENERATOR_HPP
#include <algorithm>
#include "algo.hpp"
namespace CosmoTool
{
template<typename Coord, int N>
class ReplicateGenerator
{
public:
typedef Coord Coords[N];
ReplicateGenerator(const Coords& x)
{
face = 0;
numFaces = spower<N,long>(3);
std::copy(x, x+N, x_base);
}
bool next()
{
if (face == numFaces)
return false;
face++;
bool no_move = true;
int q_face = face;
for (int i = 0; i < N; i++)
{
int c_face;
c_face = q_face % 3;
q_face /= 3;
x_shifted[i] = x_base[i] + (c_face-1);
no_move = no_move && (c_face == 1);
}
if (no_move)
return next();
return true;
}
const Coord *getPosition()
{
return x_shifted;
}
void getPosition(Coords& x_out)
{
std::copy(x_shifted, x_shifted+N, x_out);
}
private:
Coord x_shifted[N], x_base[N];
long face, numFaces;
};
};
#endif