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(); } } }
|