Changeset 9167 in josm for trunk/test


Ignore:
Timestamp:
2015-12-26T20:41:45+01:00 (5 years ago)
Author:
wiktorn
Message:
  • Move TemplatedWMSTileSource to Projection.getWorldBoundsBoxEastNorth
  • fix failing tests - move to EastNorth computations instead of LatLon,

which might be non-square, which lead to trouble checking, whether point was
within the bounds or not

See #12186

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java

    r8857 r9167  
    1515import org.openstreetmap.josm.data.coor.EastNorth;
    1616import org.openstreetmap.josm.data.coor.LatLon;
    17 import org.openstreetmap.josm.data.osm.BBox;
    1817import org.openstreetmap.josm.data.projection.CustomProjection;
    1918import org.openstreetmap.josm.data.projection.Projection;
     
    107106        TemplatedWMSTileSource source = getSource();
    108107
    109         verifyLocation(source, new LatLon(60, 18), 3);
    110         verifyLocation(source, new LatLon(60, 18));
     108        verifyTileSquarness(source, 0, 1, 4);
     109        verifyLocation(source, new LatLon(60, 18.1), 3);
     110        verifyLocation(source, new LatLon(60, 18.1));
    111111    }
    112112
     
    158158                tileIndex.getYIndex() <= source.getTileYMax(z));
    159159
     160        EastNorth locationEN = Main.getProjection().latlon2eastNorth(location);
     161        EastNorth x1 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex, z));
     162        EastNorth x2 = Main.getProjection().latlon2eastNorth(getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z));
    160163        // test that location is within tile bounds
    161         BBox bbox = new BBox(
    162                 getTileLatLon(source, tileIndex, z),
    163                 getTileLatLon(source, tileIndex.getXIndex() + 1, tileIndex.getYIndex() + 1, z)
    164                 );
    165         assertTrue(location.toDisplayString() + " not within " + bbox.toString() +
     164        assertTrue(locationEN.toString() + " not within " + bboxStr(x1, x2) +
    166165                " for tile " + z + "/" + tileIndex.getXIndex() + "/" + tileIndex.getYIndex(),
    167                 bbox.bounds(location));
     166                isWithin(locationEN, x1, x2));
    168167        verifyTileSquarness(source, tileIndex.getXIndex(), tileIndex.getYIndex(), z);
     168    }
     169
     170    private static boolean isWithin(EastNorth point, EastNorth topLeft, EastNorth bottomRight) {
     171        return Math.min(topLeft.east(), bottomRight.east()) <= point.east() &&
     172                point.east() <= Math.max(topLeft.east(), bottomRight.east())  &&
     173                Math.min(topLeft.north(), bottomRight.north()) <= point.north() &&
     174                point.north() <= Math.max(topLeft.north(), bottomRight.north());
     175    }
     176
     177    private static String bboxStr(EastNorth x1, EastNorth x2) {
     178        return "[" + x1.east() +", " + x1.north() + ", " + x2.east() + ", " + x2.north() +"]";
    169179    }
    170180
Note: See TracChangeset for help on using the changeset viewer.