GeoRectangle extends Primitive { @Override public boolean overlaps(@Nonnull final GeoArea area) { final GeoRectangle other = area.boundingBox(); final boolean overlap; 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) ); overlap = t1.overlaps(o1) || t2.overlaps(o2); } else { overlap = t1.overlaps(other) || t2.overlaps(other); } } else { 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) ); overlap = overlaps(o1) || overlaps(o2); } else { overlap = !((southWest.getLat() > other.northEast.getLat()) || (northEast.getLat() < other.southWest.getLat()) || (southWest.getLon() > other.northEast.getLon()) || (northEast.getLon() < other.southWest.getLon())); } } return overlap; } 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 testOverlaps() { LOG.info("testOverlaps"); 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.assertTrue(a1.overlaps(a1)); Assert.assertTrue(a1.overlaps(a2)); Assert.assertFalse(a1.overlaps(a3)); Assert.assertTrue(a4.overlaps(a2)); Assert.assertTrue(a5.overlaps(a2)); 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.overlaps(b2)); Assert.assertTrue(b1.overlaps(b3)); Assert.assertTrue(b1.overlaps(b4)); Assert.assertFalse(b1.overlaps(b5)); Assert.assertTrue(b1.overlaps(b6)); Assert.assertFalse(a5.overlaps(b1)); }