Pads or crops a rectangle as necessary to achieve the target dimensions,
	ensuring the modified rectangle falls within the specified bounds.
	
	The input rectangle, bounds, and return value are all a tuple of (x,y,w,h).
358304
def fitToSize(rect, targetWidth, targetHeight, bounds):
	
	
	# Determine the difference between the current size and target size
	x,y,w,h = rect
	diffX = w - targetWidth
	diffY = h - targetHeight
	
	# Determine if we are cropping or padding the width
	if diffX > 0:
		cropLeft  = math.floor(diffX / 2)
		cropRight = diffX - cropLeft
		x,y,w,h   = cropRect((x,y,w,h), 0, 0, cropLeft, cropRight)
	elif diffX < 0:
		padLeft  = math.floor(abs(diffX) / 2)
		padRight = abs(diffX) - padLeft
		x,y,w,h  = padRect((x,y,w,h), 0, 0, padLeft, padRight, bounds, False)
	
	# Determine if we are cropping or padding the height
	if diffY > 0:
		cropTop    = math.floor(diffY / 2)
		cropBottom = diffY - cropTop
		x,y,w,h    = cropRect((x,y,w,h), cropTop, cropBottom, 0, 0)
	elif diffY < 0:
		padTop    = math.floor(abs(diffY) / 2)
		padBottom = abs(diffY) - padTop
		x,y,w,h   = padRect((x,y,w,h), padTop, padBottom, 0, 0, bounds, False)
	
	return (x,y,w,h)
236819
def crop_keypoint_by_coords(keypoint, crop_coords, crop_height, crop_width, rows, cols):
    
    x, y, a, s = keypoint
    x1, y1, x2, y2 = crop_coords
    cropped_keypoint = [x - x1, y - y1, a, s]
    return cropped_keypoint
692242
@Pure
	public Rectangle2d toRectangle2d() {
		final Rectangle2d bounds = new Rectangle2d();
		bounds.setFromCorners(this.minx, this.miny, this.maxx, this.maxy);
		return bounds;
	}
591859
def _infer_shape(self, dimensions):
    
    # Size of input
    n = np.prod(dimensions)
    # Size of output where defined
    m = np.prod(abs(np.array(self._shape)))
    # Replace wildcard
    v = np.array(self._shape)
    v[v == -1] = n // m
    return tuple(v)
1219586
function(bounds, x, y)
	{
		return (bounds.x <= x && bounds.x + bounds.width >= x &&
				bounds.y <= y && bounds.y + bounds.height >= y);
	}
794002
def crop_sizes(cls, original_width, original_height, target_width, target_height):
        
        if target_width < original_width:
            left = abs(original_width - target_width) / 2
            right = left + target_width
        else:
            left = 0
            right = original_width
        if target_height < original_height:
            upper = abs(original_height - target_height) / 2
            lower = upper + target_height
        else:
            upper = 0
            lower = original_height

        return left, upper, right, lower
332708
public void ensureSurrounds(CmsPositionBean child, int padding) {

        // increase the size of the outer rectangle
        if ((getLeft() + padding) > child.getLeft()) {
            int diff = getLeft() - child.getLeft();
            // ensure padding
            diff += padding;
            setLeft(getLeft() - diff);
            setWidth(getWidth() + diff);
        }
        if ((getTop() + padding) > child.getTop()) {
            int diff = getTop() - child.getTop();
            diff += padding;
            setTop(getTop() - diff);
            setHeight(getHeight() + diff);
        }
        if ((getLeft() + getWidth()) < (child.getLeft() + child.getWidth() + padding)) {
            int diff = (child.getLeft() + child.getWidth()) - (getLeft() + getWidth());
            diff += padding;
            setWidth(getWidth() + diff);
        }
        if ((getTop() + getHeight()) < (child.getTop() + child.getHeight() + padding)) {
            int diff = (child.getTop() + child.getHeight()) - (getTop() + getHeight());
            diff += padding;
            setHeight(getHeight() + diff);
        }
    }
973165
@Override
	@Pure
	public Iterator<E> iterator(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds) {
		return new BoundedElementIterator<>(bounds, iterator());
	}
