1 7 8 package java.awt.geom; 9 10 import java.util.*; 11 12 19 class CubicIterator implements PathIterator { 20 CubicCurve2D cubic; 21 AffineTransform affine; 22 int index; 23 24 CubicIterator(CubicCurve2D q, AffineTransform at) { 25 this.cubic = 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("cubic iterator iterator out of bounds"); 77 } 78 int type; 79 if (index == 0) { 80 coords[0] = (float) cubic.getX1(); 81 coords[1] = (float) cubic.getY1(); 82 type = SEG_MOVETO; 83 } else { 84 coords[0] = (float) cubic.getCtrlX1(); 85 coords[1] = (float) cubic.getCtrlY1(); 86 coords[2] = (float) cubic.getCtrlX2(); 87 coords[3] = (float) cubic.getCtrlY2(); 88 coords[4] = (float) cubic.getX2(); 89 coords[5] = (float) cubic.getY2(); 90 type = SEG_CUBICTO; 91 } 92 if (affine != null) { 93 affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 3); 94 } 95 return type; 96 } 97 98 116 public int currentSegment(double[] coords) { 117 if (isDone()) { 118 throw new NoSuchElementException("cubic iterator iterator out of bounds"); 119 } 120 int type; 121 if (index == 0) { 122 coords[0] = cubic.getX1(); 123 coords[1] = cubic.getY1(); 124 type = SEG_MOVETO; 125 } else { 126 coords[0] = cubic.getCtrlX1(); 127 coords[1] = cubic.getCtrlY1(); 128 coords[2] = cubic.getCtrlX2(); 129 coords[3] = cubic.getCtrlY2(); 130 coords[4] = cubic.getX2(); 131 coords[5] = cubic.getY2(); 132 type = SEG_CUBICTO; 133 } 134 if (affine != null) { 135 affine.transform(coords, 0, coords, 0, index == 0 ? 1 : 3); 136 } 137 return type; 138 } 139 } 140 | Popular Tags |