public static <T> Viewport intersect(final Iterable<T> source, final Function<T, Viewport> mapper) {
        if (source == null) {
            return null;
        }
        int maxLowerLon = Integer.MIN_VALUE;
        int maxLowerLat = Integer.MIN_VALUE;
        int minHigherLon = Integer.MAX_VALUE;
        int minHigherLat = Integer.MAX_VALUE;
        for (T src : source) {
            if (src == null) {
                return null;
            }
            final Viewport vp = mapper.apply(src);
            if (vp == null) {
                return null;
            }
            maxLowerLon = Math.max(maxLowerLon, vp.bottomLeft.getLongitudeE6());
            maxLowerLat = Math.max(maxLowerLat, vp.bottomLeft.getLatitudeE6());
            minHigherLon = Math.min(minHigherLon, vp.topRight.getLongitudeE6());
            minHigherLat = Math.min(minHigherLat, vp.topRight.getLatitudeE6());
        }
        if (maxLowerLon == Integer.MIN_VALUE) {
            return null;
        }
        // There might not be any overlap at all
        if (minHigherLon <= maxLowerLon || minHigherLat <= maxLowerLat) {
            return null;
        }

        return new Viewport(maxLowerLat, maxLowerLon, minHigherLat, minHigherLon, null);
    }
internal worker function for
- containing(Points)
- containingGCLiveCaches(Geocaches)
- containingCachesAndWaypoints(Geocaches)
main/src/main/java/cgeo/geocaching/location/Viewport.java