Name: bsC130419 Date: 07/24/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
I resubmit the same bug report (review ID: 127784) against JDK 1.3.1. This bug
also exists for JDK 1.2.2_006, 1.3.0, 1.3.0_02. I tested only on Win2000 for
specified JDK versions. I didn't test for another JDKs as well as for Unix
platforms.
The -Xint or -Xfuture options do not help.
When you will run the application it will print out the message:
General Path intersects Rectangle = true
======================= My original bug report ===============================
The GeneralPath.intersects( Rectangle2D r ) method returns true if:
1. GeneralPath is open shape (polyline).
2. The rectangle lies on the virtual line connecting the first and the last
points of GeneralPath, between first and last point.
In this case (in my opinion) this method should return false because
GeneralPath (polyline) doesn't intersect rectangle.
It seems that algorithm implemented in sun.awt.geom.Crossings.findCrossings
(...) doesn't make difference between open and closed GeneralPath. It works
like if GeneralPath were closed even if it is actually open.
See the source code demonstrating the problem:
============================================================
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
// --------------------------------------------------------
// Test application
// --------------------------------------------------------
public class IntersectTest
extends JFrame {
private GeneralPath _gp;
private Rectangle2D _rect;
// ------------------------------------------------------
// Constructor
// ------------------------------------------------------
public IntersectTest( String title ) {
super( title );
_gp = new GeneralPath();
_gp.moveTo( 200.0F, 200.0F );
_gp.lineTo( 200.0F, 300.0F );
_gp.lineTo( 300.0F, 300.0F );
_gp.lineTo( 300.0F, 200.0F );
_rect = new Rectangle2D.Double( 250.0, 199.0, 3.0, 3.0 );
System.out.println("General Path intersects Rectangle = " + _gp.intersects(
_rect ));
// Attach listener for "X" button
addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
});
}
// ------------------------------------------------------
// Overriden method
// ------------------------------------------------------
public void paint( Graphics g ) {
Graphics2D g2 = (Graphics2D) g;
g2.draw( _gp );
g2.draw( _rect );
}
// ------------------------------------------------------
// Run the application
// ------------------------------------------------------
public static void main( String[] args ) {
IntersectTest app = new IntersectTest("Test Intersection");
app.setSize( 500, 500 );
app.setVisible( true );
}
}
(Review ID: 127967)
======================================================================