Index: /trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 9166)
+++ /trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 9167)
@@ -16,5 +16,4 @@
 import java.util.regex.Pattern;
 
-import org.openstreetmap.gui.jmapviewer.OsmMercator;
 import org.openstreetmap.gui.jmapviewer.Tile;
 import org.openstreetmap.gui.jmapviewer.TileXY;
@@ -23,5 +22,5 @@
 import org.openstreetmap.gui.jmapviewer.tilesources.TMSTileSource;
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.ProjectionBounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -40,5 +39,4 @@
     private final Set<String> serverProjections;
     private EastNorth topLeftCorner;
-    private Bounds worldBounds;
     private int[] tileXMax;
     private int[] tileYMax;
@@ -96,10 +94,10 @@
      */
     public void initProjection(Projection proj) {
-        this.worldBounds = getWorldBounds();
-        EastNorth min = proj.latlon2eastNorth(worldBounds.getMin());
-        EastNorth max = proj.latlon2eastNorth(worldBounds.getMax());
+        ProjectionBounds worldBounds = proj.getWorldBoundsBoxEastNorth();
+        EastNorth min = worldBounds.getMin();
+        EastNorth max = worldBounds.getMax();
         this.topLeftCorner = new EastNorth(min.east(), max.north());
 
-        LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon());
+        EastNorth bottomRight = new EastNorth(worldBounds.getMax().east(), worldBounds.getMin().north());
 
         // use 256 as "tile size" to keep the scale in line with default tiles in Mercator projection
@@ -113,5 +111,5 @@
             // this makes the zoom levels "glued" to standard TMS zoom levels
             degreesPerTile[zoom] = (SCALE_DENOMINATOR_ZOOM_LEVEL_1 / Math.pow(2, zoom - 1)) * crsScale;
-            TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom);
+            TileXY maxTileIndex = eastNorthToTileXY(bottomRight, zoom);
             tileXMax[zoom] = maxTileIndex.getXIndex();
             tileYMax[zoom] = maxTileIndex.getYIndex();
@@ -243,4 +241,8 @@
         Projection proj = Main.getProjection();
         EastNorth enPoint = proj.latlon2eastNorth(new LatLon(lat, lon));
+        return eastNorthToTileXY(enPoint, zoom);
+    }
+
+    private TileXY eastNorthToTileXY(EastNorth enPoint, int zoom) {
         double scale = getDegreesPerTile(zoom);
         return new TileXY(
@@ -356,23 +358,3 @@
         return degreesPerTile[zoom];
     }
-
-    /**
-     * returns world bounds, but detect situation, when default bounds are provided (-90, -180, 90, 180), and projection
-     * returns very close values for both min and max X. To work around this problem, cap this projection on north and south
-     * pole, the same way they are capped in Mercator projection, so conversions should work properly
-     */
-    private static Bounds getWorldBounds() {
-        Projection proj = Main.getProjection();
-        Bounds bounds = proj.getWorldBoundsLatLon();
-        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
-        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
-
-        if (Math.abs(min.getX() - max.getX()) < 1 && bounds.equals(new Bounds(new LatLon(-90, -180), new LatLon(90, 180)))) {
-            return new Bounds(
-                    new LatLon(OsmMercator.MIN_LAT, bounds.getMinLon()),
-                    new LatLon(OsmMercator.MAX_LAT, bounds.getMaxLon())
-                    );
-        }
-        return bounds;
-    }
 }
Index: /trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java	(revision 9166)
+++ /trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java	(revision 9167)
@@ -15,5 +15,4 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.BBox;
 import org.openstreetmap.josm.data.projection.CustomProjection;
 import org.openstreetmap.josm.data.projection.Projection;
@@ -107,6 +106,7 @@
         TemplatedWMSTileSource source = getSource();
 
-        verifyLocation(source, new LatLon(60, 18), 3);
-        verifyLocation(source, new LatLon(60, 18));
+        verifyTileSquarness(source, 0, 1, 4);
+        verifyLocation(source, new LatLon(60, 18.1), 3);
+        verifyLocation(source, new LatLon(60, 18.1));
     }
 
@@ -158,13 +158,23 @@
                 tileIndex.getYIndex() <= source.getTileYMax(z));
 
+        EastNorth locationEN = Main.getProjection().latlon2eastNorth(location);
+        EastNorth x1 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex, z));
+        EastNorth x2 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z));
         // test that location is within tile bounds
-        BBox bbox = new BBox(
-                getTileLatLon(source, tileIndex, z),
-                getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z)
-                );
-        assertTrue(location.toDisplayString() + " not within " + bbox.toString() +
+        assertTrue(locationEN.toString() + " not within " + bboxStr(x1, x2) +
                 " for tile " + z + "/" + tileIndex.getXIndex() + "/" + tileIndex.getYIndex(),
-                bbox.bounds(location));
+                isWithin(locationEN, x1, x2));
         verifyTileSquarness(source, tileIndex.getXIndex(), tileIndex.getYIndex(), z);
+    }
+
+    private static boolean isWithin(EastNorth point, EastNorth topLeft, EastNorth bottomRight) {
+        return Math.min(topLeft.east(), bottomRight.east()) <= point.east() &&
+                point.east() <= Math.max(topLeft.east(), bottomRight.east())  &&
+                Math.min(topLeft.north(), bottomRight.north()) <= point.north() &&
+                point.north() <= Math.max(topLeft.north(), bottomRight.north());
+    }
+
+    private static String bboxStr(EastNorth x1, EastNorth x2) {
+        return "[" + x1.east() +", " + x1.north() + ", " + x2.east() + ", " + x2.north() +"]";
     }
 
