United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4493128 CubicCurve2D intersects method fails
JDK-4493128 : CubicCurve2D intersects method fails

Details
Type:
Bug
Submit Date:
2001-08-17
Status:
Closed
Updated Date:
2011-02-01
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
generic
Sub-Component:
2d
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.2
Fixed Versions:

Related Reports

Sub Tasks

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
                                     
2011-02-01



Hardware and Software, Engineered to Work Together