diff --git a/src/org/openstreetmap/josm/data/imagery/Shape.java b/src/org/openstreetmap/josm/data/imagery/Shape.java
index 9e7fa16076..c55d371d61 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.data.imagery; |
| 3 | 3 | |
| | 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
| | 5 | |
| 4 | 6 | import java.awt.Polygon; |
| 5 | 7 | import java.text.MessageFormat; |
| 6 | 8 | import java.util.AbstractList; |
| … |
… |
import org.openstreetmap.gui.jmapviewer.Coordinate;
|
| 13 | 15 | import org.openstreetmap.josm.data.coor.LatLon; |
| 14 | 16 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
| 15 | 17 | |
| 16 | | import static org.openstreetmap.josm.tools.I18n.tr; |
| 17 | | |
| 18 | 18 | /** |
| 19 | 19 | * Data class to store the outline for background imagery coverage. |
| 20 | 20 | * |
| … |
… |
public class Shape {
|
| 85 | 85 | }; |
| 86 | 86 | } |
| 87 | 87 | |
| | 88 | /** |
| | 89 | * Check if the coordinates are inside this shape. |
| | 90 | * @see Polygon#contains(int, int) |
| | 91 | * @param latlon The latlon to look for |
| | 92 | * @return {@code true} if the LatLon is inside the shape. |
| | 93 | */ |
| 88 | 94 | public boolean contains(LatLon latlon) { |
| 89 | 95 | return coords.contains( |
| 90 | 96 | latlon.getX() * LatLon.MAX_SERVER_INV_PRECISION, |
| … |
… |
public class Shape {
|
| 114 | 120 | } |
| 115 | 121 | |
| 116 | 122 | coords.addPoint( |
| 117 | | (int) (lon * LatLon.MAX_SERVER_INV_PRECISION), |
| 118 | | (int) (lat * LatLon.MAX_SERVER_INV_PRECISION)); |
| | 123 | (int) Math.round((lon * LatLon.MAX_SERVER_INV_PRECISION)), |
| | 124 | (int) Math.round((lat * LatLon.MAX_SERVER_INV_PRECISION))); |
| 119 | 125 | } |
| 120 | 126 | |
| 121 | 127 | @Override |
diff --git a/test/unit/org/openstreetmap/josm/data/imagery/ShapeTest.java b/test/unit/org/openstreetmap/josm/data/imagery/ShapeTest.java
index 4887ff3085..6ac3e4901b 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.data.imagery; |
| 3 | 3 | |
| | 4 | import static org.junit.jupiter.api.Assertions.assertAll; |
| 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | 6 | |
| 6 | 7 | import java.util.Arrays; |
| 7 | 8 | |
| 8 | 9 | import org.junit.jupiter.api.Test; |
| | 10 | import org.junit.jupiter.params.ParameterizedTest; |
| | 11 | import org.junit.jupiter.params.provider.ValueSource; |
| 9 | 12 | |
| 10 | 13 | /** |
| 11 | 14 | * Unit tests for class {@link Shape}. |
| … |
… |
class ShapeTest {
|
| 28 | 31 | assertEquals("47.1//11.1//47.2//11.2//47.3//11.3", shape.encodeAsString("//")); |
| 29 | 32 | assertEquals("47.1,11.1,47.2,11.2,47.3,11.3;47.1,11.1,47.2,11.2,47.3,11.3", Shape.encodeAsString(Arrays.asList(shape, shape))); |
| 30 | 33 | } |
| | 34 | |
| | 35 | /** |
| | 36 | * Check double edge cases |
| | 37 | * @param coordinate the coordinate to check |
| | 38 | */ |
| | 39 | @ParameterizedTest |
| | 40 | @ValueSource(doubles = { |
| | 41 | // The double representation of 0.2575799 * 1e7 is 2575798.9999999995. Directly casting to int will round down. |
| | 42 | 0.2575799, |
| | 43 | // Check that 2575798.0000000005 is rounded down |
| | 44 | 0.2575798 |
| | 45 | }) |
| | 46 | void testDoubleEdgeCases(final double coordinate) { |
| | 47 | final Shape shape = new Shape(); |
| | 48 | shape.addPoint(Double.toString(1), Double.toString(coordinate)); |
| | 49 | shape.addPoint(Double.toString(coordinate), Double.toString(1)); |
| | 50 | shape.addPoint(Double.toString(coordinate), Double.toString(coordinate)); |
| | 51 | assertAll("Coordinates are not properly rounded on entry", |
| | 52 | () -> assertEquals(coordinate, shape.getPoints().get(0).getLon()), |
| | 53 | () -> assertEquals(coordinate, shape.getPoints().get(1).getLat())); |
| | 54 | } |
| 31 | 55 | } |