@Override
  public BaseBounds deriveWithNewBoundsAndSort(
      float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
    if ((minZ == 0) && (maxZ == 0)) {
      setBoundsAndSort(minX, minY, minZ, maxX, maxY, maxZ);
      return this;
    }

    BaseBounds bb = new BoxBounds();
    bb.setBoundsAndSort(minX, minY, minZ, maxX, maxY, maxZ);
    return bb;
  }
  @Override
  public void intersectWith(BaseBounds other) {
    // Short circuit intersect if either bounds is empty.
    if (this.isEmpty()) return;
    if (other.isEmpty()) {
      makeEmpty();
      return;
    }

    minX = Math.max(minX, other.getMinX());
    minY = Math.max(minY, other.getMinY());
    maxX = Math.min(maxX, other.getMaxX());
    maxY = Math.min(maxY, other.getMaxY());
  }
 @Override
 public BaseBounds deriveWithUnion(BaseBounds other) {
   if (other.getBoundsType() == BoundsType.RECTANGLE) {
     RectBounds rb = (RectBounds) other;
     unionWith(rb);
   } else if (other.getBoundsType() == BoundsType.BOX) {
     BoxBounds bb = new BoxBounds((BoxBounds) other);
     bb.unionWith(this);
     return bb;
   } else {
     throw new UnsupportedOperationException("Unknown BoundsType");
   }
   return this;
 }
 @Override
 public BaseBounds deriveWithNewBounds(BaseBounds other) {
   if (other.isEmpty()) return makeEmpty();
   if (other.getBoundsType() == BoundsType.RECTANGLE) {
     RectBounds rb = (RectBounds) other;
     minX = rb.getMinX();
     minY = rb.getMinY();
     maxX = rb.getMaxX();
     maxY = rb.getMaxY();
   } else if (other.getBoundsType() == BoundsType.BOX) {
     return new BoxBounds((BoxBounds) other);
   } else {
     throw new UnsupportedOperationException("Unknown BoundsType");
   }
   return this;
 }
 public boolean intersects(BaseBounds other) {
   if ((other == null) || other.isEmpty() || isEmpty()) {
     return false;
   }
   return (other.getMaxX() >= minX
       && other.getMaxY() >= minY
       && other.getMaxZ() >= getMinZ()
       && other.getMinX() <= maxX
       && other.getMinY() <= maxY
       && other.getMinZ() <= getMaxZ());
 }