5 #ifndef MERCATOR_RANDCACHE_H 6 #define MERCATOR_RANDCACHE_H 12 #include <wfmath/MersenneTwister.h> 23 typedef WFMath::MTRand::uint32
uint32;
31 virtual size_type
operator()(
int x,
int y) = 0;
38 RandCache(uint32 seed, std::unique_ptr<Ordering> o) :
39 m_rand(seed), m_ordering(
std::move(o)) {}
45 RandCache(uint32* seed, uint32 seed_len, std::unique_ptr<Ordering> o) :
46 m_rand(seed, seed_len), m_ordering(
std::move(o)) {}
55 size_type cache_order = (*m_ordering)(x, y);
58 if(cache_order >= m_cache.size()) {
59 size_type old_size = m_cache.size();
60 m_cache.resize(cache_order + 64);
61 while(old_size < m_cache.size())
62 m_cache[old_size++] = m_rand.randInt();
65 return double(m_cache[cache_order] * (1.0/4294967295.0));
70 WFMath::MTRand m_rand;
72 std::vector<uint32> m_cache;
74 std::unique_ptr<Ordering> m_ordering;
83 if (x==0 && y==0)
return 0;
85 int d=std::max(std::abs(x), std::abs(y));
86 int min=(2*d-1)*(2*d-1);
88 if (y == d)
return min + 2*d - x;
89 if (x == -d)
return min + 4*d - y;
90 if (y == -d)
return min + 6*d + x;
92 if (y >=0)
return min + y;
93 else return min + 8*d + y;
RandCache(uint32 *seed, uint32 seed_len, std::unique_ptr< Ordering > o)
Constructor.
A cache of random values.
RandCache(uint32 seed, std::unique_ptr< Ordering > o)
Constructor.
WFMath::MTRand::uint32 uint32
Unsigned 32bit integer.
std::vector< uint32 >::size_type size_type
Size type of std::vector.
double operator()(int x, int y)
Retrieve a random value associated with parameters.
RandCache::size_type operator()(int x, int y) override
Determine the order.
Interface to define the ordering of the random number cache.
virtual size_type operator()(int x, int y)=0
Determine the order.
SpiralOrdering(int x, int y)
Constructor.