1 /* 2 * Copyright (c) 2011, 2013, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.rt_6334; 27 28 import com.sun.javafx.geom.CubicCurve2D; 29 import com.sun.javafx.geom.Line2D; 30 import com.sun.javafx.geom.Path2D; 31 import com.sun.javafx.geom.PathIterator; 32 import com.sun.javafx.geom.QuadCurve2D; 33 import com.sun.javafx.geom.Shape; 34 import com.sun.prism.BasicStroke; 35 import org.junit.Test; 36 37 public class rt_6334Test { 38 static int numcoords[] = { 2, 2, 4, 6, 0 }; 39 static boolean verbose; 40 41 public static void testPath(Shape orig, float thickness) { 42 BasicStroke stroke = 43 new BasicStroke(thickness, BasicStroke.CAP_SQUARE, 44 BasicStroke.JOIN_MITER, 10f); 45 Shape result = stroke.createStrokedShape(orig); 46 PathIterator pi = result.getPathIterator(null); 47 float coords[] = new float[6]; 48 while (!pi.isDone()) { 49 int type = pi.currentSegment(coords); 50 int ncoords = numcoords[type]; 51 if (verbose) { 52 System.out.print("MLQCX".charAt(type)+"["); 53 } 54 for (int i = 0; i < ncoords; i++) { 55 if (verbose) { 56 if (i > 0) System.out.print(", "); 57 System.out.print(coords[i]); 58 } 59 if (coords[i] < Float.POSITIVE_INFINITY && 60 coords[i] > Float.NEGATIVE_INFINITY) 61 { 62 continue; 63 } else { 64 throw new InternalError("non-finite coordinate generated: "+coords[i]); 65 } 66 } 67 if (verbose) { 68 System.out.println("]"); 69 } 70 pi.next(); 71 } 72 } 73 74 @Test(timeout=1000) 75 public void test_6334() { 76 Path2D p = new Path2D(); 77 p.moveTo(304.51f, 179.78f); 78 p.quadTo(301.00f, 180.78f, 305.20f, 180.76f); 79 p.quadTo(305.35f, 180.76f, 304.51f, 179.78f); 80 p.closePath(); 81 testPath(p, 1f); 82 } 83 84 static float rndFlt() { 85 return (float) Math.random(); 86 } 87 static float rndCoord() { 88 return rndFlt() * 2f + 300f; 89 } 90 91 @Test(timeout=5000) 92 public void testLines() { 93 Line2D l = new Line2D(); 94 for (int i = 0; i < 50000; i++) { 95 l.setLine(rndCoord(), rndCoord(), 96 rndCoord(), rndCoord()); 97 testPath(l, 1f); 98 testPath(l, rndFlt() * 10f); 99 testPath(l, 20f); 100 } 101 } 102 103 @Test(timeout=5000) 104 public void testQuads() { 105 QuadCurve2D qc = new QuadCurve2D(); 106 for (int i = 0; i < 50000; i++) { 107 qc.setCurve(rndCoord(), rndCoord(), 108 rndCoord(), rndCoord(), 109 rndCoord(), rndCoord()); 110 testPath(qc, 1f); 111 testPath(qc, rndFlt() * 10f); 112 testPath(qc, 20f); 113 } 114 } 115 116 @Test(timeout=5000) 117 public void testCubics() { 118 CubicCurve2D cc = new CubicCurve2D(); 119 for (int i = 0; i < 50000; i++) { 120 cc.setCurve(rndCoord(), rndCoord(), 121 rndCoord(), rndCoord(), 122 rndCoord(), rndCoord(), 123 rndCoord(), rndCoord()); 124 testPath(cc, 1f); 125 testPath(cc, rndFlt() * 10f); 126 testPath(cc, 20f); 127 } 128 } 129 }