Re: Testing Intersection with A Rectangle(2D) w/No Area
From: Fred L. Kleinschmidt (fred.l.kleinschmidt_at_nospam_boeing.com)
Date: 02/18/04
- Next message: Laird Nelson: "Defaults for JFileChooser?"
- Previous message: ak: "Re: JTable"
- In reply to: Aaron Davies: "Testing Intersection with A Rectangle(2D) w/No Area"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 Feb 2004 17:21:39 GMT
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
- Next message: Laird Nelson: "Defaults for JFileChooser?"
- Previous message: ak: "Re: JTable"
- In reply to: Aaron Davies: "Testing Intersection with A Rectangle(2D) w/No Area"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|