private void adjustRight(
      RectF rect,
      float right,
      RectF bounds,
      int viewWidth,
      float snapMargin,
      float aspectRatio,
      boolean topMoves,
      boolean bottomMoves) {

    float newRight = right;

    if (newRight > viewWidth) {
      newRight = viewWidth + (newRight - viewWidth) / 1.05f;
      mTouchOffset.x -= (newRight - viewWidth) / 1.1f;
    }

    if (newRight > bounds.right) {
      mTouchOffset.x -= (newRight - bounds.right) / 2f;
    }

    // If close to the edge
    if (bounds.right - newRight < snapMargin) {
      newRight = bounds.right;
    }

    // Checks if the window is too small horizontally
    if (newRight - rect.left < mMinCropWidth) {
      newRight = rect.left + mMinCropWidth;
    }

    // Checks if the window is too large horizontally
    if (newRight - rect.left > mMaxCropWidth) {
      newRight = rect.left + mMaxCropWidth;
    }

    // If close to the edge
    if (bounds.right - newRight < snapMargin) {
      newRight = bounds.right;
    }

    // check vertical bounds if aspect ratio is in play
    if (aspectRatio > 0) {
      float newHeight = (newRight - rect.left) / aspectRatio;

      // Checks if the window is too small vertically
      if (newHeight < mMinCropHeight) {
        newRight = Math.min(bounds.right, rect.left + mMinCropHeight * aspectRatio);
        newHeight = (newRight - rect.left) / aspectRatio;
      }

      // Checks if the window is too large vertically
      if (newHeight > mMaxCropHeight) {
        newRight = Math.min(bounds.right, rect.left + mMaxCropHeight * aspectRatio);
        newHeight = (newRight - rect.left) / aspectRatio;
      }

      // if top AND bottom edge moves by aspect ratio check that it is within full height bounds
      if (topMoves && bottomMoves) {
        newRight =
            Math.min(newRight, Math.min(bounds.right, rect.left + bounds.height() * aspectRatio));
      } else {
        // if top edge moves by aspect ratio check that it is within bounds
        if (topMoves && rect.bottom - newHeight < bounds.top) {
          newRight = Math.min(bounds.right, rect.left + (rect.bottom - bounds.top) * aspectRatio);
          newHeight = (newRight - rect.left) / aspectRatio;
        }

        // if bottom edge moves by aspect ratio check that it is within bounds
        if (bottomMoves && rect.top + newHeight > bounds.bottom) {
          newRight =
              Math.min(
                  newRight,
                  Math.min(bounds.right, rect.left + (bounds.bottom - rect.top) * aspectRatio));
        }
      }
    }

    rect.right = newRight;
  }
Get the resulting x-position of the right edge of the crop window given the handle's position
and the image's bounding box and snap radius.

@param right the position that the right edge is dragged to
@param bounds the bounding box of the image that is being cropped
@param viewWidth
@param snapMargin the snap distance to the image edge (in pixels)
core/src/main/java/com/theartofdev/edmodo/cropper/CropWindowMoveHandler.java