1 7 8 package java.awt.geom; 9 10 import java.util.*; 11 12 19 class LineIterator implements PathIterator { 20 Line2D line; 21 AffineTransform affine; 22 int index; 23 24 LineIterator(Line2D l, AffineTransform at) { 25 this.line = l; 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("line iterator out of bounds"); 77 } 78 int type; 79 if (index == 0) { 80 coords[0] = (float) line.getX1(); 81 coords[1] = (float) line.getY1(); 82 type = SEG_MOVETO; 83 } else { 84 coords[0] = (float) line.getX2(); 85 coords[1] = (float) line.getY2(); 86 type = SEG_LINETO; 87 } 88 if (affine != null) { 89 affine.transform(coords, 0, coords, 0, 1); 90 } 91 return type; 92 } 93 94 112 public int currentSegment(double[] coords) { 113 if (isDone()) { 114 throw new NoSuchElementException("line iterator out of bounds"); 115 } 116 int type; 117 if (index == 0) { 118 coords[0] = line.getX1(); 119 coords[1] = line.getY1(); 120 type = SEG_MOVETO; 121 } else { 122 coords[0] = line.getX2(); 123 coords[1] = line.getY2(); 124 type = SEG_LINETO; 125 } 126 if (affine != null) { 127 affine.transform(coords, 0, coords, 0, 1); 128 } 129 return type; 130 } 131 } 132 | Popular Tags |