Resizes this bounding box to represent the intersection of this and the given bounding box. @param other the other bounding box @return this bounding box (now representing the intersection) @throws IllegalArgumentException if the bounding boxes don't overlap
(@NotNull BoundingBox other)
| 645 | * @throws IllegalArgumentException if the bounding boxes don't overlap |
| 646 | */ |
| 647 | @NotNull |
| 648 | public BoundingBox intersection(@NotNull BoundingBox other) { |
| 649 | Validate.notNull(other, "Other bounding box is null!"); |
| 650 | Validate.isTrue(this.overlaps(other), "The bounding boxes do not overlap!"); |
| 651 | double newMinX = Math.max(this.minX, other.minX); |
| 652 | double newMinY = Math.max(this.minY, other.minY); |
| 653 | double newMinZ = Math.max(this.minZ, other.minZ); |
| 654 | double newMaxX = Math.min(this.maxX, other.maxX); |
| 655 | double newMaxY = Math.min(this.maxY, other.maxY); |
| 656 | double newMaxZ = Math.min(this.maxZ, other.maxZ); |
| 657 | return this.resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Shifts this bounding box by the given amounts. |
no test coverage detected