Ticket #18730: 18730.patch

File 18730.patch, 1.7 KB (added by taylor.smock, 4 years ago)

Add addLatLon method to BBox

  • src/org/openstreetmap/josm/data/osm/BBox.java

     
    178178    }
    179179
    180180    /**
     181     * Extends this bbox to include the bbox of the primitive extended by extraSpace.
     182     * @param latLon a LatLon
     183     * @param extraSpace the value to extend the primitives bbox. Unit is in LatLon degrees.
     184     * @since xxx
     185     */
     186    public void addLatLon(LatLon latLon, double extraSpace) {
     187        Objects.requireNonNull(latLon, "LatLon cannot be null");
     188        add(latLon);
     189        add(latLon.getX() - extraSpace, latLon.getY() - extraSpace);
     190        add(latLon.getX() + extraSpace, latLon.getY() + extraSpace);
     191    }
     192
     193    /**
    181194     * Gets the height of the bbox.
    182195     * @return The difference between ymax and ymin. 0 for invalid bboxes.
    183196     */
  • test/unit/org/openstreetmap/josm/data/osm/BBoxTest.java

     
    126126    }
    127127
    128128    /**
     129     * Unit test of {@link BBox#addLatLon} method.
     130     */
     131    @Test
     132    public void testAddLatLonBuffer() {
     133        BBox b = new BBox();
     134        b.addLatLon(LatLon.NORTH_POLE, 0.5);
     135        assertEquals(LatLon.NORTH_POLE, b.getCenter());
     136        assertEquals(new LatLon(90.5, -0.5), b.getTopLeft());
     137        assertEquals(new LatLon(89.5, +0.5), b.getBottomRight());
     138    }
     139
     140    /**
    129141     * Unit test of {@link BBox#add(double, double)} method.
    130142     */
    131143    @Test