Ignore:
Timestamp:
2009-11-14T18:47:09+01:00 (17 years ago)
Author:
jttt
Message:

Added parameter Bounds to MapView, draw only currently visible primitives in MapPaintVisititor

File:
1 edited

Legend:

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

    r2449 r2450  
    5858    public static double WORLD_PARTS = (1 << NR_LEVELS);
    5959
    60     public static int MAX_OBJECTS_PER_LEVEL = 16;
    61     // has to be a power of 2
    62     public static int TILES_PER_LEVEL_SHIFT = 2;
    63     public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;
    64     // Maybe this should just be a Rectangle??
    65     public static class BBox
    66     {
    67         private double xmin = Double.POSITIVE_INFINITY;
    68         private double xmax = Double.NEGATIVE_INFINITY;
    69         private double ymin = Double.POSITIVE_INFINITY;
    70         private double ymax = Double.NEGATIVE_INFINITY;
    71         void sanity()
    72         {
    73             if (xmin < -180.0) {
    74                 xmin = -180.0;
    75             }
    76             if (xmax >  180.0) {
    77                 xmax =  180.0;
    78             }
    79             if (ymin <  -90.0) {
    80                 ymin =  -90.0;
    81             }
    82             if (ymax >   90.0) {
    83                 ymax =   90.0;
    84             }
    85             if ((xmin < -180.0) ||
    86                     (xmax >  180.0) ||
    87                     (ymin <  -90.0) ||
    88                     (ymax >   90.0))
    89                 throw new IllegalArgumentException("bad BBox: " + this);
    90         }
    91         @Override
    92         public String toString()
    93         {
    94             return "[ x: " + xmin + " -> " + xmax +
    95             ", y: " + ymin + " -> " + ymax + " ]";
    96         }
    97         double min(double a, double b)
    98         {
    99             if (a < b)
    100                 return a;
    101             return b;
    102         }
    103         double max(double a, double b)
    104         {
    105             if (a > b)
    106                 return a;
    107             return b;
    108         }
    109         private void add(LatLon c)
    110         {
    111             xmin = min(xmin, c.lon());
    112             xmax = max(xmax, c.lon());
    113             ymin = min(ymin, c.lat());
    114             ymax = max(ymax, c.lat());
    115         }
    116         public BBox(LatLon a, LatLon b)
    117         {
    118             add(a);
    119             add(b);
    120             sanity();
    121         }
    122         public BBox(double a_x, double a_y, double b_x, double b_y)
    123         {
    124             xmin = min(a_x, b_x);
    125             xmax = max(a_x, b_x);
    126             ymin = min(a_y, b_y);
    127             ymax = max(a_y, b_y);
    128             sanity();
    129         }
    130         public BBox(Way w)
    131         {
    132             for (Node n : w.getNodes()) {
    133                 LatLon coor = n.getCoor();
    134                 if (coor == null) {
    135                     continue;
    136                 }
    137                 add(coor);
    138             }
    139             this.sanity();
    140         }
    141         public double height()
    142         {
    143             return ymax-ymin;
    144         }
    145         public double width()
    146         {
    147             return xmax-xmin;
    148         }
    149         boolean bounds(BBox b)
    150         {
    151             if (!(xmin <= b.xmin) ||
    152                     !(xmax >= b.xmax) ||
    153                     !(ymin <= b.ymin) ||
    154                     !(ymax >= b.ymax))
    155                 return false;
    156             return true;
    157         }
    158         boolean bounds(LatLon c)
    159         {
    160             if ((xmin <= c.lon()) &&
    161                     (xmax >= c.lon()) &&
    162                     (ymin <= c.lat()) &&
    163                     (ymax >= c.lat()))
    164                 return true;
    165             return false;
    166         }
    167         boolean inside(BBox b)
    168         {
    169             if (xmin >= b.xmax)
    170                 return false;
    171             if (xmax <= b.xmin)
    172                 return false;
    173             if (ymin >= b.ymax)
    174                 return false;
    175             if (ymax <= b.ymin)
    176                 return false;
    177             return true;
    178         }
    179         boolean intersects(BBox b)
    180         {
    181             return this.inside(b) || b.inside(this);
    182         }
    183         List<LatLon> points()
    184         {
    185             LatLon p1 = new LatLon(ymin, xmin);
    186             LatLon p2 = new LatLon(ymin, xmax);
    187             LatLon p3 = new LatLon(ymax, xmin);
    188             LatLon p4 = new LatLon(ymax, xmax);
    189             List<LatLon> ret = new ArrayList<LatLon>();
    190             ret.add(p1);
    191             ret.add(p2);
    192             ret.add(p3);
    193             ret.add(p4);
    194             return ret;
    195         }
    196     }
     60    public static int MAX_OBJECTS_PER_LEVEL = 2;
    19761    class QBLevel
    19862    {
     
    294158                    continue;
    295159                }
    296                 if (children == null)
     160                if (children == null) {
    297161                    children = newChildren();
     162                }
    298163                if (children[new_index] == null) {
    299164                    children[new_index] = new QBLevel(this, new_index);
     
    725590        public BBox bbox()
    726591        {
    727             if (bbox != null) {
    728                 bbox.sanity();
     592            if (bbox != null)
    729593                return bbox;
    730             }
    731594            if (level == 0) {
    732595                bbox = new BBox(-180, 90, 180, -90);
     
    738601                bbox = new BBox(bottom_left, top_right);
    739602            }
    740             bbox.sanity();
    741603            return bbox;
    742604        }
     
    1100962            out("search bbox before sanity: " +  bbox);
    1101963        }
    1102         bbox.sanity();
    1103964        if (debug) {
    1104965            out("search bbox after sanity: " +  bbox);
     
    1124985    {
    1125986        BBox bbox = new BBox(b1.lon(), b1.lat(), b2.lon(), b2.lat());
    1126         bbox.sanity();
    1127987        return this.search(bbox);
    1128988    }
Note: See TracChangeset for help on using the changeset viewer.