Changeset 16959 in osm for applications/viewer


Ignore:
Timestamp:
2009-08-10T12:04:42+02:00 (15 years ago)
Author:
stotz
Message:

LonToX mathematically optimized; uses now long instead of double

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java

    r14053 r16959  
    4646     * Transform longitude to pixelspace
    4747     *
     48     * <p>
     49     * Mathematical optimization<br>
     50     * <code>
     51     * x = radius(aZoomlevel) * toRadians(aLongitude) + falseEasting(aZoomLevel)<br>
     52     * x = getMaxPixels(aZoomlevel) / (2 * PI) * (aLongitude * PI) / 180 + getMaxPixels(aZoomlevel) / 2<br>
     53     * x = getMaxPixels(aZoomlevel) * aLongitude / 360 + 180 * getMaxPixels(aZoomlevel) / 360<br>
     54     * x = getMaxPixels(aZoomlevel) * (aLongitude + 180) / 360<br>
     55     * </code>
     56     * </p>
     57     *
    4858     * @param aLongitude
    4959     *            [-180..180]
    5060     * @return [0..2^Zoomlevel*TILE_SIZE[
     61     * @author Jan Peter Stotz
    5162     */
    5263    public static int LonToX(double aLongitude, int aZoomlevel) {
    53         double longitude = Math.toRadians(aLongitude);
    54         int x = (int) ((radius(aZoomlevel) * longitude) + falseEasting(aZoomlevel));
    55         x = Math.min(x, getMaxPixels(aZoomlevel) - 1);
     64        int mp = getMaxPixels(aZoomlevel);
     65        int x = (int) ((mp * (aLongitude + 180l)) / 360l);
     66        x = Math.min(x, mp - 1);
    5667        return x;
    5768    }
Note: See TracChangeset for help on using the changeset viewer.