JDK-4493128 : CubicCurve2D intersects method fails
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-08-17
  • Updated: 2011-02-01
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b128Fixed
Description
The following test case demonstrates a failure with the intersects(Rectangle)
method of CubicCurve2D.  If you plot the shapes you should see that the
rectangle does intersect the interior of the curve.

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.CubicCurve2D;

public class CurveTestBug {
    public static void main(String argv[]) {
	test(new Point(264, 305),
	     new CubicCurve2D.Double(50.0, 300.0,
				     150.0, 166.6666717529297,
				     238.0, 456.66668701171875,
				     350.0, 300.0));
    }

    public static void test(Point point, Shape curve) {
	Rectangle shadow = new Rectangle(point.x-5, point.y-5, 10, 10);
	boolean pointinside = curve.contains(point);
	boolean shadowtouches = curve.intersects(shadow);
	boolean shadowinside = curve.contains(shadow);
        if ((shadowinside && (!pointinside || !shadowtouches)) ||
	    (pointinside && !shadowtouches))
	{
	    System.out.println("Error!");
	    System.out.println("  Point:  "+point);
	    System.out.println("  Shadow: "+shadow);
	    System.out.println("  Curve:  "+stringFor(curve));
	    System.out.println("    shadowinside:  "+shadowinside);
	    System.out.println("    pointinside:   "+pointinside);
	    System.out.println("    shadowtouches: "+shadowtouches);
	    throw new RuntimeException("intersection/containment violation");
	}
    }

    public static String stringFor(Shape s) {
	if (s instanceof CubicCurve2D) {
	    CubicCurve2D curve = (CubicCurve2D) s;
	    return ("CubicCurve("+
		    curve.getX1()+", "+curve.getY1()+", "+
		    curve.getCtrlX1()+", "+curve.getCtrlY1()+", "+
		    curve.getCtrlX2()+", "+curve.getCtrlY2()+", "+
		    curve.getX2()+", "+curve.getY2()+")");
	} else {
	    return s.toString();
	}
    }
}

Comments
EVALUATION Fixed in JDK 7 : Changeset: c8a10bfd2fcb Author: dlila Date: 2011-01-19 11:31 -0500 URL: http://hg.openjdk.java.net/jdk7/2d/jdk/rev/c8a10bfd2fcb 4493128: CubicCurve2D intersects method fails Summary: Now using subdivision code in sun.awt.geom.Curve. Reviewed-by: flar ! src/share/classes/java/awt/geom/CubicCurve2D.java
01-02-2011