Changeset 11272 in josm for trunk/src/org
- Timestamp:
- 2016-11-17T21:00:49+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r10910 r11272 27 27 private double minLat, minLon, maxLat, maxLon; 28 28 29 /** 30 * Gets the point that has both the minimal lat and lon coordinate 31 * @return The point 32 */ 29 33 public LatLon getMin() { 30 34 return new LatLon(minLat, minLon); … … 51 55 } 52 56 57 /** 58 * Gets the point that has both the maximum lat and lon coordinate 59 * @return The point 60 */ 53 61 public LatLon getMax() { 54 62 return new LatLon(maxLat, maxLon); -
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r11269 r11272 6 6 import java.util.Objects; 7 7 8 import org.openstreetmap.josm.data.Bounds; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.coor.QuadTiling; 10 11 import org.openstreetmap.josm.tools.Utils; 11 12 13 /** 14 * A BBox represents an area in lat/lon space. It is used for the quad tree. 15 * 16 * In contrast to a {@link Bounds} object, a BBox can represent an invalid (empty) area. 17 */ 12 18 public class BBox { 13 19 … … 30 36 */ 31 37 public BBox(final double x, final double y) { 32 if (!Double.isNaN(x) && !Double.isNaN(y)) { 33 xmin = x; 34 ymin = y; 35 xmax = x; 36 ymax = y; 37 } 38 add(x, y); 38 39 } 39 40 … … 69 70 */ 70 71 public BBox(double ax, double ay, double bx, double by) { 71 if (Double.isNaN(ax) || Double.isNaN(ay) || Double.isNaN(bx) || Double.isNaN(by)) { 72 return; // use default which is an invalid BBox 73 } 74 75 if (ax > bx) { 76 xmax = ax; 77 xmin = bx; 78 } else { 79 xmax = bx; 80 xmin = ax; 81 } 82 83 if (ay > by) { 84 ymax = ay; 85 ymin = by; 86 } else { 87 ymax = by; 88 ymin = ay; 89 } 72 if (!(Double.isNaN(ax) || Double.isNaN(ay) || Double.isNaN(bx) || Double.isNaN(by))) { 73 add(ax, ay); 74 add(bx, by); 75 } 76 // otherwise use default which is an invalid BBox 90 77 } 91 78 … … 96 83 */ 97 84 public BBox(Way w) { 98 w.getNodes().forEach( (n)-> add(n.getCoor()));85 w.getNodes().forEach(n -> add(n.getCoor())); 99 86 } 100 87 … … 104 91 */ 105 92 public BBox(Node n) { 106 if (n.isLatLonKnown()) 93 if (n.isLatLonKnown()) { 107 94 add(n.getCoor()); 95 } 108 96 } 109 97 … … 114 102 */ 115 103 public final void add(LatLon c) { 116 if (c != null && c.isValid()) 104 if (c != null && c.isValid()) { 117 105 add(c.lon(), c.lat()); 106 } 118 107 } 119 108 … … 124 113 */ 125 114 public final void add(double x, double y) { 126 if ( Double.isNaN(x) || Double.isNaN(y))127 return;128 xmin = Math.min(xmin, x);129 xmax = Math.max(xmax, x);130 ymin = Math.min(ymin, y);131 ymax = Math.max(ymax, y);115 if (!Double.isNaN(x) && !Double.isNaN(y)) { 116 xmin = Math.min(xmin, x); 117 xmax = Math.max(xmax, x); 118 ymin = Math.min(ymin, y); 119 ymax = Math.max(ymax, y); 120 } 132 121 } 133 122 … … 156 145 } 157 146 147 /** 148 * Gets the height of the bbox. 149 * @return The difference between ymax and ymin. 0 for invalid bboxes. 150 */ 158 151 public double height() { 159 return ymax-ymin; 160 } 161 152 if (isValid()) { 153 return ymax - ymin; 154 } else { 155 return 0; 156 } 157 } 158 159 /** 160 * Gets the width of the bbox. 161 * @return The difference between xmax and xmin. 0 for invalid bboxes. 162 */ 162 163 public double width() { 163 return xmax-xmin; 164 if (isValid()) { 165 return xmax - xmin; 166 } else { 167 return 0; 168 } 164 169 } 165 170 … … 191 196 */ 192 197 public boolean intersects(BBox b) { 193 if (xmin > b.xmax) 194 return false; 195 if (xmax < b.xmin) 196 return false; 197 if (ymin > b.ymax) 198 return false; 199 if (ymax < b.ymin) 200 return false; 201 return true; 198 return xmin <= b.xmax && xmax >= b.xmin 199 && ymin <= b.ymax && ymax >= b.ymin; 202 200 } 203 201 … … 254 252 } 255 253 254 /** 255 * Gets the center of this BBox. 256 * @return The center. 257 */ 256 258 public LatLon getCenter() { 257 259 return new LatLon(ymin + (ymax-ymin)/2.0, xmin + (xmax-xmin)/2.0); … … 298 300 * @return true if the bbox covers a part of the planets surface 299 301 * Height and width must be non-negative, but may (both) be 0. 302 * @since 11269 300 303 */ 301 304 public boolean isValid() { 302 return (xmin <= xmax && ymin <= ymax); 303 } 304 305 /** 306 * @return true if the bbox covers a part of the planets surface 305 return xmin <= xmax && ymin <= ymax; 306 } 307 308 /** 309 * @return true if the bbox is avalid and covers a part of the planets surface 310 * @since 11269 307 311 */ 308 312 public boolean isInWorld() { 309 return !(xmin < -180.0 || xmax > 180.0 || ymin < -90.0 || ymax > 90.0);313 return isValid() && xmin >= -180.0 && xmax <= 180.0 && ymin >= -90.0 && ymax <= 90.0; 310 314 } 311 315 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r11269 r11272 1422 1422 * @param box a bbox instance 1423 1423 * @param visited a set of visited members or null 1424 * @since 11269 1424 1425 */ 1425 1426 protected abstract void addToBBox(BBox box, Set<PrimitiveId> visited); -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r11269 r11272 314 314 QBLevel<T>[] children = getChildren(); 315 315 for (int i = 0; i < QuadTiling.TILES_PER_LEVEL; i++) { 316 if (children[i] == findThis) 316 if (children[i] == findThis) { 317 317 return i; 318 } 318 319 } 319 320 return -1; … … 344 345 345 346 boolean canRemove() { 346 if (content != null && !content.isEmpty()) 347 return false; 348 if (this.hasChildren()) 349 return false; 350 return true; 347 return (content == null || content.isEmpty()) && !this.hasChildren(); 351 348 } 352 349 } … … 374 371 @Override 375 372 public boolean add(T n) { 376 if (n.getBBox().isValid()) 373 if (n.getBBox().isValid()) { 377 374 root.add(n); 378 else375 } else { 379 376 invalidBBoxPrimitives.add(n); 377 } 380 378 size++; 381 379 return true; … … 388 386 continue; 389 387 } 390 if (!this.remove(o)) 388 if (!this.remove(o)) { 391 389 return false; 390 } 392 391 } 393 392 return true; … … 415 414 public boolean containsAll(Collection<?> objects) { 416 415 for (Object o : objects) { 417 if (!this.contains(o)) 416 if (!this.contains(o)) { 418 417 return false; 418 } 419 419 } 420 420 return true; … … 428 428 QBLevel<T> bucket = root.findBucket(t.getBBox()); 429 429 boolean removed = bucket.removeContent(t); 430 if (!removed) 430 if (!removed) { 431 431 removed = invalidBBoxPrimitives.remove(o); 432 if (removed) 432 } 433 if (removed) { 433 434 size--; 435 } 434 436 return removed; 435 437 } … … 439 441 @SuppressWarnings("unchecked") 440 442 T t = (T) o; 441 if (!t.getBBox().isValid()) 443 if (!t.getBBox().isValid()) { 442 444 return invalidBBoxPrimitives.contains(o); 445 } 443 446 QBLevel<T> bucket = root.findBucket(t.getBBox()); 444 447 return bucket != null && bucket.content != null && bucket.content.contains(t); … … 521 524 @Override 522 525 public T next() { 523 if (fromInvalidBBoxPrimitives) 526 if (fromInvalidBBoxPrimitives) { 524 527 return invalidBBoxIterator.next(); 528 } 525 529 T ret = peek(); 526 530 if (ret == null)
Note:
See TracChangeset
for help on using the changeset viewer.