Changeset 11269 in josm for trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
- Timestamp:
- 2016-11-17T19:58:39+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r11237 r11269 6 6 import java.util.Collection; 7 7 import java.util.Iterator; 8 import java.util.LinkedHashSet; 8 9 import java.util.List; 9 10 import java.util.NoSuchElementException; … … 167 168 168 169 boolean matches(final T o, final BBox searchBbox) { 169 if (o instanceof Node) {170 final LatLon latLon = ((Node) o).getCoor();171 // node without coords -> bbox[0,0,0,0]172 return searchBbox.bounds(latLon != null ? latLon : LatLon.ZERO);173 }174 170 return o.getBBox().intersects(searchBbox); 175 171 } … … 359 355 private QBLevel<T> searchCache; 360 356 private int size; 357 private Collection<T> invalidBBoxPrimitives; 361 358 362 359 /** … … 370 367 public final void clear() { 371 368 root = new QBLevel<>(); 369 invalidBBoxPrimitives = new LinkedHashSet<>(); 372 370 searchCache = null; 373 371 size = 0; … … 376 374 @Override 377 375 public boolean add(T n) { 378 root.add(n); 376 if (n.getBBox().isValid()) 377 root.add(n); 378 else 379 invalidBBoxPrimitives.add(n); 379 380 size++; 380 381 return true; … … 426 427 searchCache = null; // Search cache might point to one of removed buckets 427 428 QBLevel<T> bucket = root.findBucket(t.getBBox()); 428 if (bucket.removeContent(t)) { 429 boolean removed = bucket.removeContent(t); 430 if (!removed) 431 removed = invalidBBoxPrimitives.remove(o); 432 if (removed) 429 433 size--; 430 return true; 431 } else 432 return false; 434 return removed; 433 435 } 434 436 … … 437 439 @SuppressWarnings("unchecked") 438 440 T t = (T) o; 441 if (!t.getBBox().isValid()) 442 return invalidBBoxPrimitives.contains(o); 439 443 QBLevel<T> bucket = root.findBucket(t.getBBox()); 440 444 return bucket != null && bucket.content != null && bucket.content.contains(t); … … 466 470 private QBLevel<T> currentNode; 467 471 private int contentIndex; 472 private Iterator<T> invalidBBoxIterator = invalidBBoxPrimitives.iterator(); 473 boolean fromInvalidBBoxPrimitives; 468 474 QuadBuckets<T> qb; 469 475 … … 491 497 @Override 492 498 public boolean hasNext() { 493 if (this.peek() == null) 494 return false; 499 if (this.peek() == null) { 500 fromInvalidBBoxPrimitives = true; 501 return invalidBBoxIterator.hasNext(); 502 } 495 503 return true; 496 504 } … … 513 521 @Override 514 522 public T next() { 523 if (fromInvalidBBoxPrimitives) 524 return invalidBBoxIterator.next(); 515 525 T ret = peek(); 516 526 if (ret == null) … … 522 532 @Override 523 533 public void remove() { 524 // two uses 525 // 1. Back up to the thing we just returned 526 // 2. move the index back since we removed 527 // an element 528 contentIndex--; 529 T object = peek(); 530 if (currentNode.removeContent(object)) 534 if (fromInvalidBBoxPrimitives) { 535 invalidBBoxIterator.remove(); 531 536 qb.size--; 537 } else { 538 // two uses 539 // 1. Back up to the thing we just returned 540 // 2. move the index back since we removed 541 // an element 542 contentIndex--; 543 T object = peek(); 544 if (currentNode.removeContent(object)) 545 qb.size--; 546 547 } 532 548 } 533 549 } … … 555 571 public List<T> search(BBox searchBbox) { 556 572 List<T> ret = new ArrayList<>(); 573 if (!searchBbox.isValid()) { 574 return ret; 575 } 576 557 577 // Doing this cuts down search cost on a real-life data set by about 25% 558 578 if (searchCache == null) {
Note:
See TracChangeset
for help on using the changeset viewer.