Changeset 1273 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-01-17T11:38:59+01:00 (16 years ago)
Author:
ulfl
Message:

We don't need to transform each node to check it for visibility. So for each visitAll(), transform the current screen bounds coordinates to EastNorth only once and do each visibility check of an OsmPrimitive against these values.

Put getColors() back in, was a merge mistake ;-)

File:
1 edited

Legend:

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

    r1272 r1273  
    2929import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    3030import org.openstreetmap.josm.data.coor.LatLon;
     31import org.openstreetmap.josm.data.coor.EastNorth;
    3132import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
    3233import org.openstreetmap.josm.gui.mappaint.ElemStyle;
     
    5960    private static int paintid = 0;
    6061    private static int viewid = 0;
     62    private EastNorth minEN;
     63    private EastNorth maxEN;
    6164
    6265    protected int profilerVisibleNodes;
     
    114117    public void visit(Node n) {
    115118        // check, if the node is visible at all
    116         Point p = nc.getPoint(n.eastNorth);
    117         if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight()))
     119        if((n.eastNorth.east()  > maxEN.east() ) ||
     120           (n.eastNorth.north() > maxEN.north()) ||
     121           (n.eastNorth.east()  < minEN.east() ) ||
     122           (n.eastNorth.north() < minEN.north()))
    118123        {
    119124            n.mappaintVisibleCode = viewid;
     
    149154
    150155        // check, if the way is visible at all
    151         Polygon polygon = getPolygon(w);
    152         if(!isPolygonVisible(polygon))
     156        double minx = 10000;
     157        double maxx = -10000;
     158        double miny = 10000;
     159        double maxy = -10000;
     160
     161        for (Node n : w.nodes)
     162        {
     163            if(n.eastNorth.east() > maxx) maxx = n.eastNorth.east();
     164            if(n.eastNorth.north() > maxy) maxy = n.eastNorth.north();
     165            if(n.eastNorth.east() < minx) minx = n.eastNorth.east();
     166            if(n.eastNorth.north() < miny) miny = n.eastNorth.north();
     167        }
     168       
     169        if ((minx > maxEN.east()) ||
     170            (miny > maxEN.north()) ||
     171            (maxx < minEN.east()) ||
     172            (maxy < minEN.north()))
    153173        {
    154174            w.mappaintVisibleCode = viewid;
     
    190210                {
    191211                    profilerVisibleAreas++;
    192                     drawArea(polygon, w.selected ? selectedColor : ((AreaElemStyle)wayStyle).color);
     212                    drawArea(w, w.selected ? selectedColor : ((AreaElemStyle)wayStyle).color);
    193213                    if(!w.isClosed())
    194214                        w.putError(tr("Area style way is not closed."), true);
     
    409429                drawWay((Way)osm, ((AreaElemStyle)style).line, selectedColor, true);
    410430                if(area)
    411                     drawArea(getPolygon((Way)osm), areaselected ? selectedColor
     431                    drawArea((Way)osm, areaselected ? selectedColor
    412432                    : ((AreaElemStyle)style).color);
    413433            }
     
    650670                    if(isPolygonVisible(pd.get()))
    651671                    {
    652                         drawArea(pd.get(), (pd.way.selected || r.selected) ? selectedColor
     672                        drawArea(pd.way, (pd.way.selected || r.selected) ? selectedColor
    653673                        : ((AreaElemStyle)wayStyle).color);
    654674                        visible = true;
     
    741761    }
    742762
    743     protected void drawArea(Polygon polygon, Color color)
     763    protected void drawArea(Way w, Color color)
    744764    {
     765        Polygon polygon = getPolygon(w);
     766       
    745767        // set the opacity (alpha) level of the filled polygon
    746768        g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), fillAlpha));
     
    872894    }
    873895
    874     /*public void getColors()
     896    public void getColors()
    875897    {
    876898        super.getColors();
    877899        untaggedColor = Main.pref.getColor(marktr("untagged"),Color.GRAY);
    878900        textColor = Main.pref.getColor (marktr("text"), Color.WHITE);
    879     }*/
     901    }
    880902
    881903    // Shows areas before non-areas
     
    910932        String currentLocale = Locale.getDefault().getLanguage();
    911933        regionalNameOrder = Main.pref.get("mappaint.nameOrder", "name:"+currentLocale+";name;int_name;ref;operator;brand").split(";");
     934        minEN = nc.getEastNorth(0,nc.getHeight()-1);
     935        maxEN = nc.getEastNorth(nc.getWidth()-1,0);
     936       
    912937
    913938        selectedCall = false;
Note: See TracChangeset for help on using the changeset viewer.