GeoRectangle extends Primitive { @Nonnull public GeoRectangle grow(@Nonnull final GeoPoint point) { final double newSouthWestLat; final double newNorthEastLat; final double newSouthWestElevationMeters; final double newNorthEastElevationMeters; if (southWest.getLat() < point.getLat()) { newSouthWestLat = southWest.getLat(); newSouthWestElevationMeters = southWest.getElevationMetersOrNaN(); } else { newSouthWestLat = point.getLat(); newSouthWestElevationMeters = point.getElevationMetersOrNaN(); } if (northEast.getLat() > point.getLat()) { newNorthEastLat = northEast.getLat(); newNorthEastElevationMeters = northEast.getElevationMetersOrNaN(); } else { newNorthEastLat = point.getLat(); newNorthEastElevationMeters = point.getElevationMetersOrNaN(); } final double newSouthWestLon1; final double newNorthEastLon1; final double newSouthWestLon2; final double newNorthEastLon2; if (isWrapped()) { newSouthWestLon1 = Math.min(southWest.getLon(), point.getLon()); newNorthEastLon1 = Math.min(northEast.getLon(), point.getLon()); newSouthWestLon2 = Math.max(southWest.getLon(), point.getLon()); newNorthEastLon2 = Math.max(northEast.getLon(), point.getLon()); } else { newSouthWestLon1 = Math.min(southWest.getLon(), point.getLon()); newNorthEastLon1 = Math.max(northEast.getLon(), point.getLon()); newSouthWestLon2 = Math.max(southWest.getLon(), point.getLon()); newNorthEastLon2 = Math.min(northEast.getLon(), point.getLon()); } final GeoRectangle rect1 = new GeoRectangle( new GeoPoint(newSouthWestLat, newSouthWestLon1, newSouthWestElevationMeters), new GeoPoint(newNorthEastLat, newNorthEastLon1, newNorthEastElevationMeters)); final GeoRectangle rect2 = new GeoRectangle( new GeoPoint(newSouthWestLat, newSouthWestLon2, newSouthWestElevationMeters), new GeoPoint(newNorthEastLat, newNorthEastLon2, newNorthEastElevationMeters)); final GeoRectangle rect3 = new GeoRectangle( southWest.withLat(newSouthWestLat), northEast.withLat(newNorthEastLat)); final GeoRectangle smallest; if (rect1.getEasting() <= rect2.getEasting()) { if (rect1.getEasting() > getEasting()) { smallest = rect1; } else { smallest = rect3; } } else { if (rect2.getEasting() > getEasting()) { smallest = rect2; } else { smallest = rect3; } } return smallest; } GeoRectangle(
            @Nonnull final GeoPoint southWest,
            @Nonnull final GeoPoint northEast); @SuppressWarnings({"ConstantConditions", "UnusedDeclaration"}) @Deprecated private  GeoRectangle(); @Deprecated() @Nonnull static GeoRectangle getWorld(); @Nonnull @Override GeoRectangle boundingBox(); @Nonnull GeoPoint getSouthWest(); @Nonnull GeoPoint getNorthEast(); @Nonnull GeoRectangle withSouthWest(@Nonnull final GeoPoint southWest); @Nonnull GeoRectangle withNorthEast(@Nonnull final GeoPoint northEast); double getNorthing(); double getEasting(); @Override boolean overlaps(@Nonnull final GeoArea area); @Nonnull GeoRectangle expand(final double meters); @Override boolean contains(@Nonnull final GeoArea area); @Override boolean contains(@Nonnull final GeoPoint point); @Nonnull @Override GeoRectangle translate(@Nonnull final GeoVector vector); @Nonnull @Override GeoRectangle moveTo(@Nonnull final GeoPoint origin); @Override @Nonnull Collection<GeoRectangle> pixelate(); @Nonnull GeoRectangle grow(@Nonnull final GeoPoint point); @Nonnull GeoRectangle grow(@Nonnull final GeoRectangle other); boolean isWrapped(); @Override boolean canEqual(@Nonnull final Object obj); @Override boolean equals(@Nullable final Object obj); @Override int hashCode(); static final GeoRectangle WORLD; }
