5 #ifndef MERCATOR_RANDCACHE_H 6 #define MERCATOR_RANDCACHE_H 11 #include <wfmath/MersenneTwister.h> 22 typedef WFMath::MTRand::uint32
uint32;
30 virtual size_type
operator()(
int x,
int y) = 0;
38 m_rand(seed), m_ordering(o) {}
45 m_rand(seed, seed_len), m_ordering(o) {}
54 size_type cache_order = (*m_ordering)(x, y);
57 if(cache_order >= m_cache.size()) {
58 size_type old_size = m_cache.size();
59 m_cache.resize(cache_order + 64);
60 while(old_size < m_cache.size())
61 m_cache[old_size++] = m_rand.randInt();
64 return double(m_cache[cache_order] * (1.0/4294967295.0));
69 WFMath::MTRand m_rand;
71 std::vector<uint32> m_cache;
82 if (x==0 && y==0)
return 0;
84 int d=std::max(std::abs(x), std::abs(y));
85 int min=(2*d-1)*(2*d-1);
87 if (y == d)
return min + 2*d - x;
88 if (x == -d)
return min + 4*d - y;
89 if (y == -d)
return min + 6*d + x;
91 if (y >=0)
return min + y;
92 else return min + 8*d + y;
A cache of random values.
Definition: RandCache.h:18
RandCache(uint32 seed, Ordering *o)
Constructor.
Definition: RandCache.h:37
RandCache(uint32 *seed, uint32 seed_len, Ordering *o)
Constructor.
Definition: RandCache.h:44
RandCache::size_type operator()(int x, int y)
Determine the order.
Definition: RandCache.h:80
A spiral around x,y.
Definition: RandCache.h:98
A spiral around 0,0.
Definition: RandCache.h:77
WFMath::MTRand::uint32 uint32
Unsigned 32bit integer.
Definition: RandCache.h:22
std::vector< uint32 >::size_type size_type
Size type of std::vector.
Definition: RandCache.h:24
double operator()(int x, int y)
Retrieve a random value associated with parameters.
Definition: RandCache.h:52
Interface to define the ordering of the random number cache.
Definition: RandCache.h:27
virtual size_type operator()(int x, int y)=0
Determine the order.
SpiralOrdering(int x, int y)
Constructor.
Definition: RandCache.h:110