Package com.kheops.jmap.client.layers
Class TileSet
java.lang.Object
com.kheops.jmap.client.layers.TileSet
- Direct Known Subclasses:
SharedTileSet
A TileSet is composed by a set of orthogonal tiles organized in the form of
a N x M grid and a universe tile of infinite dimension. It offers methods
that do operations on the tiles.
Each tile can be accessed either by its (n,m) grid position (Ex: 4th column and 3rd row, where columns and rows start at zero) or by its sequential position (ex: 23rd tile, where the first tile is top left at position 0). The universal tile is assigned position -1.
Here is an example of a 5 by 6 tile set:
5 columns
00 01 02 03 04 6
05 06 07 08 09
10 11 12 13 14 r
15 16 17 18 19 o
20 21 22 23 24 w
25 26 27 28 29 s
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddElement(K2DElement elem) Adds an element to the tile that should contain it.voidclone()voidclose()Resets the current tile set.findTileContaining(Point coord) Finds the tile containing the specified coordinate.findTileContaining(Point coord, boolean keepIt) Finds the tile containing the specified coordinate.Finds the tiles containing (completely or partially) the specified rectangle.findTilesContaining(OrientedRectangle rect, boolean keepIt) Finds the tiles containing (completely or partially) the specified rectangle.findTilesContaining(Rectangle rect, boolean keepIt) Finds the tiles containing (completely or partially) the specified rectangle.findTilesContaining(Vector<Tile> result, OrientedRectangle rect, boolean keepIt) Finds the tiles containing (completely or partially) the specified rectangle.findTilesContaining(Vector<Tile> result, Rectangle rect, boolean keepIt) Finds the tiles containing (completely or partially) the specified rectangle.Gets an enumeration containing all the tiles of this tileSet.Gets the bounds of this tile setintGets the number of elements in this tile set.intGets the number of loaded tiles in this tile set.intgetNbCol()Gets the number of columnsintgetNbRow()Gets the number of rowsgetTile(int pos) Returns the tile at position n if it existsgetTile(int col, int row) Returns the specified tile if it existsgetTileRegion(int pos) Calculates the region occupied by the specified tile.getTileRegion(int col, int row) Calculates the region occupied by the specified tile.protected TileinitTile(int col, int row) voidRemoves all the tiles from this tile set.removeElement(long elementId) Removes the element that has the specified idbooleanremoveElement(K2DElement elem) Removes the specified element.voidSets the tile specified in parameter in the tileSet.share()voidunloadTile(Tile tile) voidvalidateTiling(K2DElement[] elements)
-
Constructor Details
-
TileSet
public TileSet()Constructs a new TileSet containing only the universe tile. -
TileSet
Constructs a TileSet with nRow x nCol tiles of the specified size.- Parameters:
nCol- the number of columnsnRow- the number of rowsregion- the region of this tile set
-
-
Method Details
-
close
public void close()Resets the current tile set. Note that this method had the same behaviour asremoveAllElements() -
removeAllElements
public void removeAllElements()Removes all the tiles from this tile set. -
getTile
Returns the specified tile if it exists- Parameters:
col- the column indexrow- the row index- Returns:
- the appropriate tile if it exists, null otherwise.
-
getTile
Returns the tile at position n if it exists- Parameters:
pos- the position of the tile- Returns:
- the appropriate tile if it exists, null otherwise.
-
getAllTiles
Gets an enumeration containing all the tiles of this tileSet.- Returns:
- the enumeration of all the tiles.
-
getTileRegion
Calculates the region occupied by the specified tile.- Parameters:
col- Column of the tilerow- Row of the tile- Returns:
- the region of the tile
-
getTileRegion
Calculates the region occupied by the specified tile.- Parameters:
pos- Sequential position of the tile- Returns:
- the region of the tile
-
initTile
-
getElementCount
public int getElementCount()Gets the number of elements in this tile set.- Returns:
- element count.
-
addElement
Adds an element to the tile that should contain it. If it overlaps more than one tile, it will be put the element in the universe tile.- Parameters:
elem- the element to be added.- Returns:
- the position of the tile containing the newly added element.
-
removeElement
Removes the specified element.- Parameters:
elem- the element to be removed.- Returns:
- true if the element was properly removed false otherwise.
-
clearTile
-
unloadTile
-
removeElement
Removes the element that has the specified id- Parameters:
elementId- the id of the element to be removed- Returns:
- the removed element if it was found, null otherwise
-
findTileContaining
Finds the tile containing the specified coordinate.- Parameters:
coord- the coordinate- Returns:
- the tile containing the coordinate
-
findTileContaining
Finds the tile containing the specified coordinate. The boolean flag keepIt determines if a new instance of the tile is added to the tile set in memory or discarded.- Parameters:
coord- the coordinatekeepIt- if true adds the new Tile instance to the tile set in memory- Returns:
- the tile containing the coordinate
-
findTilesContaining
Finds the tiles containing (completely or partially) the specified rectangle.- Parameters:
rect- the corresponding rectangle.- Returns:
- a vector containing the matching tiles
-
findTilesContaining
Finds the tiles containing (completely or partially) the specified rectangle. The boolean flag keepIt determines if a new instance of the tile is added to the tile set in memory.- Parameters:
rect- the rectamglekeepIt- if true adds the new Tile instance to the tile set in memory- Returns:
- tile
-
findTilesContaining
Finds the tiles containing (completely or partially) the specified rectangle. The boolean flag keepIt determines if a new instance of the tile is added to the tile set in memory.- Parameters:
rect- the rectanglekeepIt- if true adds the new Tile instance to the tile set in memory- Returns:
- tile
-
findTilesContaining
Finds the tiles containing (completely or partially) the specified rectangle. The boolean flag keepIt determines if a new instance of the tile is added to the tile set in memory.- Parameters:
result- the Vector object to initialize and returnrect- the rectanglekeepIt- if true adds the new Tile instance to the tile set in memory- Returns:
- a vector containing the matching tiles
-
findTilesContaining
public Vector<Tile> findTilesContaining(Vector<Tile> result, OrientedRectangle rect, boolean keepIt) Finds the tiles containing (completely or partially) the specified rectangle. The boolean flag keepIt determines if a new instance of the tile is added to the tile set in memory.- Parameters:
result- the Vector object to initialize and returnrect- the rectanglekeepIt- if true adds the new Tile instance to the tile set in memory- Returns:
- a vector containing the matching tiles
-
getNbCol
public int getNbCol()Gets the number of columns- Returns:
- number of columns
-
getNbRow
public int getNbRow()Gets the number of rows- Returns:
- the number of rows
-
getBounds
Gets the bounds of this tile set- Returns:
- bounds
-
setTile
Sets the tile specified in parameter in the tileSet.- Parameters:
tile- the tile.
-
clone
-
validateTiling
-
getLoadedTileCount
public int getLoadedTileCount()Gets the number of loaded tiles in this tile set.- Returns:
- the number of loaded tiles in this tile set.
-