001// License: GPL. For details, see Readme.txt file. 002package org.openstreetmap.gui.jmapviewer; 003 004/** 005 * @author w 006 * 007 */ 008public class TileXY { 009 /** 010 * x index of the tile (horizontal) 011 */ 012 private final double x; 013 014 /** 015 * y number of the tile (vertical) 016 */ 017 private final double y; 018 019 /** 020 * Returns an instance of coordinates. 021 * 022 * @param d number of the tile 023 * @param e number of the tile 024 */ 025 public TileXY(double d, double e) { 026 this.x = d; 027 this.y = e; 028 } 029 030 /** 031 * @return x index of the tile as integer 032 */ 033 public int getXIndex() { 034 return x < 0 ? (int) Math.ceil(x) : (int) Math.floor(x); 035 } 036 037 /** 038 * @return y index of the tile as integer 039 */ 040 public int getYIndex() { 041 return y < 0 ? (int) Math.ceil(y) : (int) Math.floor(y); 042 } 043 044 /** 045 * @return x index as double, might be non integral, when the point is not topleft corner of the tile 046 */ 047 public double getX() { 048 return x; 049 } 050 051 /** 052 * @return y index as double, might be non integral, when the point is not topleft corner of the tile 053 */ 054 public double getY() { 055 return y; 056 } 057}