Ticket #8902: quadbucketsindex.diff
File quadbucketsindex.diff, 5.1 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/data/coor/QuadTiling.java
102 102 int shift = NR_LEVELS-level-1; 103 103 return (int)((x >> shift & 1) * 2 + (y >> shift & 1)); 104 104 } 105 106 static public int index(double lat, double lon, int level) { 107 long x = lon2x(lon); 108 long y = lat2y(lat); 109 int shift = NR_LEVELS-level-1; 110 return (int)((x >> shift & 1) * 2 + (y >> shift & 1)); 111 } 105 112 } -
src/org/openstreetmap/josm/data/osm/BBox.java
7 7 8 8 import org.openstreetmap.josm.data.Bounds; 9 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.coor.QuadTiling; 10 11 import org.openstreetmap.josm.tools.Utils; 11 12 12 13 public class BBox { … … 151 152 return true; 152 153 } 153 154 154 /**155 * Returns a list of all 4 corners of the bbox rectangle.156 */157 public List<LatLon> points() {158 LatLon p1 = new LatLon(ymin, xmin);159 LatLon p2 = new LatLon(ymin, xmax);160 LatLon p3 = new LatLon(ymax, xmin);161 LatLon p4 = new LatLon(ymax, xmax);162 List<LatLon> ret = new ArrayList<LatLon>(4);163 ret.add(p1);164 ret.add(p2);165 ret.add(p3);166 ret.add(p4);167 return ret;168 }169 170 155 public LatLon getTopLeft() { 171 156 return new LatLon(ymax, xmin); 172 157 } … … 179 164 return new LatLon(ymin + (ymax-ymin)/2.0, xmin + (xmax-xmin)/2.0); 180 165 } 181 166 167 int getIndex(final int level) { 168 169 int idx1 = QuadTiling.index(ymin, xmin, level); 170 171 final int idx2 = QuadTiling.index(ymin, xmax, level); 172 if (idx1 == -1) idx1 = idx2; 173 else if (idx1 != idx2) return -1; 174 175 final int idx3 = QuadTiling.index(ymax, xmin, level); 176 if (idx1 == -1) idx1 = idx3; 177 else if (idx1 != idx3) return -1; 178 179 final int idx4 = QuadTiling.index(ymax, xmax, level); 180 if (idx1 == -1) idx1 = idx4; 181 else if (idx1 != idx4) return -1; 182 183 return idx1; 184 } 185 182 186 @Override 183 187 public int hashCode() { 184 188 return (int)(ymin * xmin); -
src/org/openstreetmap/josm/data/osm/QuadBuckets.java
158 158 if (!hasChildren()) 159 159 return this; 160 160 else { 161 int index = get_index(bbox,level);161 int index = bbox.getIndex(level); 162 162 if (index == -1) 163 163 return this; 164 164 return getChild(index).findBucket(bbox); … … 183 183 } 184 184 return ret; 185 185 } 186 // Get the correct index for the given primitive 187 // at the given level. If the primitive can not 188 // fit into a single quad at this level, return -1 189 int get_index(BBox bbox, int level) { 190 int index = -1; 191 for (LatLon c : bbox.points()) { 192 /*if (debug) { 193 out("getting index for point: " + c); 194 }*/ 195 if (index == -1) { 196 index = QuadTiling.index(c, level); 197 /*if (debug) { 198 out("set initial index to: " + index); 199 }*/ 200 continue; 201 } 202 int another_index = QuadTiling.index(c, level); 203 /*if (debug) { 204 out("other point index: " + another_index); 205 }*/ 206 if (another_index != index) 207 return -1; 208 } 209 return index; 210 } 186 211 187 /* 212 188 * There is a race between this and qb.nextContentNode(). 213 189 * If nextContentNode() runs into this bucket, it may … … 224 200 content = null; 225 201 226 202 for (T o: tmpcontent) { 227 int index = get_index(o.getBBox(),level);203 int index = o.getBBox().getIndex(level); 228 204 if (index == -1) { 229 205 __add_content(o); 230 206 } else { … … 377 353 if (!matches(o, this.bbox())) { 378 354 /*out("-----------------------------"); 379 355 debug = true;*/ 380 get_index(o.getBBox(),level);381 get_index(o.getBBox(),level-1);356 o.getBBox().getIndex(level); 357 o.getBBox().getIndex(level-1); 382 358 int nr = 0; 383 359 /*for (QBLevel sibling : parent.getChildren()) { 384 360 out("sibling["+ (nr++) +"]: " + sibling.bbox() + " this: " + (this==sibling));