1 26 27 package org.nightlabs.editor2d.j2d; 28 29 import java.awt.geom.AffineTransform ; 30 import java.awt.geom.PathIterator ; 31 32 43 class GeneralShapeIterator implements PathIterator { 44 int typeIdx = 0; 45 int pointIdx = 0; 46 GeneralShape path; 47 AffineTransform affine; 48 49 private static final int curvesize[] = {2, 2, 4, 6, 0}; 50 51 55 GeneralShapeIterator(GeneralShape path) { 56 this(path, null); 57 } 58 59 64 GeneralShapeIterator(GeneralShape path, AffineTransform at) { 65 this.path = path; 66 this.affine = at; 67 } 68 69 75 public int getWindingRule() { 76 return path.getWindingRule(); 77 } 78 79 83 public boolean isDone() { 84 return (typeIdx >= path.numTypes); 85 } 86 87 92 public void next() { 93 int type = path.pointTypes[typeIdx++]; 94 pointIdx += curvesize[type]; 95 } 96 97 115 public int currentSegment(float[] coords) { 116 int type = path.pointTypes[typeIdx]; 117 int numCoords = curvesize[type]; 118 if (numCoords > 0 && affine != null) { 119 affine.transform(path.pointCoords, pointIdx, 120 coords, 0, 121 numCoords / 2); 122 } else { 123 System.arraycopy(path.pointCoords, pointIdx, coords, 0, numCoords); 124 } 125 return type; 126 } 127 128 146 public int currentSegment(double[] coords) { 147 int type = path.pointTypes[typeIdx]; 148 int numCoords = curvesize[type]; 149 if (numCoords > 0 && affine != null) { 150 affine.transform(path.pointCoords, pointIdx, 151 coords, 0, 152 numCoords / 2); 153 } else { 154 for (int i=0; i < numCoords; i++) { 155 coords[i] = path.pointCoords[pointIdx + i]; 156 } 157 } 158 return type; 159 } 160 } 161 162 | Popular Tags |