1 7 8 package java.awt.geom; 9 10 import java.util.*; 11 12 19 class RectIterator implements PathIterator { 20 double x, y, w, h; 21 AffineTransform affine; 22 int index; 23 24 RectIterator(Rectangle2D r, AffineTransform at) { 25 this.x = r.getX(); 26 this.y = r.getY(); 27 this.w = r.getWidth(); 28 this.h = r.getHeight(); 29 this.affine = at; 30 if (w < 0 || h < 0) { 31 index = 6; 32 } 33 } 34 35 41 public int getWindingRule() { 42 return WIND_NON_ZERO; 43 } 44 45 49 public boolean isDone() { 50 return index > 5; 51 } 52 53 58 public void next() { 59 index++; 60 } 61 62 80 public int currentSegment(float[] coords) { 81 if (isDone()) { 82 throw new NoSuchElementException("rect iterator out of bounds"); 83 } 84 if (index == 5) { 85 return SEG_CLOSE; 86 } 87 coords[0] = (float) x; 88 coords[1] = (float) y; 89 if (index == 1 || index == 2) { 90 coords[0] += (float) w; 91 } 92 if (index == 2 || index == 3) { 93 coords[1] += (float) h; 94 } 95 if (affine != null) { 96 affine.transform(coords, 0, coords, 0, 1); 97 } 98 return (index == 0 ? SEG_MOVETO : SEG_LINETO); 99 } 100 101 119 public int currentSegment(double[] coords) { 120 if (isDone()) { 121 throw new NoSuchElementException("rect iterator out of bounds"); 122 } 123 if (index == 5) { 124 return SEG_CLOSE; 125 } 126 coords[0] = x; 127 coords[1] = y; 128 if (index == 1 || index == 2) { 129 coords[0] += w; 130 } 131 if (index == 2 || index == 3) { 132 coords[1] += h; 133 } 134 if (affine != null) { 135 affine.transform(coords, 0, coords, 0, 1); 136 } 137 return (index == 0 ? SEG_MOVETO : SEG_LINETO); 138 } 139 } 140 | Popular Tags |