Ticket #9002: nodes.diff

File nodes.diff, 6.4 KB (added by shinigami, 13 years ago)
  • src/org/openstreetmap/josm/data/osm/Node.java

     
    1616public final class Node extends OsmPrimitive implements INode {
    1717
    1818    /*
    19      * We "inline" lat/lon rather than using a LatLon-object => reduces memory footprint
     19     * the coordinates
    2020     */
    21     private double lat = Double.NaN;
    22     private double lon = Double.NaN;
     21    private LatLon latLon;
    2322
    2423    /*
    2524     * the cached projected coordinates
    2625     */
    27     private double east = Double.NaN;
    28     private double north = Double.NaN;
     26    private EastNorth eastNorth;
    2927
    3028    private boolean isLatLonKnown() {
    31         return !Double.isNaN(lat) && !Double.isNaN(lon);
     29        return latLon != null;
    3230    }
    3331
    3432    @Override
     
    5654
    5755    @Override
    5856    public final LatLon getCoor() {
    59         if (!isLatLonKnown()) return null;
    60         return new LatLon(lat,lon);
     57        return latLon;
    6158    }
    6259
    6360    /**
     
    7774     */
    7875    @Override
    7976    public final EastNorth getEastNorth() {
    80         if (!isLatLonKnown()) return null;
     77        if (!isLatLonKnown())
     78            return null;
    8179
    8280        if (getDataSet() == null)
    8381            // there is no dataset that listens for projection changes
    8482            // 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);
    8684
    87         if (Double.isNaN(east) || Double.isNaN(north)) {
     85        if (eastNorth == null) {
    8886            // projected coordinates haven't been calculated yet,
    8987            // 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);
    9389        }
    94         return new EastNorth(east, north);
     90        return eastNorth;
    9591    }
    9692
    9793    /**
     
    9995     */
    10096    protected void setCoorInternal(LatLon coor, EastNorth eastNorth) {
    10197        if (coor != null) {
    102             this.lat = coor.lat();
    103             this.lon = coor.lon();
     98            this.latLon = coor;
    10499            invalidateEastNorthCache();
    105100        } 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;
    111103        } else {
    112             this.lat = Double.NaN;
    113             this.lon = Double.NaN;
     104            latLon = null;
    114105            invalidateEastNorthCache();
    115106            if (isVisible()) {
    116107                setIncomplete(true);
     
    209200        boolean locked = writeLock();
    210201        try {
    211202            super.cloneFrom(osm);
    212             setCoor(((Node)osm).getCoor());
     203            setCoor(((Node) osm).getCoor());
    213204        } finally {
    214205            writeUnlock(locked);
    215206        }
     
    232223        try {
    233224            super.mergeFrom(other);
    234225            if (!other.isIncomplete()) {
    235                 setCoor(((Node)other).getCoor());
     226                setCoor(((Node) other).getCoor());
    236227            }
    237228        } finally {
    238229            writeUnlock(locked);
    239230        }
    240231    }
    241232
    242     @Override public void load(PrimitiveData data) {
     233    @Override
     234    public void load(PrimitiveData data) {
    243235        boolean locked = writeLock();
    244236        try {
    245237            super.load(data);
    246             setCoor(((NodeData)data).getCoor());
     238            setCoor(((NodeData) data).getCoor());
    247239        } finally {
    248240            writeUnlock(locked);
    249241        }
    250242    }
    251243
    252     @Override public NodeData save() {
     244    @Override
     245    public NodeData save() {
    253246        NodeData data = new NodeData();
    254247        saveCommonAttributes(data);
    255248        if (!isIncomplete()) {
     
    260253
    261254    @Override
    262255    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                + "}";
    265259    }
    266260
    267261    @Override
    268262    public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
    269263        if (!(other instanceof Node))
    270264            return false;
    271         if (! super.hasEqualSemanticAttributes(other))
     265        if (!super.hasEqualSemanticAttributes(other))
    272266            return false;
    273         Node n = (Node)other;
     267        Node n = (Node) other;
    274268        LatLon coor = getCoor();
    275269        LatLon otherCoor = n.getCoor();
    276270        if (coor == null && otherCoor == null)
     
    327321     * next time.
    328322     */
    329323    public void invalidateEastNorthCache() {
    330         this.east = Double.NaN;
    331         this.north = Double.NaN;
     324        eastNorth = null;
    332325    }
    333326}
  • src/org/openstreetmap/josm/data/osm/NodeData.java

     
    88
    99public class NodeData extends PrimitiveData implements INode {
    1010
    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;
    1612
    17     public NodeData() {}
     13    public NodeData() {
     14    }
    1815
    1916    public NodeData(NodeData data) {
    2017        super(data);
    2118        setCoor(data.getCoor());
    2219    }
    2320
    24     private boolean isLatLonKnown() {
    25         return !Double.isNaN(lat) && !Double.isNaN(lon);
    26     }
    27 
    2821    @Override
    2922    public LatLon getCoor() {
    30         return isLatLonKnown() ? new LatLon(lat,lon) : null;
     23        return latLon;
    3124    }
    3225
    3326    @Override
    3427    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;
    4229    }
    4330
    4431    @Override