@Test public void testGrowRect() { LOG.info("testGrowRect"); final GeoRectangle a1 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(1.0, 1.0)); final GeoRectangle a2 = new GeoRectangle(new GeoPoint(1.0, 1.0), new GeoPoint(2.0, 2.0)); final GeoRectangle a3 = new GeoRectangle(new GeoPoint(1.0, 1.0), new GeoPoint(3.0, 3.0)); final GeoRectangle a4 = new GeoRectangle(new GeoPoint(-1.0, -1.0), new GeoPoint(4.0, 4.0)); final GeoRectangle a5 = new GeoRectangle(new GeoPoint(0.2, 0.3), new GeoPoint(0.4, 0.5)); final GeoRectangle a6 = new GeoRectangle(new GeoPoint(-1.0, 0.0), new GeoPoint(0.3, 0.5)); final GeoRectangle a7 = new GeoRectangle(new GeoPoint(0.5, 0.5), new GeoPoint(3.0, 4.0)); final GeoRectangle b1 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(2.0, 2.0)); final GeoRectangle b2 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(3.0, 3.0)); final GeoRectangle b3 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(1.0, 1.0)); final GeoRectangle b4 = new GeoRectangle(new GeoPoint(-1.0, 0.0), new GeoPoint(1.0, 1.0)); final GeoRectangle b5 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(3.0, 4.0)); Assert.assertEquals(b1, a1.grow(a2)); Assert.assertEquals(b2, a1.grow(a3)); Assert.assertEquals(a4, a1.grow(a4)); Assert.assertEquals(b3, a1.grow(a5)); Assert.assertEquals(b4, a1.grow(a6)); Assert.assertEquals(b5, a1.grow(a7)); }
@Test public void testGrowPoint() { LOG.info("testGrowPoint"); final GeoRectangle a1 = new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, 160.0)); final GeoRectangle a2 = new GeoRectangle(new GeoPoint(0.0, -160.0), new GeoPoint(2.0, -150.0)); final GeoRectangle a3 = new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)); final GeoPoint p1 = new GeoPoint(1.0, 170.0); final GeoPoint p2 = new GeoPoint(1.0, -170.0); final GeoPoint p3 = new GeoPoint(1.0, 150.0); final GeoPoint p4 = new GeoPoint(1.0, -150.0); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, 170.0)), a1.grow(p1)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, -170.0)), a1.grow(p2)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 170.0), new GeoPoint(2.0, -150.0)), a2.grow(p1)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, -170.0), new GeoPoint(2.0, -150.0)), a2.grow(p2)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)), a3.grow(p1)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)), a3.grow(p2)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, -160.0)), a3.grow(p3)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -150.0)), a3.grow(p4)); final GeoPoint p5 = new GeoPoint(1.0, 151.0); final GeoPoint p6 = new GeoPoint(-1.0, 151.0); final GeoPoint p7 = new GeoPoint(0.0, 149.0); final GeoPoint p8 = new GeoPoint(1.0, 161.0); final GeoPoint p9 = new GeoPoint(3.0, 159.0); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, 160.0)), a1.grow(p5)); Assert.assertEquals(new GeoRectangle(new GeoPoint(-1.0, 150.0), new GeoPoint(2.0, 160.0)), a1.grow(p6)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 149.0), new GeoPoint(2.0, 160.0)), a1.grow(p7)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(2.0, 161.0)), a1.grow(p8)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 150.0), new GeoPoint(3.0, 160.0)), a1.grow(p9)); final GeoPoint p10 = new GeoPoint(1.0, 161.0); final GeoPoint p11 = new GeoPoint(1.0, -161.0); final GeoPoint p12 = new GeoPoint(1.0, 159.0); final GeoPoint p13 = new GeoPoint(-1.0, 161.0); final GeoPoint p14 = new GeoPoint(1.0, -159.0); final GeoPoint p15 = new GeoPoint(3.0, -161.0); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)), a3.grow(p10)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)), a3.grow(p11)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 159.0), new GeoPoint(2.0, -160.0)), a3.grow(p12)); Assert.assertEquals(new GeoRectangle(new GeoPoint(-1.0, 160.0), new GeoPoint(2.0, -160.0)), a3.grow(p13)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -159.0)), a3.grow(p14)); Assert.assertEquals(new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(3.0, -160.0)), a3.grow(p15)); }