Changeset 3145 in josm
- Timestamp:
- 2010-03-19T21:59:29+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/QuadTiling.java
r3083 r3145 7 7 public static double WORLD_PARTS = (1 << NR_LEVELS); 8 8 9 public static int MAX_OBJECTS_PER_LEVEL = 16; 10 // has to be a power of 2 11 public static int TILES_PER_LEVEL_SHIFT = 2; 9 public static int TILES_PER_LEVEL_SHIFT = 2; // Has to be 2. Other parts of QuadBuckets code rely on it 12 10 public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT; 13 11 static public int X_PARTS = 360; … … 97 95 return (int)(mask & (quad >> total_shift)); 98 96 } 99 static public int index(LatLon coor, int level) 100 { 97 static public int index(LatLon coor, int level) { 101 98 // The nodes that don't return coordinates will all get 102 99 // stuck in a single tile. Hopefully there are not too … … 104 101 if (coor == null) 105 102 return 0; 106 long quad = coorToTile(coor); 107 return index(level, quad); 103 104 long x = lon2x(coor.lon()); 105 long y = lat2y(coor.lat()); 106 int shift = NR_LEVELS-level-1; 107 return (int)((x >> shift & 1) * 2 + (y >> shift & 1)); 108 108 } 109 109 } -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r3083 r3145 60 60 class QBLevel 61 61 { 62 int level; 63 long quad; 64 QBLevel parent; 62 final int level; 63 private final BBox bbox; 64 final long quad; 65 final QBLevel parent; 65 66 66 67 public List<T> content; … … 71 72 return super.toString()+ "["+level+"]: " + bbox(); 72 73 } 73 public QBLevel(QBLevel parent) 74 { 75 init(parent); 76 } 74 /** 75 * Constructor for root node 76 */ 77 public QBLevel() { 78 level = 0; 79 quad = 0; 80 parent = null; 81 bbox = new BBox(-180, 90, 180, -90); 82 } 83 84 public QBLevel(QBLevel parent, int parent_index) { 85 this.parent = parent; 86 this.level = parent.level + 1; 87 int shift = (QuadBuckets.NR_LEVELS - level) * 2; 88 long mult = 1; 89 // Java blows the big one. It seems to wrap when 90 // you shift by > 31 91 if (shift >= 30) { 92 shift -= 30; 93 mult = 1<<30; 94 } 95 long this_quadpart = mult * (parent_index << shift); 96 this.quad = parent.quad | this_quadpart; 97 this.bbox = calculateBBox(); // calculateBBox reference quad 98 if (debug) { 99 out("new level["+this.level+"] bbox["+parent_index+"]: " + this.bbox() 100 + " coor: " + this.coor() 101 + " quadpart: " + Long.toHexString(this_quadpart) 102 + " quad: " + Long.toHexString(this.quad)); 103 } 104 } 105 106 private BBox calculateBBox() { 107 LatLon bottom_left = this.coor(); 108 double lat = bottom_left.lat() + parent.height() / 2; 109 double lon = bottom_left.lon() + parent.width() / 2; 110 LatLon top_right = new LatLon(lat, lon); 111 return new BBox(bottom_left, top_right); 112 } 113 77 114 boolean remove_content(T o) 78 115 { … … 535 572 return Long.toHexString(quad); 536 573 } 537 public void init(QBLevel parent)538 {539 this.parent = parent;540 if (parent == null) {541 this.level = 0;542 } else {543 this.level = parent.level + 1;544 }545 this.quad = 0;546 }547 574 int index_of(QBLevel find_this) 548 575 { … … 556 583 return -1; 557 584 } 558 public QBLevel(QBLevel parent, int parent_index) 559 { 560 this.init(parent); 561 int shift = (QuadBuckets.NR_LEVELS - level) * 2; 562 long mult = 1; 563 // Java blows the big one. It seems to wrap when 564 // you shift by > 31 565 if (shift >= 30) { 566 shift -= 30; 567 mult = 1<<30; 568 } 569 long this_quadpart = mult * (parent_index << shift); 570 this.quad = parent.quad | this_quadpart; 571 if (debug) { 572 out("new level["+this.level+"] bbox["+parent_index+"]: " + this.bbox() 573 + " coor: " + this.coor() 574 + " quadpart: " + Long.toHexString(this_quadpart) 575 + " quad: " + Long.toHexString(this.quad)); 576 } 577 } 578 /* 579 * Surely we can calculate these efficiently instead of storing 580 */ 581 double width = Double.NEGATIVE_INFINITY; 582 double width() 583 { 584 if (width != Double.NEGATIVE_INFINITY) 585 return this.width; 586 if (level == 0) { 587 width = this.bbox().width(); 588 } else { 589 width = parent.width()/2; 590 } 591 return width; 592 } 593 double height() 594 { 595 return width()/2; 596 } 597 private BBox bbox = null; 598 public BBox bbox() 599 { 600 if (bbox != null) 601 return bbox; 602 if (level == 0) { 603 bbox = new BBox(-180, 90, 180, -90); 604 } else { 605 LatLon bottom_left = this.coor(); 606 double lat = bottom_left.lat() + this.height(); 607 double lon = bottom_left.lon() + this.width(); 608 LatLon top_right = new LatLon(lat, lon); 609 bbox = new BBox(bottom_left, top_right); 610 } 585 double width() { 586 return bbox.width(); 587 } 588 589 double height() { 590 return bbox.height(); 591 } 592 593 public BBox bbox() { 611 594 return bbox; 612 595 } … … 675 658 public void clear() 676 659 { 677 root = new QBLevel( null);660 root = new QBLevel(); 678 661 search_cache = null; 679 662 if (debug) { … … 717 700 public void reindex() 718 701 { 719 QBLevel newroot = new QBLevel( null);702 QBLevel newroot = new QBLevel(); 720 703 Iterator<T> i = this.iterator(); 721 704 while (i.hasNext()) {
Note:
See TracChangeset
for help on using the changeset viewer.