Changeset 12818 in josm for trunk/src/org/openstreetmap


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
Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

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

    r12374 r12818  
    570570     * @param visitor A function to call for the points on the edge.
    571571     * @since 10806
    572      */
     572     * @deprecated use {@link Projection#visitOutline(Bounds, Consumer)}
     573     */
     574    @Deprecated
    573575    public void visitEdge(Projection projection, Consumer<LatLon> visitor) {
    574576        double width = getWidth();
  • trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java

    r11774 r12818  
    7575        this.maxEast = maxEast;
    7676        this.maxNorth = maxNorth;
     77    }
     78
     79    /**
     80     * Construct uninitialized bounds.
     81     * <p>
     82     * At least one call to {@link #extend(EastNorth)} or {@link #extend(ProjectionBounds)}
     83     * is required immediately after construction to initialize the {@code ProjectionBounds}
     84     * instance and make it valid.
     85     * <p>
     86     * Uninitialized {@code ProjectionBounds} must not be passed to other methods
     87     * or used in any way other than initializing it.
     88     */
     89    public ProjectionBounds() {
     90        this.minEast = Double.POSITIVE_INFINITY;
     91        this.minNorth = Double.POSITIVE_INFINITY;
     92        this.maxEast = Double.NEGATIVE_INFINITY;
     93        this.maxNorth = Double.NEGATIVE_INFINITY;
    7794    }
    7895
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r12809 r12818  
    5656    public void visit(Bounds b) {
    5757        if (b != null) {
    58             b.visitEdge(Main.getProjection(), this::visit);
     58            Main.getProjection().visitOutline(b, this::visit);
    5959        }
    6060    }
  • 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}
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r12216 r12818  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection;
     3
     4import java.util.function.Consumer;
    35
    46import org.openstreetmap.josm.data.Bounds;
     
    121123     */
    122124    boolean switchXY();
     125
     126    /**
     127     * Visit points along the edge of this bounds instance.
     128     * <p>
     129     * Depending on the shape in east/north space, it may simply visit the 4 corners
     130     * or (more generally) several points along the curved edges.
     131     * @param bounds the lat/lon rectangle to trace
     132     * @param visitor a function to call for the points on the edge.
     133     * @since 12818
     134     */
     135    void visitOutline(Bounds bounds, Consumer<EastNorth> visitor);
    123136}
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r12725 r12818  
    302302    public Area getArea(Bounds bounds) {
    303303        Path2D area = new Path2D.Double();
    304         bounds.visitEdge(getProjection(), latlon -> {
    305             MapViewPoint point = getPointFor(latlon);
     304        getProjection().visitOutline(bounds, en -> {
     305            MapViewPoint point = getPointFor(en);
    306306            if (area.getCurrentPoint() == null) {
    307307                area.moveTo(point.getInViewX(), point.getInViewY());
Note: See TracChangeset for help on using the changeset viewer.