| | 1 | // License: GPL. For details, see LICENSE file. |
| | 2 | package org.openstreetmap.josm.data.osm.visitor; |
| | 3 | |
| | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | 5 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | 6 | |
| | 7 | import org.junit.jupiter.api.Test; |
| | 8 | import org.openstreetmap.josm.data.ProjectionBounds; |
| | 9 | import org.openstreetmap.josm.data.coor.LatLon; |
| | 10 | import org.openstreetmap.josm.data.osm.DataSet; |
| | 11 | import org.openstreetmap.josm.data.osm.Node; |
| | 12 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences; |
| | 13 | import org.openstreetmap.josm.testutils.annotations.Projection; |
| | 14 | |
| | 15 | /** |
| | 16 | * Unit tests for class {@link BoundingXYVisitor}. |
| | 17 | */ |
| | 18 | @BasicPreferences |
| | 19 | @Projection |
| | 20 | public class BoundingXYVisitorTest { |
| | 21 | |
| | 22 | /** |
| | 23 | * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/24982">#24982</a> |
| | 24 | */ |
| | 25 | @Test |
| | 26 | public void testTicket24982() { |
| | 27 | DataSet ds = new DataSet(); |
| | 28 | // two nodes with coordinates as in the example data |
| | 29 | Node n1 = new Node(new LatLon(53.1637636, 7.8315384)); |
| | 30 | Node n2 = new Node(new LatLon(53.1729062, 7.7530235)); |
| | 31 | ds.addPrimitive(n1); |
| | 32 | ds.addPrimitive(n2); |
| | 33 | |
| | 34 | BoundingXYVisitor v = new BoundingXYVisitor(); |
| | 35 | ds.setSelected(ds.getNodes()); |
| | 36 | assertEquals(2, ds.getSelectedNodes().size()); |
| | 37 | ds.getSelectedNodes().forEach(v::visit); |
| | 38 | ProjectionBounds boundsBeforeZoom = v.getBounds(); |
| | 39 | v.enlargeBoundingBoxLogarithmically(); |
| | 40 | ProjectionBounds boundsAfterZoom = v.getBounds(); |
| | 41 | // check that the new bounding box isn't smaller than the old one |
| | 42 | assertTrue(boundsAfterZoom.contains(boundsBeforeZoom.getMin())); |
| | 43 | assertTrue(boundsAfterZoom.contains(boundsBeforeZoom.getMax())); |
| | 44 | // check that the new bounding box contains both nodes |
| | 45 | assertTrue(boundsAfterZoom.contains(n1.getEastNorth())); |
| | 46 | assertTrue(boundsAfterZoom.contains(n2.getEastNorth())); |
| | 47 | } |
| | 48 | |
| | 49 | } |