1 7 8 package java.awt.geom; 9 10 import java.util.*; 11 12 19 class QuadIterator implements PathIterator { 20 QuadCurve2D quad; 21 AffineTransform affine; 22 int index; 23 24 QuadIterator(QuadCurve2D q, AffineTransform at) { 25 this.quad = q; 26 this.affine = at; 27 } 28 29 35 public int getWindingRule() { 36 return WIND_NON_ZERO; 37 } 38 39 43 public boolean isDone() { 44 return (index > 1); 45 } 46 47 52 public void next() { 53 index++; 54 } 55 56 74 public int currentSegment(float[] coords) { 75 if (isDone()) { 76 throw new NoSuchElementException("quad iterator iterator out of bounds"); 77 } 78 int type; 79 if (index == 0) { 80 coords[0] = (float) quad.getX1(); 81 coords[1] = (float) quad.getY1(); 82 type = SEG_MOVETO; 83 } else { 84 coords[0] = (float) quad.getCtrlX(); 85 coords[1] = (float) quad.getCtrlY(); 86 coords[2] = (float) quad.getX2(); 87 coords[3] = (float) quad.getY2(); 88 type = SEG_QUADTO; 89 } 90 if (affine != null) { 91 affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 2); 92 } 93 return type; 94 } 95 96 114 public int currentSegment(double[] coords) { 115 if (isDone()) { 116 throw new NoSuchElementException("quad iterator iterator out of bounds"); 117 } 118 int type; 119 if (index == 0) { 120 coords[0] = quad.getX1(); 121 coords[1] = quad.getY1(); 122 type = SEG_MOVETO; 123 } else { 124 coords[0] = quad.getCtrlX(); 125 coords[1] = quad.getCtrlY(); 126 coords[2] = quad.getX2(); 127 coords[3] = quad.getY2(); 128 type = SEG_QUADTO; 129 } 130 if (affine != null) { 131 affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 2); 132 } 133 return type; 134 } 135 } 136 | Popular Tags |