1 7 8 package java.awt.geom; 9 10 import java.util.*; 11 12 19 class EllipseIterator implements PathIterator { 20 double x, y, w, h; 21 AffineTransform affine; 22 int index; 23 24 EllipseIterator(Ellipse2D e, AffineTransform at) { 25 this.x = e.getX(); 26 this.y = e.getY(); 27 this.w = e.getWidth(); 28 this.h = e.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 public static final double CtrlVal = 0.5522847498307933; 64 65 70 private static final double pcv = 0.5 + CtrlVal * 0.5; 71 private static final double ncv = 0.5 - CtrlVal * 0.5; 72 private static double ctrlpts[][] = { 73 { 1.0, pcv, pcv, 1.0, 0.5, 1.0 }, 74 { ncv, 1.0, 0.0, pcv, 0.0, 0.5 }, 75 { 0.0, ncv, ncv, 0.0, 0.5, 0.0 }, 76 { pcv, 0.0, 1.0, ncv, 1.0, 0.5 } 77 }; 78 79 97 public int currentSegment(float[] coords) { 98 if (isDone()) { 99 throw new NoSuchElementException("ellipse iterator out of bounds"); 100 } 101 if (index == 5) { 102 return SEG_CLOSE; 103 } 104 if (index == 0) { 105 double ctrls[] = ctrlpts[3]; 106 coords[0] = (float) (x + ctrls[4] * w); 107 coords[1] = (float) (y + ctrls[5] * h); 108 if (affine != null) { 109 affine.transform(coords, 0, coords, 0, 1); 110 } 111 return SEG_MOVETO; 112 } 113 double ctrls[] = ctrlpts[index - 1]; 114 coords[0] = (float) (x + ctrls[0] * w); 115 coords[1] = (float) (y + ctrls[1] * h); 116 coords[2] = (float) (x + ctrls[2] * w); 117 coords[3] = (float) (y + ctrls[3] * h); 118 coords[4] = (float) (x + ctrls[4] * w); 119 coords[5] = (float) (y + ctrls[5] * h); 120 if (affine != null) { 121 affine.transform(coords, 0, coords, 0, 3); 122 } 123 return SEG_CUBICTO; 124 } 125 126 144 public int currentSegment(double[] coords) { 145 if (isDone()) { 146 throw new NoSuchElementException("ellipse iterator out of bounds"); 147 } 148 if (index == 5) { 149 return SEG_CLOSE; 150 } 151 if (index == 0) { 152 double ctrls[] = ctrlpts[3]; 153 coords[0] = x + ctrls[4] * w; 154 coords[1] = y + ctrls[5] * h; 155 if (affine != null) { 156 affine.transform(coords, 0, coords, 0, 1); 157 } 158 return SEG_MOVETO; 159 } 160 double ctrls[] = ctrlpts[index - 1]; 161 coords[0] = x + ctrls[0] * w; 162 coords[1] = y + ctrls[1] * h; 163 coords[2] = x + ctrls[2] * w; 164 coords[3] = y + ctrls[3] * h; 165 coords[4] = x + ctrls[4] * w; 166 coords[5] = y + ctrls[5] * h; 167 if (affine != null) { 168 affine.transform(coords, 0, coords, 0, 3); 169 } 170 return SEG_CUBICTO; 171 } 172 } 173 | Popular Tags |