src/main/java/de/digitalcollections/iiif/model/image/RegionRequest.java
public Rectangle resolve(Dimension imageDims) throws ResolvingException {
    if (square) {
      if (imageDims.width > imageDims.height) {
        return new Rectangle(
            (imageDims.width - imageDims.height) / 2,
            0,
            imageDims.height, imageDims.height);
      } else if (imageDims.height > imageDims.width) {
        return new Rectangle(
            0,
            (imageDims.height - imageDims.width) / 2,
            imageDims.width, imageDims.width);
      }
    }
    if (absoluteBox == null && relativeBox == null) {
      return new Rectangle(0, 0, imageDims.width, imageDims.height);
    }
    Rectangle rect;
    if (isRelative()) {
      rect = new Rectangle(
          (int) Math.round(relativeBox.x.doubleValue() / 100. * imageDims.getWidth()),
          (int) Math.round(relativeBox.y.doubleValue() / 100. * imageDims.getHeight()),
          (int) Math.round(relativeBox.w.doubleValue() / 100. * imageDims.getWidth()),
          (int) Math.round(relativeBox.h.doubleValue() / 100. * imageDims.getHeight()));
    } else {
      rect = absoluteBox;
    }
    if (rect.x >= imageDims.width || rect.y >= imageDims.height) {
      throw new ResolvingException("X and Y must be smaller than the native width/height");
    }
    if (rect.x + rect.width > imageDims.width) {
      rect.width = imageDims.width - rect.x;
    }
    if (rect.y + rect.height > imageDims.height) {
      rect.height = imageDims.height - rect.y;
    }
    return rect;
  }
public Rectangle resolve(Dimension imageDims) throws ResolvingException {
    if (square) {
      if (imageDims.width > imageDims.height) {
        return new Rectangle(
            (imageDims.width - imageDims.height) / 2,
            0,
            imageDims.height, imageDims.height);
      } else if (imageDims.height > imageDims.width) {
        return new Rectangle(
            0,
            (imageDims.height - imageDims.width) / 2,
            imageDims.width, imageDims.width);
      }
    }
    if (absoluteBox == null && relativeBox == null) {
      return new Rectangle(0, 0, imageDims.width, imageDims.height);
    }
    Rectangle rect;
    if (isRelative()) {
      rect = new Rectangle(
          (int) Math.round(relativeBox.x.doubleValue() / 100. * imageDims.getWidth()),
          (int) Math.round(relativeBox.y.doubleValue() / 100. * imageDims.getHeight()),
          (int) Math.round(relativeBox.w.doubleValue() / 100. * imageDims.getWidth()),
          (int) Math.round(relativeBox.h.doubleValue() / 100. * imageDims.getHeight()));
    } else {
      rect = absoluteBox;
    }
    if (rect.x >= imageDims.width || rect.y >= imageDims.height) {
      throw new ResolvingException("X and Y must be smaller than the native width/height");
    }
    if (rect.x + rect.width > imageDims.width) {
      rect.width = imageDims.width - rect.x;
    }
    if (rect.y + rect.height > imageDims.height) {
      rect.height = imageDims.height - rect.y;
    }
    return rect;
  }
Resolve the region request into an actual region that can be used for cropping the image

@param imageDims actual image dimensions
@return Rectangle representing th actual region
@throws de.digitalcollections.iiif.model.image.ResolvingException if rectangle is outside image dimensions