/** * Unions the supplied two rectangles, writing the result into {@code dst}. */ public static void union (IRectangle src1, IRectangle src2, Rectangle dst) { float x1 = Math.min(src1.minX(), src2.minX()); float y1 = Math.min(src1.minY(), src2.minY()); float x2 = Math.max(src1.maxX(), src2.maxX()); float y2 = Math.max(src1.maxY(), src2.maxY()); dst.setBounds(x1, y1, x2 - x1, y2 - y1); }
/** * Unions the supplied two rectangles, writing the result into {@code dst}. */ public static void union (IRectangle src1, IRectangle src2, Rectangle dst) { float x1 = Math.min(src1.minX(), src2.minX()); float y1 = Math.min(src1.minY(), src2.minY()); float x2 = Math.max(src1.maxX(), src2.maxX()); float y2 = Math.max(src1.maxY(), src2.maxY()); dst.setBounds(x1, y1, x2 - x1, y2 - y1); }
/** * Intersects the supplied two rectangles, writing the result into {@code dst}. */ public static void intersect (IRectangle src1, IRectangle src2, Rectangle dst) { float x1 = Math.max(src1.minX(), src2.minX()); float y1 = Math.max(src1.minY(), src2.minY()); float x2 = Math.min(src1.maxX(), src2.maxX()); float y2 = Math.min(src1.maxY(), src2.maxY()); dst.setBounds(x1, y1, x2 - x1, y2 - y1); }
/** * Intersects the supplied two rectangles, writing the result into {@code dst}. */ public static void intersect (IRectangle src1, IRectangle src2, Rectangle dst) { float x1 = Math.max(src1.minX(), src2.minX()); float y1 = Math.max(src1.minY(), src2.minY()); float x2 = Math.min(src1.maxX(), src2.maxX()); float y2 = Math.min(src1.maxY(), src2.maxY()); dst.setBounds(x1, y1, x2 - x1, y2 - y1); }
/** * Computes the point inside the bounds of the rectangle that's closest to the given point, * writing the result into {@code out}. * @return {@code out} for call chaining convenience. */ public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) { out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()), MathUtil.clamp(p.y(), r.minY(), r.maxY())); return out; }
/** * Computes the point inside the bounds of the rectangle that's closest to the given point, * writing the result into {@code out}. * @return {@code out} for call chaining convenience. */ public static Point closestInteriorPoint (IRectangle r, IPoint p, Point out) { out.set(MathUtil.clamp(p.x(), r.minX(), r.maxX()), MathUtil.clamp(p.y(), r.minY(), r.maxY())); return out; }