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

SwingUtilities.computeIntersection() gets "negative" rectangle

XMLWordPrintable



      Name: akC57697 Date: 03/12/98



      The SwingUtilities.computeIntersection() gets "negative" rectangle as a
      result for rectangles which do not intersect.

      -----------------------Example--------------------
      import java.awt.swing.SwingUtilities;
      import java.awt.Rectangle;
      public class SwingUtilitiesTest {
          public static void main(String s[]) {
          
        Rectangle rec_1 = new Rectangle(0,0,10,10); // Do not intersect
        Rectangle rec_2 = new Rectangle(40,40,10,10);

        if (rec_1.intersects(rec_2)) {
         System.out.println("Could not setup test "+rec_1+"intersects "+rec_2);
         return;
        }

        
        System.out.println("The intersection is: "+
                SwingUtilities.computeIntersection(rec_1.x,
                                            rec_1.y,
                                            rec_1.width,
                                            rec_1.height,
                                            rec_2));
         }
      }
      --------------------------------------------------
      Output:
      The intersection is: java.awt.Rectangle[x=40,y=40,width=-30,height=-30]

      ======================================================================

            jeff Jeff Dinkins
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: