Changeset 12818 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-09-10T14:49:56+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r12374 r12818 570 570 * @param visitor A function to call for the points on the edge. 571 571 * @since 10806 572 */ 572 * @deprecated use {@link Projection#visitOutline(Bounds, Consumer)} 573 */ 574 @Deprecated 573 575 public void visitEdge(Projection projection, Consumer<LatLon> visitor) { 574 576 double width = getWidth(); -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r11774 r12818 75 75 this.maxEast = maxEast; 76 76 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; 77 94 } 78 95 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r12809 r12818 56 56 public void visit(Bounds b) { 57 57 if (b != null) { 58 b.visitEdge(Main.getProjection(), this::visit);58 Main.getProjection().visitOutline(b, this::visit); 59 59 } 60 60 } -
trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
r12161 r12818 5 5 import java.util.HashMap; 6 6 import java.util.Map; 7 import java.util.function.Consumer; 7 8 import java.util.function.DoubleUnaryOperator; 8 9 … … 204 205 result = projectionBoundsBox; 205 206 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; 224 210 } 225 211 } … … 232 218 return this; 233 219 } 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 } 234 252 } -
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r12216 r12818 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection; 3 4 import java.util.function.Consumer; 3 5 4 6 import org.openstreetmap.josm.data.Bounds; … … 121 123 */ 122 124 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); 123 136 } -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r12725 r12818 302 302 public Area getArea(Bounds bounds) { 303 303 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); 306 306 if (area.getCurrentPoint() == null) { 307 307 area.moveTo(point.getInViewX(), point.getInViewY());
Note:
See TracChangeset
for help on using the changeset viewer.