texturesynthesis.wangtilesynthesizer.wangtiles
Class WangTiling

java.lang.Object
  extended by texturesynthesis.wangtilesynthesizer.wangtiles.WangTiling

public class WangTiling
extends java.lang.Object

This class represents a Wang tiling of a plane. The tiling is rectangular. The size of the plane can not be modified after it is set.

Author:
Aki Koskinen

Field Summary
private  int horizontalTiles
          Number of tiles in the horizontal direction.
private  int[][] tiles
          The indexes to the tiles.
private  WangTileSet tileSet
          The tile set that is used for this tiling.
private  int verticalTiles
          Number of tiles in the vertical direction.
 
Constructor Summary
WangTiling(int horizontal, int vertical)
          Constructs a wang tiling instance of a given size.
 
Method Summary
private  boolean fitsTo(WangTile tmpTile, int x, int y)
          Checks if a tile fits to a position in this tiling.
 void generateWangTiling(WangTileSet tileSet)
          Fills this Wang tiling with tiles from the given set.
private  int getMatchingTileFromSet(int x, int y)
          Returns a tile that fits to a position x, y in this tiling.
 int getNumHorizontalTiles()
          Returns the number of tiles in the horizontal direction.
 int getNumVerticalTiles()
          Returns the number of tiles in the vertical direction.
 WangTile getTileAt(int x, int y)
          Returns the Wang tile at position x,y
 int getTileIndexAt(int x, int y)
          Returns the Wang tile index at position x,y
 boolean isReadyForTiling()
          Checks if this tiling is ready for filling.
 void setTileAt(int index, int x, int y)
          Sets a Wang tile index at position x,y.
 java.lang.String toString()
          A string representation of this Wang tiling.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

horizontalTiles

private int horizontalTiles
Number of tiles in the horizontal direction.


verticalTiles

private int verticalTiles
Number of tiles in the vertical direction.


tileSet

private WangTileSet tileSet
The tile set that is used for this tiling.


tiles

private int[][] tiles
The indexes to the tiles.

Constructor Detail

WangTiling

public WangTiling(int horizontal,
                  int vertical)
           throws java.lang.IllegalArgumentException
Constructs a wang tiling instance of a given size.

Parameters:
horizontal - Number of tiles in the horizontal direction.
vertical - Number of tiles in the vertical direction.
Throws:
java.lang.IllegalArgumentException - if an invalid size attribute is given.
Method Detail

getNumHorizontalTiles

public int getNumHorizontalTiles()
Returns the number of tiles in the horizontal direction.

Returns:
the number of tiles in the horizontal direction.

getNumVerticalTiles

public int getNumVerticalTiles()
Returns the number of tiles in the vertical direction.

Returns:
the number of tiles in the vertical direction.

isReadyForTiling

public boolean isReadyForTiling()
Checks if this tiling is ready for filling.

Returns:
true if this tiling is ready for filling.

setTileAt

public void setTileAt(int index,
                      int x,
                      int y)
Sets a Wang tile index at position x,y.

Parameters:
index - the Wang tile index.
x - horizontal position coordinate.
y - vertical position coordinate.

getTileAt

public WangTile getTileAt(int x,
                          int y)
Returns the Wang tile at position x,y

Parameters:
x - horizontal position coordinate
y - vertical position coordinate
Returns:
the Wang tile

getTileIndexAt

public int getTileIndexAt(int x,
                          int y)
Returns the Wang tile index at position x,y

Parameters:
x - horizontal position coordinate
y - vertical position coordinate
Returns:
the index of the tile

generateWangTiling

public void generateWangTiling(WangTileSet tileSet)
Fills this Wang tiling with tiles from the given set.

Parameters:
tileSet - the tile set.

getMatchingTileFromSet

private int getMatchingTileFromSet(int x,
                                   int y)
Returns a tile that fits to a position x, y in this tiling.

Parameters:
x - horizontal position.
y - vertical position.
Returns:
an index of a matching tile to the tile set.

fitsTo

private boolean fitsTo(WangTile tmpTile,
                       int x,
                       int y)
Checks if a tile fits to a position in this tiling.

Parameters:
tmpTile - the tile to be tested.
x - the horizontal position.
y - the vertical position.
Returns:
true if the tile fits, false if it doesn't.

toString

public java.lang.String toString()
A string representation of this Wang tiling.

Overrides:
toString in class java.lang.Object
Returns:
this Wang tiling as a String.