Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8110452

Rectangle.setBounds(Bounds2D bounds) doesn't handle empty bounds correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P2
    • fx1.3.1
    • fx1.3
    • javafx
    • None

    Description

      The functions intersectWith(...) in com.sun.javafx.geom.Bounds2D don't work for cases where the to Bounds rectangles do not intersect. Compare the code:

          public void intersectWith(float x1, float y1, float x2, float y2) {
              this.x1 = Math.max(this.x1, x1);
              this.y1 = Math.max(this.y1, y1);
              this.x2 = Math.min(this.x2, x2);
              this.y2 = Math.min(this.y2, y2);
          }

      With what AWT does and you can see there are cases missed:

          public Rectangle intersection(Rectangle r) {
      int tx1 = this.x;
      int ty1 = this.y;
      int rx1 = r.x;
      int ry1 = r.y;
      long tx2 = tx1; tx2 += this.width;
      long ty2 = ty1; ty2 += this.height;
      long rx2 = rx1; rx2 += r.width;
      long ry2 = ry1; ry2 += r.height;
      if (tx1 < rx1) tx1 = rx1;
      if (ty1 < ry1) ty1 = ry1;
      if (tx2 > rx2) tx2 = rx2;
      if (ty2 > ry2) ty2 = ry2;
      tx2 -= tx1;
      ty2 -= ty1;
      // tx2,ty2 will never overflow (they will never be
      // larger than the smallest of the two source w,h)
      // they might underflow, though...
      if (tx2 < Integer.MIN_VALUE) tx2 = Integer.MIN_VALUE;
      if (ty2 < Integer.MIN_VALUE) ty2 = Integer.MIN_VALUE;
      return new Rectangle(tx1, ty1, (int) tx2, (int) ty2);
          }

      Attachments

        Activity

          People

            ckyang Chien Yang (Inactive)
            jasper Jasper Potts (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:

              Time Tracking

                Estimated:
                Original Estimate - 2 days
                2d
                Remaining:
                Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified