net.refractions.udig.project.render
Class TileCalculator

java.lang.Object
  extended by net.refractions.udig.project.render.TileCalculator

public class TileCalculator
extends java.lang.Object

A helper class which divides an area into tiles or a minimum size. Provides a number of convenience methods.

Author:
jones

Constructor Summary
TileCalculator(java.awt.geom.AffineTransform worldToScreen, java.awt.Dimension tileSize)
          Creates a new instance, the bounds must be set before it is ready to be used.
TileCalculator(java.awt.geom.AffineTransform worldToScreen, java.awt.Dimension tileSize, Envelope bounds)
          Creates a new instance.
 
Method Summary
 Envelope getBounds()
           
 java.awt.Rectangle getScreenRandom()
          Gets a random tile in screen coordinates.
 java.awt.Rectangle getScreenTile(int x, int y)
          Return the Rectangle (screen coordinates) of the tile indexed by x and y.
 java.awt.geom.Dimension2D getTileSize()
           
 Envelope getWorldRandom()
          Gets a random tile in world coordinates.
 Envelope getWorldTile(int x, int y)
          Return the Envelope (world coordinates) of the tile indexed by x and y.
 java.awt.geom.AffineTransform getWorldToScreen()
           
 int numXTiles()
          Returns the number of tiles in the X-direction
 int numYTiles()
          Returns the number of tiles in the Y-direction
 void resetRandomizer()
          Resets so that the getRandom() will clear its cache of visited tiles.
 void setBounds(Envelope bounds)
           
 void setTileSize(java.awt.Dimension tileSize)
           
 void setWorldToScreen(java.awt.geom.AffineTransform worldToScreen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TileCalculator

public TileCalculator(java.awt.geom.AffineTransform worldToScreen,
                      java.awt.Dimension tileSize)
Creates a new instance, the bounds must be set before it is ready to be used.

Parameters:
worldToScreen - the transform from world coordinates to screen coordinates
tileSize - the size of the tiles to create.

TileCalculator

public TileCalculator(java.awt.geom.AffineTransform worldToScreen,
                      java.awt.Dimension tileSize,
                      Envelope bounds)
Creates a new instance. It is ready to be queried immediately.

Parameters:
worldToScreen - the transform from world coordinates to screen coordinates
tileSize - the size of the tiles to create.
Method Detail

numXTiles

public int numXTiles()
Returns the number of tiles in the X-direction

Returns:

numYTiles

public int numYTiles()
Returns the number of tiles in the Y-direction

Returns:

getWorldTile

public Envelope getWorldTile(int x,
                             int y)
Return the Envelope (world coordinates) of the tile indexed by x and y.

Returns:
the Envelope (world coordinates) of the tile indexed by x and y.

getScreenTile

public java.awt.Rectangle getScreenTile(int x,
                                        int y)
Return the Rectangle (screen coordinates) of the tile indexed by x and y.

Returns:
the Rectangle (screen coordinates) of the tile indexed by x and y.

resetRandomizer

public void resetRandomizer()
Resets so that the getRandom() will clear its cache of visited tiles.


getWorldRandom

public Envelope getWorldRandom()
Gets a random tile in world coordinates. Each tile is visited only once and after all the tiles have been visited null will be returned.

WARNING: If each tile is visited one and only once regardless of whether getWorldRandom() or getScreenRandom() is used

Returns:
a random tile in world coordinates.

getScreenRandom

public java.awt.Rectangle getScreenRandom()
Gets a random tile in screen coordinates. Each tile is visited only once and after all the tiles have been visited null will be returned.

WARNING: If each tile is visited one and only once regardless of whether getWorldRandom() or getScreenRandom() is used

Returns:
a random tile in screen coordinates

getBounds

public Envelope getBounds()
Returns:
Returns the bounds.

setBounds

public void setBounds(Envelope bounds)
Parameters:
bounds - The bounds to set.

getTileSize

public java.awt.geom.Dimension2D getTileSize()
Returns:
Returns the tileSize.

setTileSize

public void setTileSize(java.awt.Dimension tileSize)
Parameters:
tileSize - The tileSize to set.

getWorldToScreen

public java.awt.geom.AffineTransform getWorldToScreen()
Returns:
Returns the worldToScreen.

setWorldToScreen

public void setWorldToScreen(java.awt.geom.AffineTransform worldToScreen)
Parameters:
worldToScreen - The worldToScreen to set.