|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2026, 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 4197755 |
| 27 | + * @summary Verifies that Arc2D.getBounds() is similar to Arc2D.getBounds2D() |
| 28 | + */ |
| 29 | + |
| 30 | +import java.awt.geom.Arc2D; |
| 31 | +import java.awt.geom.Point2D; |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.List; |
| 34 | + |
| 35 | +public class Arc2DGetBoundsTest { |
| 36 | + public static void main(String[] args) { |
| 37 | + // Imagine a circle that represents a compass. |
| 38 | + // This arc represents the northern / top quarter. |
| 39 | + Arc2D arc = new Arc2D.Double(0, 0, 1000, 1000, 45, 90, Arc2D.PIE); |
| 40 | + |
| 41 | + // Create 8 pie slices, and place a dot in the center of each |
| 42 | + List<Point2D> samples = new ArrayList<>(); |
| 43 | + for (int segment = 0; segment < 8; segment++) { |
| 44 | + double theta = -(segment + .5) / 8.0 * 2 * Math.PI; |
| 45 | + Point2D p = new Point2D.Double( |
| 46 | + 500 + 100 * Math.cos(theta), |
| 47 | + 500 + 100 * Math.sin(theta) |
| 48 | + ); |
| 49 | + samples.add(p); |
| 50 | + } |
| 51 | + |
| 52 | + // these assertions have never been known to fail: |
| 53 | + assertTrue(!arc.contains(samples.get(0))); |
| 54 | + assertTrue(arc.contains(samples.get(1))); |
| 55 | + assertTrue(arc.contains(samples.get(2))); |
| 56 | + assertTrue(!arc.contains(samples.get(3))); |
| 57 | + assertTrue(!arc.contains(samples.get(4))); |
| 58 | + assertTrue(!arc.contains(samples.get(5))); |
| 59 | + assertTrue(!arc.contains(samples.get(6))); |
| 60 | + assertTrue(!arc.contains(samples.get(7))); |
| 61 | + |
| 62 | + assertTrue(arc.getBounds2D().contains(samples.get(0))); |
| 63 | + assertTrue(arc.getBounds2D().contains(samples.get(1))); |
| 64 | + assertTrue(arc.getBounds2D().contains(samples.get(2))); |
| 65 | + assertTrue(arc.getBounds2D().contains(samples.get(3))); |
| 66 | + assertTrue(!arc.getBounds2D().contains(samples.get(4))); |
| 67 | + assertTrue(!arc.getBounds2D().contains(samples.get(5))); |
| 68 | + assertTrue(!arc.getBounds2D().contains(samples.get(6))); |
| 69 | + assertTrue(!arc.getBounds2D().contains(samples.get(7))); |
| 70 | + |
| 71 | + |
| 72 | + assertTrue(arc.getBounds().contains(samples.get(0))); |
| 73 | + assertTrue(arc.getBounds().contains(samples.get(1))); |
| 74 | + assertTrue(arc.getBounds().contains(samples.get(2))); |
| 75 | + assertTrue(arc.getBounds().contains(samples.get(3))); |
| 76 | + |
| 77 | + // these are the assertions that failed before resolving 4197755 |
| 78 | + assertTrue(!arc.getBounds().contains(samples.get(4))); |
| 79 | + assertTrue(!arc.getBounds().contains(samples.get(5))); |
| 80 | + assertTrue(!arc.getBounds().contains(samples.get(6))); |
| 81 | + assertTrue(!arc.getBounds().contains(samples.get(7))); |
| 82 | + } |
| 83 | + |
| 84 | + private static void assertTrue(boolean b) { |
| 85 | + if (!b) |
| 86 | + throw new Error(); |
| 87 | + } |
| 88 | +} |
0 commit comments