/** Moves ths given inner rectangle such that it lies within the given outer rectangle. * The results are undefined if either the inner width or height is greater that the outer's * width or height, respectively. */ protected static Rectangle confine (IRectangle outer, Rectangle inner) { float dx = outer.x() - inner.x(), dy = outer.y() - inner.y(); if (dx <= 0) dx = Math.min(0, outer.maxX() - inner.maxX()); if (dy <= 0) dy = Math.min(0, outer.maxY() - inner.maxY()); inner.translate(dx, dy); return inner; }