Class TileSet

java.lang.Object
com.kheops.jmap.client.layers.TileSet
All Implemented Interfaces:
Shareable, Cloneable
Direct Known Subclasses:
SharedTileSet

public class TileSet extends Object implements Shareable, Cloneable
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 Details

    • TileSet

      public TileSet()
      Constructs a new TileSet containing only the universe tile.
    • TileSet

      public TileSet(int nCol, int nRow, Rectangle region)
      Constructs a TileSet with nRow x nCol tiles of the specified size.
      Parameters:
      nCol - the number of columns
      nRow - the number of rows
      region - 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 as removeAllElements()
    • removeAllElements

      public void removeAllElements()
      Removes all the tiles from this tile set.
    • getTile

      public Tile getTile(int col, int row)
      Returns the specified tile if it exists
      Parameters:
      col - the column index
      row - the row index
      Returns:
      the appropriate tile if it exists, null otherwise.
    • getTile

      public Tile getTile(int pos)
      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

      public Enumeration<Tile> getAllTiles()
      Gets an enumeration containing all the tiles of this tileSet.
      Returns:
      the enumeration of all the tiles.
    • getTileRegion

      public Rectangle.Double getTileRegion(int col, int row)
      Calculates the region occupied by the specified tile.
      Parameters:
      col - Column of the tile
      row - Row of the tile
      Returns:
      the region of the tile
    • getTileRegion

      public Rectangle.Double getTileRegion(int pos)
      Calculates the region occupied by the specified tile.
      Parameters:
      pos - Sequential position of the tile
      Returns:
      the region of the tile
    • initTile

      protected Tile initTile(int col, int row)
    • getElementCount

      public int getElementCount()
      Gets the number of elements in this tile set.
      Returns:
      element count.
    • addElement

      public int addElement(K2DElement elem)
      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

      public boolean removeElement(K2DElement elem)
      Removes the specified element.
      Parameters:
      elem - the element to be removed.
      Returns:
      true if the element was properly removed false otherwise.
    • clearTile

      public void clearTile(Tile tile)
    • unloadTile

      public void unloadTile(Tile tile)
    • removeElement

      public K2DElement removeElement(long elementId)
      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

      public Tile findTileContaining(Point coord)
      Finds the tile containing the specified coordinate.
      Parameters:
      coord - the coordinate
      Returns:
      the tile containing the coordinate
    • findTileContaining

      public Tile findTileContaining(Point coord, boolean keepIt)
      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 coordinate
      keepIt - if true adds the new Tile instance to the tile set in memory
      Returns:
      the tile containing the coordinate
    • findTilesContaining

      public Vector<Tile> findTilesContaining(OrientedRectangle rect)
      Finds the tiles containing (completely or partially) the specified rectangle.
      Parameters:
      rect - the corresponding rectangle.
      Returns:
      a vector containing the matching tiles
    • findTilesContaining

      public Vector<Tile> findTilesContaining(Rectangle 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:
      rect - the rectamgle
      keepIt - if true adds the new Tile instance to the tile set in memory
      Returns:
      tile
    • findTilesContaining

      public Vector<Tile> findTilesContaining(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:
      rect - the rectangle
      keepIt - if true adds the new Tile instance to the tile set in memory
      Returns:
      tile
    • findTilesContaining

      public Vector<Tile> findTilesContaining(Vector<Tile> result, Rectangle 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 return
      rect - the rectangle
      keepIt - 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 return
      rect - the rectangle
      keepIt - 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

      public Rectangle getBounds()
      Gets the bounds of this tile set
      Returns:
      bounds
    • setTile

      public void setTile(Tile tile)
      Sets the tile specified in parameter in the tileSet.
      Parameters:
      tile - the tile.
    • share

      public Shareable share()
      Specified by:
      share in interface Shareable
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • validateTiling

      public void validateTiling(K2DElement[] elements)
    • getLoadedTileCount

      public int getLoadedTileCount()
      Gets the number of loaded tiles in this tile set.
      Returns:
      the number of loaded tiles in this tile set.