Ticket #9002: nodes.diff
| File nodes.diff, 6.4 KB (added by , 13 years ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/Node.java
16 16 public final class Node extends OsmPrimitive implements INode { 17 17 18 18 /* 19 * We "inline" lat/lon rather than using a LatLon-object => reduces memory footprint19 * the coordinates 20 20 */ 21 private double lat = Double.NaN; 22 private double lon = Double.NaN; 21 private LatLon latLon; 23 22 24 23 /* 25 24 * the cached projected coordinates 26 25 */ 27 private double east = Double.NaN; 28 private double north = Double.NaN; 26 private EastNorth eastNorth; 29 27 30 28 private boolean isLatLonKnown() { 31 return !Double.isNaN(lat) && !Double.isNaN(lon);29 return latLon != null; 32 30 } 33 31 34 32 @Override … … 56 54 57 55 @Override 58 56 public final LatLon getCoor() { 59 if (!isLatLonKnown()) return null; 60 return new LatLon(lat,lon); 57 return latLon; 61 58 } 62 59 63 60 /** … … 77 74 */ 78 75 @Override 79 76 public final EastNorth getEastNorth() { 80 if (!isLatLonKnown()) return null; 77 if (!isLatLonKnown()) 78 return null; 81 79 82 80 if (getDataSet() == null) 83 81 // there is no dataset that listens for projection changes 84 82 // and invalidates the cache, so we don't use the cache at all 85 return Projections.project( new LatLon(lat, lon));83 return Projections.project(latLon); 86 84 87 if ( Double.isNaN(east) || Double.isNaN(north)) {85 if (eastNorth == null) { 88 86 // projected coordinates haven't been calculated yet, 89 87 // so fill the cache of the projected node coordinates 90 EastNorth en = Projections.project(new LatLon(lat, lon)); 91 this.east = en.east(); 92 this.north = en.north(); 88 eastNorth = Projections.project(latLon); 93 89 } 94 return new EastNorth(east, north);90 return eastNorth; 95 91 } 96 92 97 93 /** … … 99 95 */ 100 96 protected void setCoorInternal(LatLon coor, EastNorth eastNorth) { 101 97 if (coor != null) { 102 this.lat = coor.lat(); 103 this.lon = coor.lon(); 98 this.latLon = coor; 104 99 invalidateEastNorthCache(); 105 100 } else if (eastNorth != null) { 106 LatLon ll = Projections.inverseProject(eastNorth); 107 this.lat = ll.lat(); 108 this.lon = ll.lon(); 109 this.east = eastNorth.east(); 110 this.north = eastNorth.north(); 101 this.latLon = Projections.inverseProject(eastNorth); 102 this.eastNorth = eastNorth; 111 103 } else { 112 this.lat = Double.NaN; 113 this.lon = Double.NaN; 104 latLon = null; 114 105 invalidateEastNorthCache(); 115 106 if (isVisible()) { 116 107 setIncomplete(true); … … 209 200 boolean locked = writeLock(); 210 201 try { 211 202 super.cloneFrom(osm); 212 setCoor(((Node) osm).getCoor());203 setCoor(((Node) osm).getCoor()); 213 204 } finally { 214 205 writeUnlock(locked); 215 206 } … … 232 223 try { 233 224 super.mergeFrom(other); 234 225 if (!other.isIncomplete()) { 235 setCoor(((Node) other).getCoor());226 setCoor(((Node) other).getCoor()); 236 227 } 237 228 } finally { 238 229 writeUnlock(locked); 239 230 } 240 231 } 241 232 242 @Override public void load(PrimitiveData data) { 233 @Override 234 public void load(PrimitiveData data) { 243 235 boolean locked = writeLock(); 244 236 try { 245 237 super.load(data); 246 setCoor(((NodeData) data).getCoor());238 setCoor(((NodeData) data).getCoor()); 247 239 } finally { 248 240 writeUnlock(locked); 249 241 } 250 242 } 251 243 252 @Override public NodeData save() { 244 @Override 245 public NodeData save() { 253 246 NodeData data = new NodeData(); 254 247 saveCommonAttributes(data); 255 248 if (!isIncomplete()) { … … 260 253 261 254 @Override 262 255 public String toString() { 263 String coorDesc = isLatLonKnown() ? "lat="+lat+",lon="+lon : ""; 264 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}"; 256 String coorDesc = isLatLonKnown() ? "lat=" + latLon.lat() + ",lon=" + latLon.lon() : ""; 257 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc 258 + "}"; 265 259 } 266 260 267 261 @Override 268 262 public boolean hasEqualSemanticAttributes(OsmPrimitive other) { 269 263 if (!(other instanceof Node)) 270 264 return false; 271 if (! super.hasEqualSemanticAttributes(other))265 if (!super.hasEqualSemanticAttributes(other)) 272 266 return false; 273 Node n = (Node) other;267 Node n = (Node) other; 274 268 LatLon coor = getCoor(); 275 269 LatLon otherCoor = n.getCoor(); 276 270 if (coor == null && otherCoor == null) … … 327 321 * next time. 328 322 */ 329 323 public void invalidateEastNorthCache() { 330 this.east = Double.NaN; 331 this.north = Double.NaN; 324 eastNorth = null; 332 325 } 333 326 } -
src/org/openstreetmap/josm/data/osm/NodeData.java
8 8 9 9 public class NodeData extends PrimitiveData implements INode { 10 10 11 /* 12 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint 13 */ 14 private double lat = Double.NaN; 15 private double lon = Double.NaN; 11 private LatLon latLon; 16 12 17 public NodeData() {} 13 public NodeData() { 14 } 18 15 19 16 public NodeData(NodeData data) { 20 17 super(data); 21 18 setCoor(data.getCoor()); 22 19 } 23 20 24 private boolean isLatLonKnown() {25 return !Double.isNaN(lat) && !Double.isNaN(lon);26 }27 28 21 @Override 29 22 public LatLon getCoor() { 30 return isLatLonKnown() ? new LatLon(lat,lon) : null;23 return latLon; 31 24 } 32 25 33 26 @Override 34 27 public void setCoor(LatLon coor) { 35 if (coor == null) { 36 this.lat = Double.NaN; 37 this.lon = Double.NaN; 38 } else { 39 this.lat = coor.lat(); 40 this.lon = coor.lon(); 41 } 28 latLon = coor; 42 29 } 43 30 44 31 @Override
