From 4b55043dccc51dc2f786876523e061976f02ad33 Mon Sep 17 00:00:00 2001 From: Emux Date: Mon, 31 Oct 2016 15:13:31 +0200 Subject: [PATCH] =?UTF-8?q?MercatorProjection.latitudeToY=20not=20work=20a?= =?UTF-8?q?t=20>=20=C2=B185.05113=C2=B0,=20fixes=20#222?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vtm/src/org/oscim/core/MercatorProjection.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vtm/src/org/oscim/core/MercatorProjection.java b/vtm/src/org/oscim/core/MercatorProjection.java index e4e8d422..ba497847 100644 --- a/vtm/src/org/oscim/core/MercatorProjection.java +++ b/vtm/src/org/oscim/core/MercatorProjection.java @@ -1,6 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2012 Hannes Janetzek + * Copyright 2016 devemux86 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -17,6 +18,8 @@ */ package org.oscim.core; +import org.oscim.utils.FastMath; + /** * An implementation of the spherical Mercator projection. */ @@ -68,14 +71,14 @@ public final class MercatorProjection { } /** - * Projects a longitude coordinate (in degrees) to the range [0.0,1.0] + * Projects a latitude coordinate (in degrees) to the range [0.0,1.0] * * @param latitude the latitude coordinate that should be converted. - * @return the position . + * @return the position. */ public static double latitudeToY(double latitude) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); - return 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI); + return FastMath.clamp(0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI), 0.0, 1.0); } public static double toLatitude(double y) { @@ -86,7 +89,7 @@ public final class MercatorProjection { * Projects a longitude coordinate (in degrees) to the range [0.0,1.0] * * @param longitude the longitude coordinate that should be converted. - * @return the position . + * @return the position. */ public static double longitudeToX(double longitude) { return (longitude + 180.0) / 360.0;