# Class IsoProjection

java.lang.Object
com.codename1.gaming.level.IsoProjection

public class IsoProjection extends Object

Maps between board cells (row, column) and screen pixels for the 2:1 isometric "diamond" layout used by board / strategy games.

This is the projection the `BoardGameSample` hand-rolled, promoted to a reusable piece so a board-mode `GameLevel` and its editor share one source of truth. A tile is `#getTileWidth()` x `#getTileHeight()` pixels (height is conventionally half the width), and `(#getOriginX(), #getOriginY())` is the screen position of cell (0,0)'s center. `#tileCenterX(int, int)` / `#tileCenterY(int, int)` go cell -> screen and `#pick(int, int)` inverts screen -> cell.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IsoProjection()`
  `IsoProjection(float originX, float originY, float tileWidth, float tileHeight)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `IsoProjection`
  `fit(int n, int viewWidth, int viewHeight)`
  Sizes the tiles and centers the board to fit an `n` x `n` grid inside a view of the given pixel size, matching the `BoardGameSample` fit (width-bound or height-bound, whichever is tighter, then centered).
  `float`
  `getOriginX()`
  `float`
  `getOriginY()`
  `float`
  `getTileHeight()`
  `float`
  `getTileWidth()`
  `int[]`
  `pick(int px, int py)`
  Inverts a screen pixel to the nearest cell, returned as `{row, col}`.
  `IsoProjection`
  `setOrigin(float originX, float originY)`
  `IsoProjection`
  `setTileSize(float tileWidth, float tileHeight)`
  `float`
  `tileCenterX(int row, int col)`
  The screen x of the center of cell (row, col).
  `float`
  `tileCenterY(int row, int col)`
  The screen y of the center of cell (row, col).

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### IsoProjection

    public IsoProjection()

  - ### IsoProjection

    public IsoProjection(float originX, float originY, float tileWidth, float tileHeight)

- ## Method Details

  - ### getOriginX

    public float getOriginX()

  - ### getOriginY

    public float getOriginY()

  - ### setOrigin

    public IsoProjection setOrigin(float originX, float originY)

  - ### getTileWidth

    public float getTileWidth()

  - ### getTileHeight

    public float getTileHeight()

  - ### setTileSize

    public IsoProjection setTileSize(float tileWidth, float tileHeight)

  - ### fit

    public IsoProjection fit(int n, int viewWidth, int viewHeight)
    Sizes the tiles and centers the board to fit an `n` x `n` grid inside a view of the given pixel size, matching the `BoardGameSample` fit (width-bound or height-bound, whichever is tighter, then centered).

  - ### tileCenterX

    public float tileCenterX(int row, int col)
    The screen x of the center of cell (row, col).

  - ### tileCenterY

    public float tileCenterY(int row, int col)
    The screen y of the center of cell (row, col).

  - ### pick

    public int[] pick(int px, int py)
    Inverts a screen pixel to the nearest cell, returned as `{row, col}`. The result is not clamped to any board size -- callers validate the range.