Ignore:
Timestamp:
2013-08-21T13:38:23+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8986 - Data loading/bbox index counting optimization (patch by shinigami) + code cleanup in Quad* classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/QuadTiling.java

    r4319 r6171  
    99    public static final int TILES_PER_LEVEL_SHIFT = 2; // Has to be 2. Other parts of QuadBuckets code rely on it
    1010    public static final int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;
    11     static public final int X_PARTS = 360;
    12     static public final int X_BIAS = -180;
     11    public static final int X_PARTS = 360;
     12    public static final int X_BIAS = -180;
    1313
    14     static public final int Y_PARTS = 180;
    15     static public final int Y_BIAS = -90;
     14    public static final int Y_PARTS = 180;
     15    public static final int Y_BIAS = -90;
    1616
    17     public static LatLon tile2LatLon(long quad)
    18     {
     17    public static LatLon tile2LatLon(long quad) {
    1918        // The world is divided up into X_PARTS,Y_PARTS.
    2019        // The question is how far we move for each bit
     
    4443        return new LatLon(y, x);
    4544    }
    46     static long xy2tile(long x, long y)
    47     {
     45   
     46    static long xy2tile(long x, long y) {
    4847        long tile = 0;
    4948        int i;
     
    5857        return tile;
    5958    }
    60     static long coorToTile(LatLon coor)
    61     {
     59   
     60    static long coorToTile(LatLon coor) {
    6261        return quadTile(coor);
    6362    }
    64     static long lon2x(double lon)
    65     {
     63   
     64    static long lon2x(double lon) {
    6665        //return Math.round((lon + 180.0) * QuadBuckets.WORLD_PARTS / 360.0)-1;
    6766        long ret = (long)((lon + 180.0) * WORLD_PARTS / 360.0);
     
    7170        return ret;
    7271    }
    73     static long lat2y(double lat)
    74     {
     72   
     73    static long lat2y(double lat) {
    7574        //return Math.round((lat + 90.0) * QuadBuckets.WORLD_PARTS / 180.0)-1;
    7675        long ret = (long)((lat + 90.0) * WORLD_PARTS / 180.0);
     
    8079        return ret;
    8180    }
    82     static public long quadTile(LatLon coor)
    83     {
    84         return xy2tile(lon2x(coor.lon()),
    85                 lat2y(coor.lat()));
     81   
     82    public static long quadTile(LatLon coor) {
     83        return xy2tile(lon2x(coor.lon()), lat2y(coor.lat()));
    8684    }
    87     static public int index(int level, long quad)
    88     {
     85   
     86    public static int index(int level, long quad) {
    8987        long mask = 0x00000003;
    9088        int total_shift = TILES_PER_LEVEL_SHIFT*(NR_LEVELS-level-1);
    9189        return (int)(mask & (quad >> total_shift));
    9290    }
    93     static public int index(LatLon coor, int level) {
    94         // The nodes that don't return coordinates will all get
    95         // stuck in a single tile.  Hopefully there are not too
    96         // many of them
     91   
     92    /**
     93     * Returns quad tiling index for given coordinates and level.
     94     *
     95     * @param coor coordinates
     96     * @param level level
     97     *
     98     * @return quad tiling index for given coordinates and level.
     99     * @since 2263
     100     */
     101    public static int index(LatLon coor, int level) {
     102        // The nodes that don't return coordinates will all get stuck in a single tile.
     103        // Hopefully there are not too many of them
    97104        if (coor == null)
    98105            return 0;
    99106
    100         long x = lon2x(coor.lon());
    101         long y = lat2y(coor.lat());
     107        return index(coor.lat(), coor.lon(), level);
     108    }
     109
     110    /**
     111     * Returns quad tiling index for given coordinates and level.
     112     *
     113     * @param lat latitude
     114     * @param lon longitude
     115     * @param level level
     116     *
     117     * @return quad tiling index for given coordinates and level.
     118     * @since 6171
     119     */
     120    public static int index(final double lat, final double lon, final int level) {
     121        long x = lon2x(lon);
     122        long y = lat2y(lat);
    102123        int shift = NR_LEVELS-level-1;
    103124        return (int)((x >> shift & 1) * 2 + (y >> shift & 1));
Note: See TracChangeset for help on using the changeset viewer.