package pathgame.rendering;

/** A container for tile texture coordinates.
 *
 * @author kajetan
 */
public class TileTexture
{
    public final static float TEXTURE_SIZE = 512;
    private final static float TILE_TEXTURE_PERCENT = TileRenderer.TILE_SIZE / TEXTURE_SIZE;
    private final static int TILES_PER_LINE = (int) (TEXTURE_SIZE / TileRenderer.TILE_SIZE);
    
    /** Returns a tile texture constructed from a given texture id.
     *
     * @param textureId a texture id
     * @return a tile texture constructed from a given texture id
     */
    public static TileTexture fromTextureId(int textureId)
    {
        float tMinX = (textureId % TILES_PER_LINE) * TILE_TEXTURE_PERCENT;
        float tMinY = (textureId/ TILES_PER_LINE) * TILE_TEXTURE_PERCENT;
        float tMaxX = tMinX + TILE_TEXTURE_PERCENT;
        float tMaxY = tMinY + TILE_TEXTURE_PERCENT;
        return new TileTexture(tMinX, tMinY, tMaxX, tMaxY);
    }
    
    private final float tMinX;
    private final float tMinY;
    private final float tMaxX;
    private final float tMaxY;
    
    /** Creates a new tile texture.
     *
     * @param tMinX the left x coordinate in the texture atlas
     * @param tMinY the upper y coordinate in the texture atlas
     * @param tMaxX the right x coordinate in the texture atlas
     * @param tMaxY the lower y coordinate in the texture atlas
     */
    public TileTexture(float tMinX, float tMinY, float tMaxX, float tMaxY)
    {     
        this.tMinX = tMinX;
        this.tMinY = tMinY;
        this.tMaxX = tMaxX;
        this.tMaxY = tMaxY;
    }

    /** Returns the the left x coordinate in the texture atlas.
     *
     * @return the left x coordinate in the texture atlas
     */
    public float getMinX()
    {
        return tMinX;
    }

    /** Returns the upper y coordinate in the texture atlas.
     *
     * @return the upper y coordinate in the texture atlas
     */
    public float getMinY()
    {
        return tMinY;
    }
             
    /** Returns the right x coordinate in the texture atlas.
     *
     * @return the right x coordinate in the texture atlas
     */
    public float getMaxX()
    {
        return tMaxX;
    }

    /** Returns the lower y coordinate in the texture atlas.
     *
     * @return the lower y coordinate in the texture atlas
     */
    public float getMaxY()
    {
        return tMaxY;
    }
}