GeoRectangle extends Primitive { @Override public boolean contains(@Nonnull final GeoArea area) { final GeoRectangle other = area.boundingBox(); final boolean contain; if (isWrapped()) { final GeoRectangle t1 = new GeoRectangle( new GeoPoint(southWest.getLat(), -180.0), new GeoPoint(northEast.getLat(), northEast.getLon()) ); final GeoRectangle t2 = new GeoRectangle( new GeoPoint(southWest.getLat(), southWest.getLon()), new GeoPoint(northEast.getLat(), Geo.LON180) ); if (other.isWrapped()) { final GeoRectangle o1 = new GeoRectangle( new GeoPoint(other.southWest.getLat(), -180.0), new GeoPoint(other.northEast.getLat(), other.northEast.getLon()) ); final GeoRectangle o2 = new GeoRectangle( new GeoPoint(other.southWest.getLat(), other.southWest.getLon()), new GeoPoint(other.northEast.getLat(), Geo.LON180) ); contain = t1.contains(o1) && t2.contains(o2); } else { contain = t1.contains(other) || t2.contains(other); } } else { if (other.isWrapped()) { final GeoRectangle o1 = new GeoRectangle( new GeoPoint(other.southWest.getLat(), -180.0), new GeoPoint(other.northEast.getLat(), northEast.getLon()) ); final GeoRectangle o2 = new GeoRectangle( new GeoPoint(other.southWest.getLat(), other.southWest.getLon()), new GeoPoint(other.northEast.getLat(), Geo.LON180) ); contain = contains(o1) && contains(o2); } else { contain = (southWest.getLat() <= other.southWest.getLat()) && (northEast.getLat() >= other.northEast.getLat()) && (southWest.getLon() <= other.southWest.getLon()) && (northEast.getLon() >= other.northEast.getLon()); } } return contain; } 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 testContains() { LOG.info("testContains"); final GeoRectangle a1 = new GeoRectangle(new GeoPoint(1.0, 1.0), new GeoPoint(1.0, 1.0)); final GeoRectangle a2 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(2.0, 2.0)); final GeoRectangle a3 = new GeoRectangle(new GeoPoint(0.0, 0.0), new GeoPoint(0.5, 0.5)); final GeoRectangle a4 = new GeoRectangle(new GeoPoint(1.0, 1.0), new GeoPoint(1.5, 1.5)); final GeoRectangle a5 = new GeoRectangle(new GeoPoint(1.0, 1.0), new GeoPoint(2.5, 2.5)); Assert.assertFalse(a1.contains(new GeoPoint(1.0, 0.0))); Assert.assertFalse(a1.contains(new GeoPoint(0.0, 1.0))); Assert.assertTrue(a1.contains(new GeoPoint(1.0, 1.0))); Assert.assertTrue(a1.contains(a1)); Assert.assertTrue(a2.contains(a1)); Assert.assertTrue(a2.contains(a3)); Assert.assertFalse(a3.contains(a2)); Assert.assertFalse(a3.contains(a4)); Assert.assertFalse(a3.contains(a4)); Assert.assertTrue(a5.contains(a4)); final GeoRectangle b1 = new GeoRectangle(new GeoPoint(0.0, 160.0), new GeoPoint(2.0, -160.0)); final GeoRectangle b2 = new GeoRectangle(new GeoPoint(0.0, 161.0), new GeoPoint(2.0, -160.0)); final GeoRectangle b3 = new GeoRectangle(new GeoPoint(0.0, 161.0), new GeoPoint(2.0, 162.0)); final GeoRectangle b4 = new GeoRectangle(new GeoPoint(0.0, 159.0), new GeoPoint(2.0, -159.0)); final GeoRectangle b5 = new GeoRectangle(new GeoPoint(0.0, -159.0), new GeoPoint(2.0, 159.0)); final GeoRectangle b6 = new GeoRectangle(new GeoPoint(0.0, -161.0), new GeoPoint(2.0, -159.0)); Assert.assertTrue(b1.contains(b2)); Assert.assertTrue(b1.contains(b3)); Assert.assertFalse(b1.contains(b4)); Assert.assertFalse(b1.contains(b5)); Assert.assertFalse(b1.contains(b6)); Assert.assertFalse(a5.contains(b1)); }