- //System.out.println("Getting array index for (" + inX + ", " + inY + ") where the centre is at (" + _tileX + ", " + _tileY
- // + ") and grid coords (" + _gridCentreX + ", " + _gridCentreY + ")");
+ final int tileSpan = 1 << _zoom;
+ int deltaX = (inX - _tileX);
+ while (deltaX > (tileSpan/2)) {deltaX -= tileSpan;}
+ while (deltaX < (-tileSpan/2)) {deltaX += tileSpan;}
+
+ int x = getCacheCoordinate(deltaX + _gridCentreX);
+ int y = getCacheCoordinate(inY - _tileY + _gridCentreY);
+ return (x + y * GRID_SIZE);
+ }
+
+ /**
+ * Get the array index for the given coordinates, without wrapping x coords
+ * (used for deletion to avoid deleting the wrong tile)
+ * @param inX x coord of tile
+ * @param inY y coord of tile
+ * @return array index
+ */
+ private int getArrayIndexNoWrap(int inX, int inY)
+ {