diff --git a/src/java/com/threerings/geom/GeomUtil.java b/src/java/com/threerings/geom/GeomUtil.java
index 5b98121be..e21ab412f 100644
--- a/src/java/com/threerings/geom/GeomUtil.java
+++ b/src/java/com/threerings/geom/GeomUtil.java
@@ -1,9 +1,11 @@
//
-// $Id: GeomUtil.java,v 1.2 2002/06/28 01:29:08 mdb Exp $
+// $Id: GeomUtil.java,v 1.3 2002/10/29 06:07:22 mdb Exp $
package com.threerings.geom;
import java.awt.Point;
+import java.awt.Rectangle;
+
import com.samskivert.util.StringUtil;
/**
@@ -112,4 +114,30 @@ public class GeomUtil
// we're on the left hand side and if it's zero, we're on the line
return dot(p1.x, p1.y, p2.x, p2.y, x, y);
}
+
+ /**
+ * Shifts the position of the tainer rectangle to ensure
+ * that it contains the tained rectangle. The
+ * tainer rectangle must be larger than or equal to the
+ * size of the tained rectangle.
+ */
+ public static void shiftToContain (Rectangle tainer, Rectangle tained)
+ {
+ if (tainer.width < tained.width || tainer.height < tained.height) {
+ throw new IllegalArgumentException(
+ tainer + " cannot contain " + tained);
+ }
+ if (tained.x < tainer.x) {
+ tainer.x = tained.x;
+ }
+ if (tained.y < tainer.y) {
+ tainer.y = tained.y;
+ }
+ if (tained.x + tained.width > tainer.x + tainer.width) {
+ tainer.x = tained.x - (tainer.width - tained.width);
+ }
+ if (tained.y + tained.height > tainer.y + tainer.height) {
+ tainer.y = tained.y - (tainer.height - tained.height);
+ }
+ }
}