482034
def set_kernel_parameter_and_add_padding(node, kp,
                                         pad_mode, pad_val,
                                         base_name, func_counter):
    
    dims = []
    strides = []
    pads = []
    kernel = []
    for attr in node.attribute:
        if attr.name == "strides":
            if attr.type != AttributeProto.INTS:
                raise ValueError("Only INTS are supported for strides in {}"
                                 .format(node.op_type))
            strides.extend(attr.ints)
            dims.append(len(strides))
        elif attr.name == "pads":
            if attr.type != AttributeProto.INTS:
                raise ValueError("Only INTS are supported for pads in {}"
                                 .format(node.op_type))
            pads.extend(attr.ints)
            dims.append(len(pads))
        elif attr.name == "kernel_shape":
            if attr.type != AttributeProto.INTS:
                raise ValueError("Only INTS are supported for kernel_shape in {}"
                                 .format(node.op_type))
            kernel.extend(attr.ints)
            dims.append(len(kernel))
        elif attr.name == "count_include_pad":
            if attr.type != AttributeProto.INT:
                raise ValueError("Only INT is supported for count_include_pad in {} op_type"
                                 .format(node.op_type))
            kp.including_pad = bool(attr.i)
        else:
            raise ValueError("Unsupported attribute {} was specified at {}"
                             .format(attr.name, node.op_type))
    # NNabla requires for the dimensions of strides, pads, kernels to match.
    # We align the dimensions for all three attributes to the shortest one.
    dim = min(dims)
    padf = None
    if strides:
        kp.stride.dim.extend(strides[:])
    if pads:
        padval = []
        asymmetry = check_padding(pads, dim, padval)
        if asymmetry:
            # Add a separate padding function for
            # asymmetry padding
            input = node.input[0]
            padded = input+"_pad"
            pad_width = rearrange_pads(pads)
            padf = generate_pad(node.name, input, padded,
                                pad_mode, pad_width, pad_val,
                                base_name, func_counter)
        kp.pad.dim.extend(padval)
    else:
        # In case we don't have padding set,
        # we set zero padding just in case NNabla does not set the
        # default padding values correctly (such as in AveragePooling).
        # This code should not be needed
        # if NNabla handles default values correctly.
        kp.pad.dim.extend([0]*dim)
    if kernel:
        kp.kernel.dim.extend(kernel[:])
    return padf
640118
def _get_crop_target(target_px:Union[int,TensorImageSize], mult:int=None)->Tuple[int,int]:
    ""
    target_r,target_c = tis2hw(target_px)
    return _round_multiple(target_r,mult),_round_multiple(target_c,mult)
1131158
function pad(str, width) {
  var len = Math.max(0, width - str.length);
  return str + Array(len + 1).join(' ');
}
578273
public final void setRect(double xMin, double xMax, double yMin, double yMax)
    {
        setRect(new Rectangle2D.Double(xMin, yMin, xMax-xMin, yMax-yMin));
    }
214845
public void rectangle(float x, float y, float w, float h) {
        content.append(x).append(' ').append(y).append(' ').append(w).append(' ').append(h).append(" re").append_i(separator);
    }
117485
function(rectangle, position, direction, up) {
  if (!defined(rectangle)) {
    throw new DeveloperError("rectangle is required.");
  }
  if (defined(position) || defined(direction) || defined(up)) {
    if (!defined(position) || !defined(direction) || !defined(up)) {
      throw new DeveloperError(
        "If any of position, direction, or up are specified, all must be specified."
      );
    }
  }

  this._rectangle = rectangle;
  this._position = position;
  this._direction = direction;
  this._up = up;
}
1014227
def bound(val)
    case val
    when Rectangle then
      r = val.clone
      r.size = r.size.min(size)
      r.loc = r.loc.bound(loc, loc + size - val.size)
      r
    when Point then (val-loc).bound(point, size) + loc
    else raise ArgumentError.new("wrong type: (#{val.class}) - Rectangle or Point expected")
    end
  end
770649
def _conv_shape_tuple(self, lhs_shape, rhs_shape, strides, pads):
    """"""
    if isinstance(pads, str):
      pads = padtype_to_pads(lhs_shape[2:], rhs_shape[2:], strides, pads)
    if len(pads) != len(lhs_shape) - 2:
      msg = 'Wrong number of explicit pads for conv: expected {}, got {}.'
      raise TypeError(msg.format(len(lhs_shape) - 2, len(pads)))
    lhs_padded = onp.add(lhs_shape[2:], onp.add(*zip(*pads)))
    out_space = onp.floor_divide(
        onp.subtract(lhs_padded, rhs_shape[2:]), strides) + 1
    out_space = onp.maximum(0, out_space)
    out_shape = (lhs_shape[0], rhs_shape[0]) + tuple(out_space)
    return tuple(out_shape)
284120
public void set(Rectangle rectangle) {
        set(rectangle.getX(), rectangle.getY(), rectangle.getWidth(), rectangle.getHeight());
    }