### Eclipse Workspace Patch 1.0
#P JOSM
|
|
|
|
| 10 | 10 | import static java.lang.Math.toRadians; |
| 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; |
| 17 | 15 | import java.util.Locale; |
| … |
… |
|
| 34 | 32 | * The API returns 7 decimals. |
| 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 | |
| 39 | 38 | private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00"); |
| … |
… |
|
| 264 | 263 | * @return rounded value |
| 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) |
| | 266 | return Math.round(value * MAX_SERVER_INV_PRECISION) / MAX_SERVER_INV_PRECISION; |
| 268 | 267 | } |
| 269 | 268 | |
| 270 | 269 | /** |
| 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. |
| | 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 | |
| 283 | 279 | /** |