1 /* 2 * Copyright (c) 2015, 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 import java.awt.geom.GeneralPath; 25 import java.awt.geom.Path2D; 26 27 /** 28 * @test 29 * @bug 8078464 30 * @summary Check the growth algorithm (needRoom) in Path2D implementations 31 * @run main Path2DGrow 32 */ 33 public class Path2DGrow { 34 35 public static final int N = 1000 * 1000; 36 37 public static boolean verbose = false; 38 public static boolean force = false; 39 40 static void echo(String msg) { 41 System.out.println(msg); 42 } 43 44 static void log(String msg) { 45 if (verbose || force) { 46 echo(msg); 47 } 48 } 49 50 public static void main(String argv[]) { 51 verbose = (argv.length != 0); 52 53 testEmptyDoublePaths(); 54 testDoublePaths(); 55 56 testEmptyFloatPaths(); 57 testFloatPaths(); 58 59 testEmptyGeneralPath(); 60 testGeneralPath(); 61 } 62 63 static void testEmptyDoublePaths() { 64 echo("\n - Test(Path2D.Double[0]) ---"); 65 test(() -> new Path2D.Double(Path2D.WIND_NON_ZERO, 0)); 66 } 67 68 static void testDoublePaths() { 69 echo("\n - Test(Path2D.Double) ---"); 70 test(() -> new Path2D.Double()); 71 } 72 73 static void testEmptyFloatPaths() { 74 echo("\n - Test(Path2D.Float[0]) ---"); 75 test(() -> new Path2D.Float(Path2D.WIND_NON_ZERO, 0)); 76 } 77 78 static void testFloatPaths() { 79 echo("\n - Test(Path2D.Float) ---"); 80 test(() -> new Path2D.Float()); 81 } 82 83 static void testEmptyGeneralPath() { 84 echo("\n - Test(GeneralPath[0]) ---"); 85 test(() -> new GeneralPath(Path2D.WIND_NON_ZERO, 0)); 86 } 87 88 static void testGeneralPath() { 89 echo("\n - Test(GeneralPath) ---"); 90 test(() -> new GeneralPath()); 91 } 92 93 interface PathFactory { 94 Path2D makePath(); 95 } 96 97 static void test(PathFactory pf) { 98 long start, end; 99 100 for (int n = 1; n <= N; n *= 10) { 101 force = (n == N); 102 103 start = System.nanoTime(); 104 testAddMoves(pf.makePath(), n); 105 end = System.nanoTime(); 106 log("testAddMoves[" + n + "] duration= " 107 + (1e-6 * (end - start)) + " ms."); 108 109 start = System.nanoTime(); 110 testAddLines(pf.makePath(), n); 111 end = System.nanoTime(); 112 log("testAddLines[" + n + "] duration= " 113 + (1e-6 * (end - start)) + " ms."); 114 115 start = System.nanoTime(); 116 testAddQuads(pf.makePath(), n); 117 end = System.nanoTime(); 118 log("testAddQuads[" + n + "] duration= " 119 + (1e-6 * (end - start)) + " ms."); 120 121 start = System.nanoTime(); 122 testAddCubics(pf.makePath(), n); 123 end = System.nanoTime(); 124 log("testAddCubics[" + n + "] duration= " 125 + (1e-6 * (end - start)) + " ms."); 126 127 start = System.nanoTime(); 128 testAddMoveAndCloses(pf.makePath(), n); 129 end = System.nanoTime(); 130 log("testAddMoveAndCloses[" + n + "] duration= " 131 + (1e-6 * (end - start)) + " ms."); 132 } 133 } 134 135 static void addMove(Path2D p2d, int i) { 136 p2d.moveTo(1.0 * i, 0.5 * i); 137 } 138 139 static void addLine(Path2D p2d, int i) { 140 p2d.lineTo(1.1 * i, 2.3 * i); 141 } 142 143 static void addCubic(Path2D p2d, int i) { 144 p2d.curveTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i, 1.5 * i, 1.6 * i); 145 } 146 147 static void addQuad(Path2D p2d, int i) { 148 p2d.quadTo(1.1 * i, 1.2 * i, 1.3 * i, 1.4 * i); 149 } 150 151 static void addClose(Path2D p2d) { 152 p2d.closePath(); 153 } 154 155 static void testAddMoves(Path2D pathA, int n) { 156 for (int i = 0; i < n; i++) { 157 addMove(pathA, i); 158 } 159 } 160 161 static void testAddLines(Path2D pathA, int n) { 162 addMove(pathA, 0); 163 for (int i = 0; i < n; i++) { 164 addLine(pathA, i); 165 } 166 } 167 168 static void testAddQuads(Path2D pathA, int n) { 169 addMove(pathA, 0); 170 for (int i = 0; i < n; i++) { 171 addQuad(pathA, i); 172 } 173 } 174 175 static void testAddCubics(Path2D pathA, int n) { 176 addMove(pathA, 0); 177 for (int i = 0; i < n; i++) { 178 addCubic(pathA, i); 179 } 180 } 181 182 static void testAddMoveAndCloses(Path2D pathA, int n) { 183 for (int i = 0; i < n; i++) { 184 addMove(pathA, i); 185 addClose(pathA); 186 } 187 } 188 }