Ignore:
Timestamp:
2009-08-10T14:45:01+02:00 (15 years ago)
Author:
stotz
Message:

XToLon mathematically optimized; speed-up about 300%

File:
1 edited

Legend:

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

    r16959 r16974  
    9090     * Transforms pixel coordinate X to longitude
    9191     *
     92     * <p>
     93     * Mathematical optimization<br>
     94     * <code>
     95     * lon = toDegree((aX - falseEasting(aZoomlevel)) / radius(aZoomlevel))<br>
     96     * lon = 180 / PI * ((aX - getMaxPixels(aZoomlevel) / 2) / getMaxPixels(aZoomlevel) / (2 * PI)<br>
     97     * lon = 180 * ((aX - getMaxPixels(aZoomlevel) / 2) / getMaxPixels(aZoomlevel))<br>
     98     * lon = 360 / getMaxPixels(aZoomlevel) * (aX - getMaxPixels(aZoomlevel) / 2)<br>
     99     * lon = 360 * aX / getMaxPixels(aZoomlevel) - 180<br>
     100     * </code>
     101     * </p>
    92102     * @param aX
    93103     *            [0..2^Zoomlevel*TILE_WIDTH[
    94104     * @return ]-180..180[
     105     * @author Jan Peter Stotz
    95106     */
    96107    public static double XToLon(int aX, int aZoomlevel) {
    97         aX -= falseEasting(aZoomlevel);
    98         double longRadians = aX / radius(aZoomlevel);
    99         double longDegrees = Math.toDegrees(longRadians);
    100         return longDegrees;
     108        return ((360d * aX) / getMaxPixels(aZoomlevel)) - 180.0;
    101109    }
    102110
Note: See TracChangeset for help on using the changeset viewer.