2013-03-05 04:48:13 +01:00
|
|
|
#ifndef __REPLICATE_GENERATOR_HPP
|
|
|
|
#define __REPLICATE_GENERATOR_HPP
|
|
|
|
|
2013-03-05 17:08:19 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include "algo.hpp"
|
|
|
|
|
2013-03-05 04:48:13 +01:00
|
|
|
namespace CosmoTool
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename Coord, int N>
|
|
|
|
class ReplicateGenerator
|
|
|
|
{
|
|
|
|
public:
|
2013-03-05 17:08:19 +01:00
|
|
|
typedef Coord Coords[N];
|
2013-03-05 17:11:20 +01:00
|
|
|
Coord replicate;
|
2013-03-05 17:08:19 +01:00
|
|
|
|
2013-03-05 17:11:20 +01:00
|
|
|
ReplicateGenerator(const Coords& x, Coord shift)
|
2013-03-05 04:48:13 +01:00
|
|
|
{
|
2013-03-05 17:08:19 +01:00
|
|
|
face = 0;
|
2013-03-05 17:11:20 +01:00
|
|
|
replicate = shift;
|
2013-03-05 17:08:19 +01:00
|
|
|
numFaces = spower<N,long>(3);
|
|
|
|
std::copy(x, x+N, x_base);
|
2013-03-05 04:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool next()
|
|
|
|
{
|
2013-03-05 17:08:19 +01:00
|
|
|
if (face == numFaces)
|
2013-03-05 04:48:13 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
face++;
|
2013-03-05 17:08:19 +01:00
|
|
|
|
|
|
|
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;
|
2013-03-05 17:11:20 +01:00
|
|
|
x_shifted[i] = x_base[i] + (c_face-1)*replicate;
|
2013-03-05 17:08:19 +01:00
|
|
|
no_move = no_move && (c_face == 1);
|
|
|
|
}
|
|
|
|
if (no_move)
|
|
|
|
return next();
|
|
|
|
return true;
|
2013-03-05 04:48:13 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 17:08:19 +01:00
|
|
|
const Coord *getPosition()
|
2013-03-05 04:48:13 +01:00
|
|
|
{
|
|
|
|
return x_shifted;
|
|
|
|
}
|
|
|
|
|
2013-03-05 17:08:19 +01:00
|
|
|
void getPosition(Coords& x_out)
|
|
|
|
{
|
|
|
|
std::copy(x_shifted, x_shifted+N, x_out);
|
|
|
|
}
|
|
|
|
|
2013-03-05 04:48:13 +01:00
|
|
|
private:
|
2013-03-05 17:08:19 +01:00
|
|
|
Coord x_shifted[N], x_base[N];
|
|
|
|
long face, numFaces;
|
2013-03-05 04:48:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|