code: public int calculatePointOffsetDistance(Point point) {
          int right = left + width;
          int bottom = top + height;
          int pointLeft = point.getLeft();
          int pointTop = point.getTop();
  
          if (contains(point)) {
              return max(top - pointTop, pointTop - bottom, left - pointLeft, pointLeft - right);
          } else if (isQuadrant1(point)) {
              return max(abs(left - pointLeft), abs(top - pointTop));
          } else if (isQuadrant2(point)) {
              return abs(top - pointTop);
          } else if (isQuadrant3(point)) {
              return max(abs(pointLeft - right), abs(top - pointTop));
          } else if (isQuadrant4(point)) {
              return abs(pointLeft - right);
          } else if (isQuadrant5(point)) {
              return max(abs(pointLeft - right), abs(pointTop - bottom));
          } else if (isQuadrant6(point)) {
              return abs(pointTop - bottom);
          } else if (isQuadrant7(point)) {
              return max(abs(left - pointLeft), abs(pointTop - bottom));
          } else {
              return abs(left - pointLeft);
          }
      }
docs: Calculates the distance of given point to one of the rect edges.
  If the point is located inside the return result will be negative.
  If the point is located on edge the result will be zero
  If the point is located outside of the rect - it will return positive value
  @param point
  @return