- Timestamp:
- 2021-04-12T00:16:06+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/BBox.java
r17703 r17752 148 148 public final void add(double x, double y) { 149 149 if (!Double.isNaN(x) && !Double.isNaN(y)) { 150 xmin = Math.min(xmin, x); 151 xmax = Math.max(xmax, x); 152 ymin = Math.min(ymin, y); 153 ymax = Math.max(ymax, y); 150 set(Math.min(xmin, x), Math.max(xmax, x), Math.min(ymin, y), Math.max(ymax, y)); 154 151 } 155 152 } … … 161 158 public final void add(BBox other) { 162 159 if (other.isValid()) { 163 xmin = Math.min(xmin, other.xmin); 164 xmax = Math.max(xmax, other.xmax); 165 ymin = Math.min(ymin, other.ymin); 166 ymax = Math.max(ymax, other.ymax); 167 } 160 set(Math.min(xmin, other.xmin), Math.max(xmax, other.xmax), Math.min(ymin, other.ymin), Math.max(ymax, other.ymax)); 161 } 162 } 163 164 protected void set(double xmin, double xmax, double ymin, double ymax) { 165 this.xmin = xmin; 166 this.xmax = xmax; 167 this.ymin = ymin; 168 this.ymax = ymax; 168 169 } 169 170 … … 371 372 372 373 @Override 373 public int hashCode() { 374 public final int hashCode() { 374 375 return Objects.hash(xmin, xmax, ymin, ymax); 375 376 } 376 377 377 378 @Override 378 public boolean equals(Object o) { 379 public final boolean equals(Object o) { 379 380 if (this == o) return true; 380 if ( o == null || getClass() != o.getClass()) return false;381 if (!(o instanceof BBox)) return false; 381 382 BBox b = (BBox) o; 382 383 return Double.compare(b.xmax, xmax) == 0 && Double.compare(b.ymax, ymax) == 0 … … 451 452 LatLon.cDdFormatter.format(ymax)); 452 453 } 454 455 /** 456 * Returns an immutable version of this bbox, i.e., modifying calls throw an {@link UnsupportedOperationException}. 457 * @return an immutable version of this bbox 458 */ 459 BBox toImmutable() { 460 return new Immutable(this); 461 } 462 463 private static class Immutable extends BBox { 464 465 Immutable(BBox copy) { 466 super(copy); 467 } 468 469 @Override 470 protected void set(double xmin, double xmax, double ymin, double ymax) { 471 throw new UnsupportedOperationException(); 472 } 473 474 @Override 475 BBox toImmutable() { 476 return this; 477 } 478 } 453 479 } -
trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
r17749 r17752 466 466 /** 467 467 * Fetches the bounding box of the primitive. 468 * Since 17752, the returned bounding box might be immutable, i.e., modifying calls throw an {@link UnsupportedOperationException}. 468 469 * @return Bounding box of the object 469 470 * @since 13764 -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r17357 r17752 441 441 @Override 442 442 public BBox getBBox() { 443 if (getDataSet() != null && bbox != null) 444 return new BBox(bbox); // use cached value 443 if (getDataSet() != null && bbox != null) { 444 return this.bbox; // use cached immutable value 445 } 445 446 446 447 BBox box = new BBox(); 447 448 addToBBox(box, new HashSet<PrimitiveId>()); 448 if (getDataSet() != null) 449 setBBox(box); // set cache 450 return new BBox(box); 449 if (getDataSet() == null) { 450 return box; 451 } 452 setBBox(box); // set cached immutable value 453 return this.bbox; 451 454 } 452 455 453 456 private void setBBox(BBox bbox) { 454 this.bbox = bbox; 457 this.bbox = bbox == null ? null : bbox.toImmutable(); 455 458 } 456 459 -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r17357 r17752 586 586 return new BBox(this); 587 587 if (bbox == null) { 588 bbox =new BBox(this);589 } 590 return new BBox(bbox);588 setBBox(new BBox(this)); 589 } 590 return bbox; 591 591 } 592 592 … … 596 596 } 597 597 598 private void setBBox(BBox bbox) { 599 this.bbox = bbox == null ? null : bbox.toImmutable(); 600 } 601 598 602 @Override 599 603 public void updatePosition() { 600 bbox =new BBox(this);604 setBBox(new BBox(this)); 601 605 clearCachedStyle(); 602 606 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadTextComponentValidator.java
r17238 r17752 154 154 this.area = primitives.stream() 155 155 .map(IPrimitive::getBBox) 156 .reduce((b1, b2) -> { 156 .reduce(new BBox(), (b1, b2) -> { 157 157 b1.add(b2); 158 158 return b1; 159 }).map(BBox::area) 160 .orElse(Double.NaN); 159 }).area(); 161 160 validate(); 162 161 }
Note:
See TracChangeset
for help on using the changeset viewer.