5 #ifndef MERCATOR_RANDCACHE_H 6 #define MERCATOR_RANDCACHE_H 10 #include <wfmath/MersenneTwister.h> 21 typedef WFMath::MTRand::uint32
uint32;
29 virtual size_type
operator()(
int x,
int y) = 0;
53 size_type cache_order = (*m_ordering)(x, y);
56 if(cache_order >=
m_cache.size()) {
57 size_type old_size =
m_cache.size();
58 m_cache.resize(cache_order + 64);
59 while(old_size <
m_cache.size())
63 return double(
m_cache[cache_order] * (1.0/4294967295.0));
81 if (x==0 && y==0)
return 0;
83 int d=std::max(std::abs(x), std::abs(y));
84 int min=(2*d-1)*(2*d-1);
86 if (y == d)
return min + 2*d - x;
87 if (x == -d)
return min + 4*d - y;
88 if (y == -d)
return min + 6*d + x;
90 if (y >=0)
return min + y;
91 else return min + 8*d + y;
A cache of random values.
Definition: RandCache.h:17
RandCache(uint32 seed, Ordering *o)
Constructor.
Definition: RandCache.h:36
RandCache(uint32 *seed, uint32 seed_len, Ordering *o)
Constructor.
Definition: RandCache.h:43
int m_x
The centre x coordinate of the spiral.
Definition: RandCache.h:101
RandCache::size_type operator()(int x, int y)
Determine the order.
Definition: RandCache.h:79
A spiral around x,y.
Definition: RandCache.h:97
A spiral around 0,0.
Definition: RandCache.h:76
WFMath::MTRand m_rand
Source random number generator.
Definition: RandCache.h:68
WFMath::MTRand::uint32 uint32
Unsigned 32bit integer.
Definition: RandCache.h:21
std::vector< uint32 >::size_type size_type
Size type of std::vector.
Definition: RandCache.h:23
int m_y
The centre y coordinate of the spiral.
Definition: RandCache.h:103
double operator()(int x, int y)
Retrieve a random value associated with parameters.
Definition: RandCache.h:51
std::vector< uint32 > m_cache
Store for the cache of values.
Definition: RandCache.h:70
Interface to define the ordering of the random number cache.
Definition: RandCache.h:26
Ordering * m_ordering
Ordering object that defines the ordering of the cache.
Definition: RandCache.h:72
virtual size_type operator()(int x, int y)=0
Determine the order.
SpiralOrdering(int x, int y)
Constructor.
Definition: RandCache.h:109