- Timestamp:
- 2012-06-08T11:20:48+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r5235 r5268 11 11 import static org.openstreetmap.josm.tools.I18n.trc; 12 12 13 import java.math.BigDecimal;14 import java.math.MathContext;15 13 import java.text.DecimalFormat; 16 14 import java.text.NumberFormat; … … 35 33 */ 36 34 public static final double MAX_SERVER_PRECISION = 1e-7; 35 public static final double MAX_SERVER_INV_PRECISION = 1e7; 37 36 public static final int MAX_SERVER_DIGITS = 7; 38 37 … … 265 264 */ 266 265 public static double roundToOsmPrecision(double value) { 267 return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; // causes tiny rounding errors (see LatLonTest) 268 } 269 270 /** 271 * Returns the value rounded to OSM precisions, i.e. to 272 * LatLon.MAX_SERVER_PRECISION. The result is guaranteed to be exact, but at a great cost. 273 * This function is about 1000 times slower than roundToOsmPrecision(), use it with caution. 266 return Math.round(value * MAX_SERVER_INV_PRECISION) / MAX_SERVER_INV_PRECISION; 267 } 268 269 /** 270 * Returns the value rounded to OSM precision. This function is now the same as 271 * {@link #roundToOsmPrecision(double)}, since the rounding error has been fixed. 274 272 * 275 273 * @return rounded value 276 274 */ 277 275 public static double roundToOsmPrecisionStrict(double value) { 278 double absV = Math.abs(value); 279 int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 280 return BigDecimal.valueOf(value).round(new MathContext(numOfDigits)).doubleValue(); 276 return roundToOsmPrecision(value); 281 277 } 282 278
Note:
See TracChangeset
for help on using the changeset viewer.