Showing the changes to java/pkg/java/awt/geom/QuadIterator.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,152 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 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 java.awt.geom; | ||
| 27 | |||
| 28 | import java.util.*; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * A utility class to iterate over the path segments of a quadratic curve | ||
| 32 | * segment through the PathIterator interface. | ||
| 33 | * | ||
| 34 | * @author Jim Graham | ||
| 35 | */ | ||
| 36 | class QuadIterator implements PathIterator { | ||
| 37 | QuadCurve2D quad; | ||
| 38 | AffineTransform affine; | ||
| 39 | int index; | ||
| 40 | |||
| 41 | QuadIterator(QuadCurve2D q, AffineTransform at) { | ||
| 42 | this.quad = q; | ||
| 43 | this.affine = at; | ||
| 44 | } | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Return the winding rule for determining the insideness of the | ||
| 48 | * path. | ||
| 49 | * @see #WIND_EVEN_ODD | ||
| 50 | * @see #WIND_NON_ZERO | ||
| 51 | */ | ||
| 52 | public int getWindingRule() { | ||
| 53 | return WIND_NON_ZERO; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Tests if there are more points to read. | ||
| 58 | * @return true if there are more points to read | ||
| 59 | */ | ||
| 60 | public boolean isDone() { | ||
| 61 | return (index > 1); | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Moves the iterator to the next segment of the path forwards | ||
| 66 | * along the primary direction of traversal as long as there are | ||
| 67 | * more points in that direction. | ||
| 68 | */ | ||
| 69 | public void next() { | ||
| 70 | index++; | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Returns the coordinates and type of the current path segment in | ||
| 75 | * the iteration. | ||
| 76 | * The return value is the path segment type: | ||
| 77 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. | ||
| 78 | * A float array of length 6 must be passed in and may be used to | ||
| 79 | * store the coordinates of the point(s). | ||
| 80 | * Each point is stored as a pair of float x,y coordinates. | ||
| 81 | * SEG_MOVETO and SEG_LINETO types will return one point, | ||
| 82 | * SEG_QUADTO will return two points, | ||
| 83 | * SEG_CUBICTO will return 3 points | ||
| 84 | * and SEG_CLOSE will not return any points. | ||
| 85 | * @see #SEG_MOVETO | ||
| 86 | * @see #SEG_LINETO | ||
| 87 | * @see #SEG_QUADTO | ||
| 88 | * @see #SEG_CUBICTO | ||
| 89 | * @see #SEG_CLOSE | ||
| 90 | */ | ||
| 91 | public int currentSegment(float[] coords) { | ||
| 92 | if (isDone()) { | ||
| 93 | throw new NoSuchElementException("quad iterator iterator out of bounds"); | ||
| 94 | } | ||
| 95 | int type; | ||
| 96 | if (index == 0) { | ||
| 97 | coords[0] = (float) quad.getX1(); | ||
| 98 | coords[1] = (float) quad.getY1(); | ||
| 99 | type = SEG_MOVETO; | ||
| 100 | } else { | ||
| 101 | coords[0] = (float) quad.getCtrlX(); | ||
| 102 | coords[1] = (float) quad.getCtrlY(); | ||
| 103 | coords[2] = (float) quad.getX2(); | ||
| 104 | coords[3] = (float) quad.getY2(); | ||
| 105 | type = SEG_QUADTO; | ||
| 106 | } | ||
| 107 | if (affine != null) { | ||
| 108 | affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 2); | ||
| 109 | } | ||
| 110 | return type; | ||
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * Returns the coordinates and type of the current path segment in | ||
| 115 | * the iteration. | ||
| 116 | * The return value is the path segment type: | ||
| 117 | * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. | ||
| 118 | * A double array of length 6 must be passed in and may be used to | ||
| 119 | * store the coordinates of the point(s). | ||
| 120 | * Each point is stored as a pair of double x,y coordinates. | ||
| 121 | * SEG_MOVETO and SEG_LINETO types will return one point, | ||
| 122 | * SEG_QUADTO will return two points, | ||
| 123 | * SEG_CUBICTO will return 3 points | ||
| 124 | * and SEG_CLOSE will not return any points. | ||
| 125 | * @see #SEG_MOVETO | ||
| 126 | * @see #SEG_LINETO | ||
| 127 | * @see #SEG_QUADTO | ||
| 128 | * @see #SEG_CUBICTO | ||
| 129 | * @see #SEG_CLOSE | ||
| 130 | */ | ||
| 131 | public int currentSegment(double[] coords) { | ||
| 132 | if (isDone()) { | ||
| 133 | throw new NoSuchElementException("quad iterator iterator out of bounds"); | ||
| 134 | } | ||
| 135 | int type; | ||
| 136 | if (index == 0) { | ||
| 137 | coords[0] = quad.getX1(); | ||
| 138 | coords[1] = quad.getY1(); | ||
| 139 | type = SEG_MOVETO; | ||
| 140 | } else { | ||
| 141 | coords[0] = quad.getCtrlX(); | ||
| 142 | coords[1] = quad.getCtrlY(); | ||
| 143 | coords[2] = quad.getX2(); | ||
| 144 | coords[3] = quad.getY2(); | ||
| 145 | type = SEG_QUADTO; | ||
| 146 | } | ||
| 147 | if (affine != null) { | ||
| 148 | affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 2); | ||
| 149 | } | ||
| 150 | return type; | ||
| 151 | } | ||
| 152 | } | ||