int tileX = Math.min(x / twidth, getTilesPerRow() - 1); int tileY = y / theight;
int tileX = Math.max(0, Math.min(x / twidth, tilesPerRow - 1)); int tileY = Math.max(0, Math.min(y / theight, rows - 1));
    private Point getTileCoordinates(int x, int y) {        int twidth = tileset.getTileWidth() + 1;        int theight = tileset.getTileHeight() + 1;        int tileX = Math.min(x / twidth, getTilesPerRow() - 1);        int tileY = y / theight;        return new Point(tileX, tileY);    }