Changeset 4574 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-11-04T01:17:49+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r4541 r4574 244 244 */ 245 245 public static double roundToOsmPrecision(double value) { 246 return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; // causes tiny rounding errors (see LatLonTest) 247 } 248 249 /** 250 * Returns the value rounded to OSM precisions, i.e. to 251 * LatLon.MAX_SERVER_PRECISION. The result is guaranteed to be exact, but at a great cost. 252 * This function is about 1000 times slower than roundToOsmPrecision(), use it with caution. 253 * 254 * @return rounded value 255 */ 256 public static double roundToOsmPrecisionStrict(double value) { 246 257 double absV = Math.abs(value); 247 258 int numOfDigits = MAX_SERVER_DIGITS + (absV < 1 ? 0 : (absV < 10 ? 1 : (absV < 100 ? 2 : 3))); 248 259 return BigDecimal.valueOf(value).round(new MathContext(numOfDigits)).doubleValue(); 249 //return Math.round(value / MAX_SERVER_PRECISION) * MAX_SERVER_PRECISION; // Old method, causes rounding errors (see LatLonTest) ! 250 } 251 260 } 261 252 262 /** 253 263 * Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. to … … 260 270 roundToOsmPrecision(lat()), 261 271 roundToOsmPrecision(lon()) 272 ); 273 } 274 275 /** 276 * Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. to 277 * MAX_SERVER_PRECISION 278 * 279 * @return a clone of this lat LatLon 280 */ 281 public LatLon getRoundedToOsmPrecisionStrict() { 282 return new LatLon( 283 roundToOsmPrecisionStrict(lat()), 284 roundToOsmPrecisionStrict(lon()) 262 285 ); 263 286 }
Note:
See TracChangeset
for help on using the changeset viewer.