+
+ private static class UndefinedRectangle extends Rectangle2D {
+
+ @Override
+ public void setRect(double x, double y, double w, double h) {
+ throw new UnsupportedOperationException("UndefinedRectangle is immutable");
+ }
+
+ @Override
+ public int outcode(double x, double y) {
+ return OUT_LEFT | OUT_TOP | OUT_RIGHT | OUT_BOTTOM;
+ }
+
+ private Rectangle2D copy(Rectangle2D r) {
+ Rectangle2D dest;
+ if (r instanceof Float) {
+ dest = new Rectangle2D.Float();
+ } else {
+ dest = new Rectangle2D.Double();
+ }
+ dest.setFrame(r);
+ return dest;
+ }
+
+ @Override
+ public Rectangle2D createIntersection(Rectangle2D r) {
+ return copy(r);
+ }
+
+ @Override
+ public Rectangle2D createUnion(Rectangle2D r) {
+ return copy(r);
+ }
+
+ @Override
+ public double getX() {
+ return java.lang.Double.NaN;
+ }
+
+ @Override
+ public double getY() {
+ return java.lang.Double.NaN;
+ }
+
+ @Override
+ public double getWidth() {
+ return 0;
+ }
+
+ @Override
+ public double getHeight() {
+ return 0;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return true;
+ }
+
+ }
+
+ private static final UndefinedRectangle UNDEFINED_RECTANGLE = new UndefinedRectangle();
+
+ public static Rectangle2D undefinedRectangle() {
+ return UNDEFINED_RECTANGLE;
+ }
+
+ public static boolean isUndefinedRectangle(Rectangle2D r) {
+ return r == UNDEFINED_RECTANGLE || (r.isEmpty() && Double.isNaN(r.getX()) && Double.isNaN(r.getY()));
+ }
+