core.field
Class RandomGridIterator

java.lang.Object
  extended bycore.field.RandomGridIterator
All Implemented Interfaces:
Vec2Iterator

public class RandomGridIterator
extends java.lang.Object
implements Vec2Iterator

Iterates over an integer, rectangular grid in a pseudo-random order. Because it is difficult to quickly produce a fully random ordering of all the grid points, this class uses a pseudo-random technique: The grid is divided evenly into square blocks, and a random point is chosen in the top-left block. The corresponding points in all the rest of the blocks are next in the sequence. Points are chosen in the block in a truly random fashion until all the points on the grid are covered.

Version:
1.0
Author:
Andreas Sundquist

Field Summary
private  int blocksize
           
private  int coverage
           
private static int coveragelimit
           
private  boolean[][] covered
           
private  int gx
           
private  int gy
           
private  java.util.Random random
           
private  Vec2 v
           
private  int x
           
private  int xmax
           
private  int xmin
           
private  int y
           
private  int ymax
           
private  int ymin
           
 
Constructor Summary
RandomGridIterator(int width, int height)
          Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [0, width-1] x [0, height-1].
RandomGridIterator(int xorigin, int yorigin, int width, int height)
          Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [xorigin, xorigin+width-1] x [yorigin, yorigin+height-1].
RandomGridIterator(int xorigin, int yorigin, int width, int height, java.util.Random random)
          Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [xorigin, xorigin+width-1] x [yorigin, yorigin+height-1] using the random sequence generator 'random'.
RandomGridIterator(int width, int height, java.util.Random random)
          Constructs a RandomGridIterator.
 
Method Summary
private  void Initialize()
           
 Vec2 next()
          Returns: null if there are no more points in the sequence, else a Vec2 whose value is the next point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coveragelimit

private static int coveragelimit

xmin

private int xmin

xmax

private int xmax

ymin

private int ymin

ymax

private int ymax

blocksize

private int blocksize

coverage

private int coverage

gx

private int gx

gy

private int gy

x

private int x

y

private int y

covered

private boolean[][] covered

random

private java.util.Random random

v

private Vec2 v
Constructor Detail

RandomGridIterator

public RandomGridIterator(int width,
                          int height)
Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [0, width-1] x [0, height-1].


RandomGridIterator

public RandomGridIterator(int width,
                          int height,
                          java.util.Random random)
Constructs a RandomGridIterator. This iterates pseudo-randomly over the integer grid [0, width-1] x [0, height-1] using the random sequence generator 'random'.


RandomGridIterator

public RandomGridIterator(int xorigin,
                          int yorigin,
                          int width,
                          int height)
Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [xorigin, xorigin+width-1] x [yorigin, yorigin+height-1].


RandomGridIterator

public RandomGridIterator(int xorigin,
                          int yorigin,
                          int width,
                          int height,
                          java.util.Random random)
Constructs a RandomGridIterator that iterates pseudo-randomly over the integer grid [xorigin, xorigin+width-1] x [yorigin, yorigin+height-1] using the random sequence generator 'random'.

Method Detail

next

public Vec2 next()
Returns: null if there are no more points in the sequence, else a Vec2 whose value is the next point. The returned Vec2 may be modified by the caller. The same Vec2 may be written to again on the subsequent call to next().

Specified by:
next in interface Vec2Iterator

Initialize

private void Initialize()