Ignore:
Timestamp:
2017-09-10T14:49:56+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - move Bounds#visitEdge to Projection#visitOutline

  • joins 2 implementations of the same algorithm
  • removes dependency of Bounds on Projection
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java

    r12161 r12818  
    55import java.util.HashMap;
    66import java.util.Map;
     7import java.util.function.Consumer;
    78import java.util.function.DoubleUnaryOperator;
    89
     
    204205                result = projectionBoundsBox;
    205206                if (result == null) {
    206                     Bounds b = getWorldBoundsLatLon();
    207                     // add 4 corners
    208                     result = new ProjectionBounds(latlon2eastNorth(b.getMin()));
    209                     result.extend(latlon2eastNorth(b.getMax()));
    210                     result.extend(latlon2eastNorth(new LatLon(b.getMinLat(), b.getMaxLon())));
    211                     result.extend(latlon2eastNorth(new LatLon(b.getMaxLat(), b.getMinLon())));
    212                     // and trace along the outline
    213                     double dLon = (b.getMaxLon() - b.getMinLon()) / 1000;
    214                     double dLat = (b.getMaxLat() - b.getMinLat()) / 1000;
    215                     for (double lon = b.getMinLon(); lon < b.getMaxLon(); lon += dLon) {
    216                         result.extend(latlon2eastNorth(new LatLon(b.getMinLat(), lon)));
    217                         result.extend(latlon2eastNorth(new LatLon(b.getMaxLat(), lon)));
    218                     }
    219                     for (double lat = b.getMinLat(); lat < b.getMaxLat(); lat += dLat) {
    220                         result.extend(latlon2eastNorth(new LatLon(lat, b.getMinLon())));
    221                         result.extend(latlon2eastNorth(new LatLon(lat, b.getMaxLon())));
    222                     }
    223                     projectionBoundsBox = result;
     207                    ProjectionBounds bds = new ProjectionBounds();
     208                    visitOutline(getWorldBoundsLatLon(), bds::extend);
     209                    projectionBoundsBox = bds;
    224210                }
    225211            }
     
    232218        return this;
    233219    }
     220
     221    @Override
     222    public void visitOutline(Bounds b, Consumer<EastNorth> visitor) {
     223        visitOutline(b, 100, visitor);
     224    }
     225
     226    private void visitOutline(Bounds b, int nPoints, Consumer<EastNorth> visitor) {
     227        double minlon = b.getMinLon();
     228        if (b.crosses180thMeridian()) {
     229            minlon -= 360.0;
     230        }
     231        double spanLon = b.getMaxLon() - minlon;
     232        double spanLat = b.getMaxLat() - b.getMinLat();
     233
     234        //TODO: Use projection to see if there is any need for doing this along each axis.
     235        for (int step = 0; step < nPoints; step++) {
     236            visitor.accept(latlon2eastNorth(
     237                    new LatLon(b.getMinLat(), minlon + spanLon * step / nPoints)));
     238        }
     239        for (int step = 0; step < nPoints; step++) {
     240            visitor.accept(latlon2eastNorth(
     241                    new LatLon(b.getMinLat() + spanLat * step / nPoints, b.getMaxLon())));
     242        }
     243        for (int step = 0; step < nPoints; step++) {
     244            visitor.accept(latlon2eastNorth(
     245                    new LatLon(b.getMaxLat(), b.getMaxLon() - spanLon * step / nPoints)));
     246        }
     247        for (int step = 0; step < nPoints; step++) {
     248            visitor.accept(latlon2eastNorth(
     249                    new LatLon(b.getMaxLat() - spanLat * step / nPoints, minlon)));
     250        }
     251    }
    234252}
Note: See TracChangeset for help on using the changeset viewer.