Changeset 4869 in josm for trunk/src/org/openstreetmap/josm/data/coor
- Timestamp:
- 24.01.2012 21:52:43 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r4580 r4869 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.coor; 3 4 import static org.openstreetmap.josm.tools.I18n.trc;5 3 6 4 import static java.lang.Math.PI; … … 11 9 import static java.lang.Math.sqrt; 12 10 import static java.lang.Math.toRadians; 11 import static org.openstreetmap.josm.tools.I18n.trc; 13 12 14 13 import java.math.BigDecimal; … … 30 29 public class LatLon extends Coordinate { 31 30 32 31 33 32 /** 34 33 * Minimum difference in location to not be represented as the same position. … … 41 40 private static DecimalFormat cDmsSecondFormatter = new DecimalFormat("00.0"); 42 41 private static DecimalFormat cDmMinuteFormatter = new DecimalFormat("00.000"); 43 public static DecimalFormat cDdFormatter;42 public static final DecimalFormat cDdFormatter; 44 43 static { 45 44 // Don't use the localized decimal separator. This way we can present … … 68 67 return lon >= -180d && lon <= 180d; 69 68 } 70 71 /**72 * Replies true if lat is in the range [-90,90] and lon is in the range [-180,180]73 * 74 * @return true if lat is in the range [-90,90] and lon is in the range [-180,180]75 */76 public boolean isValid() {77 return isValidLat(lat()) && isValidLon(lon());78 }79 69 70 /** 71 * Replies true if lat is in the range [-90,90] and lon is in the range [-180,180] 72 * 73 * @return true if lat is in the range [-90,90] and lon is in the range [-180,180] 74 */ 75 public boolean isValid() { 76 return isValidLat(lat()) && isValidLon(lon()); 77 } 78 80 79 public static double toIntervalLat(double value) { 81 80 if (value < -90) … … 88 87 /** 89 88 * Returns a valid OSM longitude [-180,+180] for the given extended longitude value. 90 * For example, a value of -181 will return +179, a value of +181 will return -179. 89 * For example, a value of -181 will return +179, a value of +181 will return -179. 91 90 * @param lon A longitude value not restricted to the [-180,+180] range. 92 91 */ 93 92 public static double toIntervalLon(double value) { 94 if (isValidLon(value)) {93 if (isValidLon(value)) 95 94 return value; 96 }else {95 else { 97 96 int n = (int) (value + Math.signum(value)*180.0) / 360; 98 97 return value - n*360.0; 99 98 } 100 99 } 101 100 102 101 /** 103 102 * Replies the coordinate in degrees/minutes/seconds format … … 180 179 Bounds b = Main.getProjection().getWorldBoundsLatLon(); 181 180 return lat() < b.getMin().lat() || lat() > b.getMax().lat() || 182 lon() < b.getMin().lon() || lon() > b.getMax().lon();181 lon() < b.getMin().lon() || lon() > b.getMax().lon(); 183 182 } 184 183 … … 220 219 * http://math.stackexchange.com/questions/720/how-to-calculate-a-heading-on-the-earths-surface 221 220 * for some hints how it is derived.) 222 * 221 * 223 222 * @param other the "destination" position 224 223 * @return heading in the range 0 <= hd < 2*PI … … 233 232 } 234 233 return hd; 235 }234 } 236 235 237 236 /** … … 258 257 return "LatLon[lat="+lat()+",lon="+lon()+"]"; 259 258 } 260 259 261 260 /** 262 261 * Returns the value rounded to OSM precisions, i.e. to … … 278 277 public static double roundToOsmPrecisionStrict(double value) { 279 278 double absV = Math.abs(value); 280 int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 279 int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 281 280 return BigDecimal.valueOf(value).round(new MathContext(numOfDigits)).doubleValue(); 282 281 } … … 292 291 roundToOsmPrecision(lat()), 293 292 roundToOsmPrecision(lon()) 294 );293 ); 295 294 } 296 295 … … 305 304 roundToOsmPrecisionStrict(lat()), 306 305 roundToOsmPrecisionStrict(lon()) 307 );306 ); 308 307 } 309 308
Note: See TracChangeset
for help on using the changeset viewer.
