1 /* 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4724569 27 * @summary Arc2D "contains" and "intersects" problems, part II: fix enclosed. 28 */ 29 30 import java.awt.Shape; 31 import java.awt.geom.Arc2D; 32 import java.awt.geom.Rectangle2D; 33 34 public class Arc2DIntersectsTest { 35 36 static Shape[][] trues = { 37 { 38 new Arc2D.Double(0, 0, 100, 100, -45, 90, Arc2D.PIE), 39 new Rectangle2D.Double(0, 0, 100, 100), 40 }, 41 { 42 new Arc2D.Double(0, 0, 100, 100, -45, 90, Arc2D.PIE), 43 new Rectangle2D.Double(25, 25, 50, 50) 44 }, 45 { 46 new Arc2D.Double(0, 0, 100, 100, -45, 90, Arc2D.PIE), 47 new Rectangle2D.Double(60, 0, 20, 100) 48 }, 49 { 50 new Arc2D.Double(0, 0, 100, 100, -135, 270, Arc2D.CHORD), 51 new Rectangle2D.Double(20, 0, 20, 100) 52 } 53 }; 54 static Shape[][] falses = { 55 { 56 new Arc2D.Double(0, 0, 100, 100, 0, 360, Arc2D.PIE), 57 new Rectangle2D.Double(0, 100, 100, 100) 58 }, 59 { 60 new Arc2D.Double(0, 0, 100, 100, 45, 20, Arc2D.PIE), 61 new Rectangle2D.Double(75, 75, 100, 100) 62 }, 63 { 64 new Arc2D.Double(0, 0, 100, 100, -10, 10, Arc2D.PIE), 65 new Rectangle2D.Double(50, 75, 50, 100) 66 }, 67 { 68 new Arc2D.Double(0, 0, 100, 100, -10, 10, Arc2D.CHORD), 69 new Rectangle2D.Double(60, 0, 10, 100) 70 } 71 }; 72 main(String[] args)73 public static void main(String[] args) { 74 75 for (int i = 0; i < trues.length; i++) { 76 checkPair((Arc2D)trues[i][0], (Rectangle2D)trues[i][1], true); 77 } 78 79 for (int i = 0; i < falses.length; i++) { 80 checkPair((Arc2D)falses[i][0], (Rectangle2D)falses[i][1], false); 81 } 82 } 83 checkPair(Arc2D arc, Rectangle2D rect, boolean expect)84 public static void checkPair(Arc2D arc, Rectangle2D rect, boolean expect) { 85 86 if (arc.intersects(rect) != expect) { 87 String errMsg = "Intersection of Arc(" + 88 arc.getX() + ", " + arc.getY() + ", " + 89 arc.getWidth() + ", " + arc.getHeight() + ", " + 90 "start = " + arc.getAngleStart() + ", " + 91 "extent = " + arc.getAngleExtent() + ", " + 92 typeName(arc.getArcType()) + ") and Rectangle(" + 93 rect.getX() + ", " + rect.getY() + ", " + 94 rect.getWidth() + ", " + rect.getHeight() + ") " + 95 "should be " + expect + ", BUT IT IS NOT."; 96 throw new RuntimeException(errMsg); 97 } 98 } 99 typeName(int type)100 public static String typeName(int type) { 101 102 if (type == Arc2D.OPEN) 103 return "Open"; 104 if (type == Arc2D.CHORD) 105 return "Chord"; 106 if (type == Arc2D.PIE) 107 return "Pie"; 108 return null; 109 } 110 } 111