Changeset 2437 in josm


Ignore:
Timestamp:
Nov 11, 2009 8:34:56 AM (4 years ago)
Author:
jttt
Message:

Cache bbox for Way

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
6 edited

Legend:

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

    r2419 r2437  
    768768    } 
    769769 
    770     void reindexNode(Node node) { 
     770    private void reindexNode(Node node) { 
    771771        nodes.remove(node); 
    772772        nodes.add(node); 
    773773        for (Way way:OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) { 
    774774            ways.remove(way); 
     775            way.updatePosition(); 
    775776            ways.add(way); 
    776777        } 
    777778    } 
    778779 
    779     void reindexWay(Way way) { 
     780    private void reindexWay(Way way) { 
    780781        ways.remove(way); 
    781782        ways.add(way); 
     783    } 
     784 
     785    public void fireNodeMoved(Node node) { 
     786        // TODO Fire event 
     787        reindexNode(node); 
     788    } 
     789 
     790    public void fireWayNodesChanged(Way way) { 
     791        // TODO Fire event 
     792        reindexWay(way); 
    782793    } 
    783794 
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r2427 r2437  
    2525            } 
    2626            if (getDataSet() != null) { 
    27                 getDataSet().reindexNode(this); 
     27                getDataSet().fireNodeMoved(this); 
    2828            } 
    2929        } 
     
    4343            } 
    4444            if (getDataSet() != null) { 
    45                 getDataSet().reindexNode(this); 
     45                getDataSet().fireNodeMoved(this); 
    4646            } 
    4747        } 
     
    177177    } 
    178178 
     179    @Override 
    179180    public BBox getBBox() { 
    180181        if (coor == null) 
     
    183184            return new BBox(coor, coor); 
    184185    } 
     186 
     187    @Override 
     188    public void updatePosition() { 
     189        // Do nothing for now, but in future replace CachedLatLon with simple doubles and update precalculated EastNorth value here 
     190    } 
    185191} 
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2427 r2437  
    10101010    public abstract BBox getBBox(); 
    10111011 
     1012    /** 
     1013     * Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...) 
     1014     */ 
     1015    public abstract void updatePosition(); 
     1016 
    10121017} 
    10131018 
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r2430 r2437  
    206206        { 
    207207            init(parent); 
    208         } 
    209         String quads(T o) 
    210         { 
    211             if (o instanceof Node) { 
    212                 LatLon coor = ((Node)o).getCoor(); 
    213                 if (coor == null) 
    214                     return "null node coordinates"; 
    215                 return Long.toHexString(QuadTiling.quadTile(coor)); 
    216             } 
    217             return "Way??"; 
    218208        } 
    219209        synchronized boolean remove_content(T o) 
     
    302292                QBLevel child = children[new_index]; 
    303293                if (debug) { 
    304                     out("putting "+o+"(q:"+quads(o)+") into ["+new_index+"] " + child.bbox()); 
     294                    out("putting "+o+"(q:"+Long.toHexString(QuadTiling.quadTile(o.getBBox().points().get(0)))+") into ["+new_index+"] " + child.bbox()); 
    305295                } 
    306296                child.add(o); 
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2427 r2437  
    330330        return new BBox(0, 0, 0, 0); 
    331331    } 
     332 
     333    @Override 
     334    public void updatePosition() { 
     335        // Do nothing for now 
     336    } 
    332337} 
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2427 r2437  
    2626     */ 
    2727    private Node[] nodes = new Node[0]; 
     28    private BBox bbox; 
    2829 
    2930    /** 
     
    6061 
    6162        clearCached(); 
    62         reindex(); 
     63        fireNodesChanged(); 
    6364    } 
    6465 
     
    289290        newNodes[nodes.length] = n; 
    290291        nodes = newNodes; 
    291         reindex(); 
     292        fireNodesChanged(); 
    292293    } 
    293294 
     
    312313        newNodes[offs] = n; 
    313314        nodes = newNodes; 
    314         reindex(); 
     315        fireNodesChanged(); 
    315316    } 
    316317 
     
    324325            } 
    325326        } 
    326         reindex(); 
     327        fireNodesChanged(); 
    327328        super.setDeleted(deleted); 
    328329    } 
     
    358359    } 
    359360 
    360     private void reindex() { 
     361    private void fireNodesChanged() { 
    361362        if (getDataSet() != null) { 
    362             getDataSet().reindexWay(this); 
     363            getDataSet().fireWayNodesChanged(this); 
    363364        } 
    364365    } 
     
    366367    @Override 
    367368    public BBox getBBox() { 
    368         // TODO Precalculate way bbox (and update it every time nodes are moved or edited) 
    369         return new BBox(this); 
     369        if (getDataSet() == null) 
     370            return new BBox(this); 
     371        if (bbox == null) { 
     372            bbox = new BBox(this); 
     373        } 
     374        return bbox; 
     375    } 
     376 
     377    @Override 
     378    public void updatePosition() { 
     379        bbox = new BBox(this); 
    370380    } 
    371381} 
Note: See TracChangeset for help on using the changeset viewer.