Testing Intersection with A Rectangle(2D) w/No Area

  • Follow


How do I test a rectangle for intersection with another rectangle which has
no area, ie where the y1 and y2 co-ords are the same? All the intersect
methods from awt.geom.Rectangle2D.* and awt.geom.Area seem to test for
intersection with the interior of the rectangle, but that always returns
false for a degenerate rect which is equivalent to a line. Do I have to
create that equivalent line and test intersectsLine, or is there a better
way?


0
Reply Aaron 2/18/2004 3:14:03 PM


Aaron Davies wrote:
> 
> How do I test a rectangle for intersection with another rectangle which has
> no area, ie where the y1 and y2 co-ords are the same? All the intersect
> methods from awt.geom.Rectangle2D.* and awt.geom.Area seem to test for
> intersection with the interior of the rectangle, but that always returns
> false for a degenerate rect which is equivalent to a line. Do I have to
> create that equivalent line and test intersectsLine, or is there a better
> way?

      Rectangle r = new Rectangle( 1,0,10,10);
      Rectangle s = new Rectangle( 0, 5, 11, 0);
      if ( r.intersects(s) ) {
         System.out.println( "r intersects s");
      }
      if ( s.intersects(r) ) {
         System.out.println( "s intersects r");
      }
      Rectangle q = r.intersection(s);
      System.out.println( "intersection: "+q);

When this is executed, it verifies that r and s intersect, regardless of
whether you use r.intersects(s) or s.intersects(r). And s is a
degenerate rectangle with no height. Are you sure your rectangles
actually intersect?
-- 
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94  (206)544-5225
0
Reply Fred 2/18/2004 5:21:39 PM


1 Replies
402 Views

(page loaded in 0.053 seconds)

Similiar Articles:









7/24/2012 11:06:47 AM


Reply: