texturesynthesis.wangtilesynthesizer.wangtiles
Class WangTile

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

public class WangTile
extends java.lang.Object

This class represents a Wang tile. A Wang tile is a square with all it's four edges colored. A Wang tiling can be constructed from multiple Wang tiles by organizing the tiles to a plane so that adjacent edges have same colors. The tiles shouldn't be rotated. The coloring of edges is an abstract term. In this case integers greater than or equal to zero are used as colors.

Author:
Aki Koskinen

Field Summary
private  int eastColor
          The color of the east edge.
private  int northColor
          The color of the north edge.
private  int numHorizontalColors
          The number of the colors in the horizontal coloring.
private  int numVerticalColors
          The number of the colors in the vertical coloring.
private  int southColor
          The color of the south edge.
private  int westColor
          The color of the west edge.
 
Constructor Summary
WangTile(int horizontalColors, int verticalColors)
          Constructs a new Wang tile skeleton.
 
Method Summary
 boolean equals(WangTile anotherTile)
          Tests if this tile is similiar to another tile.
 int getEastColor()
          Returns the color of the east edge.
 int getNorthColor()
          Returns the color of the north edge.
 int getNumHorizontalColors()
          Gets the number of the colors in the horizontal coloring.
 int getNumVerticalColors()
          Gets the number of the colors in the vertical coloring.
 int getSouthColor()
          Returns the color of the south edge.
 int getWestColor()
          Returns the color of the west edge.
private  boolean hasCorrectColoring()
          Checks if this tile is colored.
private  boolean hasCorrectColoringLimits()
          Checks if this tile has coloring limits set.
 void makeRandom()
          Chooses colors for this tile's edges at random.
 void setEastColor(int color)
          Sets the east edge color of this tile.
 void setNorthColor(int color)
          Sets the north edge color of this tile.
 void setNumHorizontalColors(int numColors)
          Sets the number of the colors in the horizontal coloring.
 void setNumVerticalColors(int numColors)
          Sets the number of the colors in the vertical coloring.
 void setSouthColor(int color)
          Sets the south edge color of this tile.
 void setWestColor(int color)
          Sets the west edge color of this tile.
 java.lang.String toString()
          Returns a string representation of this tile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numHorizontalColors

private int numHorizontalColors
The number of the colors in the horizontal coloring. Minimum is 2.


numVerticalColors

private int numVerticalColors
The number of the colors in the vertical coloring. Minimum is 2.


northColor

private int northColor
The color of the north edge. The colors start from 0.


westColor

private int westColor
The color of the west edge. The colors start from 0.


southColor

private int southColor
The color of the south edge. The colors start from 0.


eastColor

private int eastColor
The color of the east edge. The colors start from 0.

Constructor Detail

WangTile

public WangTile(int horizontalColors,
                int verticalColors)
         throws java.lang.IllegalArgumentException
Constructs a new Wang tile skeleton. The colors of the edges must be set before the tile can be used.

Parameters:
horizontalColors - the number of horizontal colors
verticalColors - the number of vertical colors
Throws:
java.lang.IllegalArgumentException
Method Detail

getNumHorizontalColors

public int getNumHorizontalColors()
Gets the number of the colors in the horizontal coloring.

Returns:
the number of the colors.

setNumHorizontalColors

public void setNumHorizontalColors(int numColors)
                            throws java.lang.IllegalArgumentException,
                                   java.lang.IllegalStateException
Sets the number of the colors in the horizontal coloring.

Parameters:
numColors - the number of the colors.
Throws:
java.lang.IllegalArgumentException - if an argument less than 2 was given.
java.lang.IllegalStateException - if the number of colors was already set.

getNumVerticalColors

public int getNumVerticalColors()
Gets the number of the colors in the vertical coloring.

Returns:
the number of the colors.

setNumVerticalColors

public void setNumVerticalColors(int numColors)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.IllegalStateException
Sets the number of the colors in the vertical coloring.

Parameters:
numColors - the number of the colors.
Throws:
java.lang.IllegalArgumentException - if an argument less than 2 was given.
java.lang.IllegalStateException - if the number of colors was already set.

getNorthColor

public int getNorthColor()
Returns the color of the north edge.

Returns:
the north color.

setNorthColor

public void setNorthColor(int color)
                   throws java.lang.IllegalArgumentException,
                          java.lang.IllegalStateException
Sets the north edge color of this tile.

Parameters:
color - the color.
Throws:
java.lang.IllegalArgumentException - if the argument was less than zero or greater than (number_of_vertical_colors - 1).
java.lang.IllegalStateException - if the tile has no coloring limits, i.e. the numbers of horizontal and vertical colors aren't set yet.

getEastColor

public int getEastColor()
Returns the color of the east edge.

Returns:
Returns the eastColor.

setEastColor

public void setEastColor(int color)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException
Sets the east edge color of this tile.

Parameters:
color - the color.
Throws:
java.lang.IllegalArgumentException - if the argument was less than zero or greater than (number_of_horizontal_colors - 1).
java.lang.IllegalStateException - if the tile has no coloring limits, i.e. the numbers of horizontal and vertical colors aren't set yet.

getSouthColor

public int getSouthColor()
Returns the color of the south edge.

Returns:
Returns the southColor.

setSouthColor

public void setSouthColor(int color)
                   throws java.lang.IllegalArgumentException,
                          java.lang.IllegalStateException
Sets the south edge color of this tile.

Parameters:
color - the color.
Throws:
java.lang.IllegalArgumentException - if the argument was less than zero or greater than (number_of_vertical_colors - 1).
java.lang.IllegalStateException - if the tile has no coloring limits, i.e. the numbers of horizontal and vertical colors aren't set yet.

getWestColor

public int getWestColor()
Returns the color of the west edge.

Returns:
Returns the westColor.

setWestColor

public void setWestColor(int color)
                  throws java.lang.IllegalArgumentException,
                         java.lang.IllegalStateException
Sets the west edge color of this tile.

Parameters:
color - the color.
Throws:
java.lang.IllegalArgumentException - if the argument was less than zero or greater than (number_of_horizontal_colors - 1).
java.lang.IllegalStateException - if the tile has no coloring limits, i.e. the numbers of horizontal and vertical colors aren't set yet.

makeRandom

public void makeRandom()
Chooses colors for this tile's edges at random.


equals

public boolean equals(WangTile anotherTile)
Tests if this tile is similiar to another tile.

Parameters:
anotherTile - another tile.
Returns:
true if the another tile is similiar.

toString

public java.lang.String toString()
Returns a string representation of this tile.

Overrides:
toString in class java.lang.Object
Returns:
a String.

hasCorrectColoringLimits

private boolean hasCorrectColoringLimits()
Checks if this tile has coloring limits set. In other words if it is ready for coloring (setting the colors of the edges).

Returns:
true if this tile has coloring limits set.

hasCorrectColoring

private boolean hasCorrectColoring()
Checks if this tile is colored.

Returns:
true if this tile is colored.