Changeset 12161 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2017-05-15T15:43:30+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r11747 r12161 10 10 import java.util.function.Consumer; 11 11 12 import org.openstreetmap.josm.data.coor.ILatLon; 12 13 import org.openstreetmap.josm.data.coor.LatLon; 13 14 import org.openstreetmap.josm.data.osm.BBox; … … 18 19 * This is a simple data class for "rectangular" areas of the world, given in 19 20 * lat/lon min/max values. The values are rounded to LatLon.OSM_SERVER_PRECISION 21 * 22 * @see BBox to represent invalid areas. 20 23 * 21 24 * @author imi … … 390 393 /** 391 394 * Determines if the given point {@code ll} is within these bounds. 395 * <p> 396 * Points with unknown coordinates are always outside the coordinates. 392 397 * @param ll The lat/lon to check 393 398 * @return {@code true} if {@code ll} is within these bounds, {@code false} otherwise 394 399 */ 395 400 public boolean contains(LatLon ll) { 401 // binary compatibility 402 return contains((ILatLon) ll); 403 } 404 405 /** 406 * Determines if the given point {@code ll} is within these bounds. 407 * <p> 408 * Points with unknown coordinates are always outside the coordinates. 409 * @param ll The lat/lon to check 410 * @return {@code true} if {@code ll} is within these bounds, {@code false} otherwise 411 * @since xxx 412 */ 413 public boolean contains(ILatLon ll) { 414 if (!ll.isLatLonKnown()) { 415 return false; 416 } 396 417 if (ll.lat() < minLat || ll.lat() > maxLat) 397 418 return false; -
trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java
r10334 r12161 5 5 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.projection.Projecting; 7 8 import org.openstreetmap.josm.data.projection.Projection; 8 9 … … 20 21 21 22 private EastNorth eastNorth; 22 private transient Projection proj;23 private transient Object cacheKey; 23 24 24 25 /** … … 37 38 public CachedLatLon(LatLon coor) { 38 39 super(coor.lat(), coor.lon()); 39 proj= null;40 cacheKey = null; 40 41 } 41 42 … … 45 46 */ 46 47 public CachedLatLon(EastNorth eastNorth) { 47 super(Main.getProjection().eastNorth2latlon(eastNorth)); 48 proj = Main.getProjection(); 48 this(eastNorth, Main.getProjection()); 49 } 50 51 private CachedLatLon(EastNorth eastNorth, Projection projection) { 52 super(projection.eastNorth2latlon(eastNorth)); 53 cacheKey = projection.getCacheKey(); 49 54 this.eastNorth = eastNorth; 50 55 } … … 55 60 * @return the internally cached east/north coordinates. null, if the globally defined projection is null 56 61 */ 57 public final EastNorth getEastNorth() { 58 if (!Objects.equals(proj, Main.getProjection())) { 59 proj = Main.getProjection(); 60 eastNorth = proj.latlon2eastNorth(this); 62 @Override 63 public final EastNorth getEastNorth(Projecting projecting) { 64 if (!Objects.equals(cacheKey, projecting.getCacheKey())) { 65 cacheKey = projecting.getCacheKey(); 66 eastNorth = projecting.latlon2eastNorth(this); 61 67 } 62 68 return eastNorth; -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r12131 r12161 43 43 * @author Imi 44 44 */ 45 public class LatLon extends Coordinate {45 public class LatLon extends Coordinate implements ILatLon { 46 46 47 47 private static final long serialVersionUID = 1L; … … 251 251 } 252 252 253 protected LatLon(LatLon coor) { 253 /** 254 * Creates a new LatLon object for the given coordinate 255 * @param coor The coordinates to copy from. 256 */ 257 public LatLon(ILatLon coor) { 254 258 super(coor.lon(), coor.lat()); 255 259 } … … 263 267 } 264 268 265 /** 266 * Returns the latitude, i.e., the north-south position in degrees. 267 * @return the latitude 268 */ 269 @Override 269 270 public double lat() { 270 271 return y; … … 286 287 } 287 288 288 /** 289 * Returns the longitude, i.e., the east-west position in degrees. 290 * @return the longitude 291 */ 289 @Override 292 290 public double lon() { 293 291 return x; -
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r11452 r12161 7 7 8 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.data.coor.ILatLon; 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 import org.openstreetmap.josm.data.coor.QuadTiling; … … 85 86 */ 86 87 public BBox(Way w) { 87 w.getNodes().forEach( n -> add(n.getCoor()));88 w.getNodes().forEach(this::add); 88 89 } 89 90 … … 93 94 */ 94 95 public BBox(Node n) { 95 if (n.isLatLonKnown()) { 96 add(n.getCoor()); 97 } 96 this((ILatLon) n); 97 } 98 99 /** 100 * Create BBox for a given latlon. An invalid BBox is returned if the coordinates are not known. 101 * @param ll The lat lon position 102 */ 103 public BBox(ILatLon ll) { 104 add(ll); 105 } 106 107 /** 108 * Add a point to an existing BBox. Extends this bbox if necessary so that this.bounds(c) will return true 109 * if c is a valid LatLon instance. 110 * Kept for binary compatibility 111 * @param c a LatLon point 112 */ 113 public final void add(LatLon c) { 114 add((ILatLon) c); 98 115 } 99 116 … … 103 120 * @param c a LatLon point 104 121 */ 105 public final void add(LatLon c) { 106 if (c != null && c.isValid()) { 107 add(c.lon(), c.lat()); 108 } 122 public final void add(ILatLon c) { 123 add(c.lon(), c.lat()); 109 124 } 110 125 -
trunk/src/org/openstreetmap/josm/data/osm/INode.java
r9460 r12161 3 3 4 4 import org.openstreetmap.josm.data.coor.EastNorth; 5 import org.openstreetmap.josm.data.coor.ILatLon; 5 6 import org.openstreetmap.josm.data.coor.LatLon; 6 7 … … 9 10 * @since 4098 10 11 */ 11 public interface INode extends IPrimitive {12 public interface INode extends IPrimitive, ILatLon { 12 13 13 14 /** … … 24 25 25 26 /** 26 * Returns east/north coordinates of this node.27 * @return east/north coordinates of this node28 */29 EastNorth getEastNorth();30 31 /**32 27 * Sets east/north coordinates of this node. 33 28 * @param eastNorth east/north coordinates of this node -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r12031 r12161 15 15 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 16 16 import org.openstreetmap.josm.data.osm.visitor.Visitor; 17 import org.openstreetmap.josm.data.projection.Projecti on;17 import org.openstreetmap.josm.data.projection.Projecting; 18 18 import org.openstreetmap.josm.data.projection.Projections; 19 19 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 48 48 * @since 7828 49 49 */ 50 @Override 50 51 public boolean isLatLonKnown() { 52 // We cannot use default implementation - if we remove this implementation, we will break binary compatibility. 51 53 return !Double.isNaN(lat) && !Double.isNaN(lon); 52 54 } … … 81 83 @Override 82 84 public LatLon getCoor() { 83 if (!isLatLonKnown()) return null; 84 return new LatLon(lat, lon); 85 } 86 87 /** 88 * <p>Replies the projected east/north coordinates.</p> 89 * 90 * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. 91 * Internally caches the projected coordinates.</p> 92 * 93 * <p>Replies {@code null} if this node doesn't know lat/lon-coordinates, i.e. because it is an incomplete node. 94 * 95 * @return the east north coordinates or {@code null} 96 * @see #invalidateEastNorthCache() 97 * 98 */ 99 @Override 100 public EastNorth getEastNorth() { 101 return getEastNorth(Main.getProjection()); 102 } 103 104 /** 105 * Replies the projected east/north coordinates. 106 * <p> 107 * The result of the last conversion is cached. The cache object is used as cache key. 108 * @param projection The projection to use. 109 * @return The projected east/north coordinates 110 * @since 10827 111 */ 112 public EastNorth getEastNorth(Projection projection) { 85 if (!isLatLonKnown()) { 86 return null; 87 } else { 88 return new LatLon(lat, lon); 89 } 90 } 91 92 @Override 93 public double lat() { 94 return lat; 95 } 96 97 @Override 98 public double lon() { 99 return lon; 100 } 101 102 @Override 103 public EastNorth getEastNorth(Projecting projection) { 113 104 if (!isLatLonKnown()) return null; 114 105 -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r12017 r12161 41 41 } 42 42 43 private boolean isLatLonKnown() { 43 @Override 44 public double lat() { 45 return lat; 46 } 47 48 @Override 49 public double lon() { 50 return lon; 51 } 52 53 @Override 54 public boolean isLatLonKnown() { 44 55 return !Double.isNaN(lat) && !Double.isNaN(lon); 45 56 } -
trunk/src/org/openstreetmap/josm/data/osm/NodePositionComparator.java
r9880 r12161 20 20 return 0; 21 21 22 int dLat = Double.compare(n1. getCoor().lat(), n2.getCoor().lat());23 return dLat != 0 ? dLat : Double.compare(n1. getCoor().lon(), n2.getCoor().lon());22 int dLat = Double.compare(n1.lat(), n2.lat()); 23 return dLat != 0 ? dLat : Double.compare(n1.lon(), n2.lon()); 24 24 } 25 25 } -
trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
r12149 r12161 10 10 import org.openstreetmap.josm.data.ProjectionBounds; 11 11 import org.openstreetmap.josm.data.coor.EastNorth; 12 import org.openstreetmap.josm.data.coor.ILatLon; 12 13 import org.openstreetmap.josm.data.coor.LatLon; 13 14 import org.openstreetmap.josm.data.projection.datum.Datum; … … 114 115 115 116 @Override 116 public EastNorth latlon2eastNorth(LatLon ll) { 117 ll = datum.fromWGS84(ll); 117 public EastNorth latlon2eastNorth(ILatLon toConvert) { 118 // TODO: Use ILatLon in datum, so we don't need to wrap it here. 119 LatLon ll = datum.fromWGS84(new LatLon(toConvert)); 118 120 double[] en = proj.project(Utils.toRadians(ll.lat()), Utils.toRadians(LatLon.normalizeLon(ll.lon() - lon0 - pm))); 119 121 return new EastNorth((ellps.a * k0 * en[0] + x0) / toMeter, (ellps.a * k0 * en[1] + y0) / toMeter); … … 122 124 @Override 123 125 public LatLon eastNorth2latlon(EastNorth en) { 126 // We know it is a latlon. Nice would be to change this method return type to ILatLon 124 127 return eastNorth2latlon(en, LatLon::normalizeLon); 125 128 } … … 127 130 @Override 128 131 public LatLon eastNorth2latlonClamped(EastNorth en) { 129 LatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180));132 ILatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180)); 130 133 Bounds bounds = getWorldBoundsLatLon(); 131 134 return new LatLon(Utils.clamp(ll.lat(), bounds.getMinLat(), bounds.getMaxLat()), -
trunk/src/org/openstreetmap/josm/data/projection/Ellipsoid.java
r12013 r12161 7 7 package org.openstreetmap.josm.data.projection; 8 8 9 import org.openstreetmap.josm.data.coor.ILatLon; 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 import org.openstreetmap.josm.tools.Utils; -
trunk/src/org/openstreetmap/josm/data/projection/Projecting.java
r10805 r12161 6 6 import org.openstreetmap.josm.data.ProjectionBounds; 7 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.ILatLon; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 … … 19 20 /** 20 21 * Convert from lat/lon to easting/northing. 22 * <p> 23 * This method exists to not break binary compatibility with old plugins 21 24 * 22 25 * @param ll the geographical point to convert (in WGS84 lat/lon) 23 26 * @return the corresponding east/north coordinates 24 27 */ 25 EastNorth latlon2eastNorth(LatLon ll); 28 default EastNorth latlon2eastNorth(LatLon ll) { 29 return latlon2eastNorth((ILatLon) ll); 30 } 31 32 /** 33 * Convert from lat/lon to easting/northing. This method uses the newer {@link ILatLon} interface. 34 * 35 * @param ll the geographical point to convert (in WGS84 lat/lon) 36 * @return the corresponding east/north coordinates 37 * @since xxx 38 */ 39 EastNorth latlon2eastNorth(ILatLon ll); 26 40 27 41 /** … … 48 62 */ 49 63 Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area); 64 65 /** 66 * Gets the object used as cache identifier when caching results of this projection. 67 * @return The object to use as cache key 68 * @since 10827 69 */ 70 default Object getCacheKey() { 71 return this; 72 } 50 73 } -
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r11858 r12161 119 119 */ 120 120 boolean switchXY(); 121 122 /**123 * Gets the object used as cache identifier when caching results of this projection.124 * @return The object to use as cache key125 * @since 10827126 */127 default Object getCacheKey() {128 return this;129 }130 121 } -
trunk/src/org/openstreetmap/josm/data/projection/ShiftedProjecting.java
r10836 r12161 7 7 import org.openstreetmap.josm.data.ProjectionBounds; 8 8 import org.openstreetmap.josm.data.coor.EastNorth; 9 import org.openstreetmap.josm.data.coor.ILatLon; 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 … … 29 30 30 31 @Override 31 public EastNorth latlon2eastNorth( LatLon ll) {32 public EastNorth latlon2eastNorth(ILatLon ll) { 32 33 return base.latlon2eastNorth(ll).add(offset); 33 34 } -
trunk/src/org/openstreetmap/josm/data/validation/PaintVisitor.java
r12131 r12161 3 3 4 4 import java.awt.Color; 5 import java.awt.Graphics ;5 import java.awt.Graphics2D; 6 6 import java.awt.Point; 7 7 import java.util.HashSet; … … 18 18 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 19 19 import org.openstreetmap.josm.gui.MapView; 20 import org.openstreetmap.josm.gui.draw.MapViewPath; 21 import org.openstreetmap.josm.gui.draw.SymbolShape; 20 22 import org.openstreetmap.josm.tools.Utils; 21 23 … … 27 29 public class PaintVisitor extends AbstractVisitor implements ValidatorVisitor { 28 30 /** The graphics */ 29 private final Graphics g;31 private final Graphics2D g; 30 32 /** The MapView */ 31 33 private final MapView mv; … … 44 46 * @param mv The Mapview 45 47 */ 46 public PaintVisitor(Graphics g, MapView mv) {48 public PaintVisitor(Graphics2D g, MapView mv) { 47 49 this.g = g; 48 50 this.mv = mv; … … 121 123 122 124 if (!paintedPoints.contains(pp)) { 123 Point p = mv.getPoint(n);125 MapViewPath circle = new MapViewPath(mv.getState()).shapeAround(n, SymbolShape.CIRCLE, 10); 124 126 125 127 if (selected) { 126 128 g.setColor(getHighlightColor(color)); 127 g.fill Oval(p.x - 5, p.y - 5, 10, 10);129 g.fill(circle); 128 130 } 129 131 g.setColor(color); 130 g.draw Oval(p.x - 5, p.y - 5, 10, 10);132 g.draw(circle); 131 133 paintedPoints.add(pp); 132 134 }
Note:
See TracChangeset
for help on using the changeset viewer.