< prev index next >
src/java.desktop/share/classes/sun/java2d/pipe/Region.java
Print this page
@@ -26,10 +26,11 @@
package sun.java2d.pipe;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import sun.java2d.loops.TransformHelper;
/**
@@ -116,10 +117,30 @@
}
return newv;
}
/**
+ * Returns the smallest (closest to negative infinity)
+ * {@code int} value that is greater than or equal to the
+ * passed coordinate and is equal to a mathematical integer.
+ * If the answer would be greater than {@code Integer.MAX_VALUE}
+ * then {@code Integer.MAX_VALUE} is returned.
+ * If the answer would be less than {@code Integer.MIN_VALUE}
+ * then {@code Integer.MIN_VALUE} is returned.
+ */
+ public static int clipRound(final double coordinate) {
+ final double newv = coordinate - 0.5;
+ if (newv > coordinate || newv < Integer.MIN_VALUE) {
+ return Integer.MIN_VALUE;
+ }
+ if (newv > Integer.MAX_VALUE) {
+ return Integer.MAX_VALUE;
+ }
+ return (int) Math.ceil(newv);
+ }
+
+ /**
* Multiply the scale factor {@code sv} and the value {@code v} with
* appropriate clipping to the bounds of Integer resolution. If the answer
* would be greater than {@code Integer.MAX_VALUE} then {@code
* Integer.MAX_VALUE} is returned. If the answer would be less than {@code
* Integer.MIN_VALUE} then {@code Integer.MIN_VALUE} is returned. Otherwise
@@ -557,10 +578,31 @@
return getIntersectionXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
}
/**
* Returns a Region object that represents the intersection of
+ * this object with the specified Rectangle2D. The return value
+ * may be this same object if no clipping occurs.
+ */
+ public Region getIntersection(Rectangle2D r) {
+ return getIntersectionXYXY(r.getMinX(), r.getMinY(), r.getMaxX(),
+ r.getMaxY());
+ }
+
+ /**
+ * Returns a Region object that represents the intersection of
+ * this object with the specified rectangular area. The return
+ * value may be this same object if no clipping occurs.
+ */
+ public Region getIntersectionXYXY(double lox, double loy, double hix,
+ double hiy) {
+ return getIntersectionXYXY(clipRound(lox), clipRound(loy),
+ clipRound(hix), clipRound(hiy));
+ }
+
+ /**
+ * Returns a Region object that represents the intersection of
* this object with the specified rectangular area. The return
* value may be this same object if no clipping occurs.
*/
public Region getIntersectionXYXY(int lox, int loy, int hix, int hiy) {
if (isInsideXYXY(lox, loy, hix, hiy)) {
< prev index next >