001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package sec.sun.awt.geom; 006 007import armyc2.c2sd.graphics2d.*; 008 009/** 010 * 011 * @author Michael Deutch 012 */ 013public class AreaIterator { 014 015 private final AffineTransform transform; 016 private final Vector curves; 017 private int index; 018 private CurveObject prevcurve; 019 private CurveObject thiscurve; 020 021 public AreaIterator(Vector curves, AffineTransform at) { 022 this.curves = curves; 023 this.transform = at; 024 if (curves.size() >= 1) { 025 thiscurve = (CurveObject) curves.get(0); 026 } 027 } 028 029 public int getWindingRule() { 030 // REMIND: Which is better, EVEN_ODD or NON_ZERO? 031 // The paths calculated could be classified either way. 032 //return WIND_EVEN_ODD; 033 return PathIterator.WIND_NON_ZERO; 034 } 035 036 public boolean isDone() { 037 return (prevcurve == null && thiscurve == null); 038 } 039 040 public void next() { 041 if (prevcurve != null) { 042 prevcurve = null; 043 } else { 044 prevcurve = thiscurve; 045 index++; 046 if (index < curves.size()) { 047 thiscurve = (CurveObject) curves.get(index); 048 if (thiscurve.getOrder() != 0 049 && prevcurve.getX1() == thiscurve.getX0() 050 && prevcurve.getY1() == thiscurve.getY0()) { 051 prevcurve = null; 052 } 053 } else { 054 thiscurve = null; 055 } 056 } 057 } 058 059 public int currentSegmentFlt(float coords[]) { 060 double dcoords[] = new double[6]; 061 int segtype = currentSegment(dcoords); 062 int numpoints = (segtype == PathIterator.SEG_CLOSE ? 0 063 : (segtype == PathIterator.SEG_QUADTO ? 2 064 : (segtype == PathIterator.SEG_CUBICTO ? 3 065 : 1))); 066 for (int i = 0; i < numpoints * 2; i++) { 067 coords[i] = (float) dcoords[i]; 068 } 069 return segtype; 070 } 071 072 public int currentSegment(double coords[]) { 073 int segtype = 0; 074 int numpoints = 0; 075 if (prevcurve != null) { 076 // Need to finish off junction between curves 077 if (thiscurve == null || thiscurve.getOrder() == 0) { 078 return PathIterator.SEG_CLOSE; 079 } 080 coords[0] = thiscurve.getX0(); 081 coords[1] = thiscurve.getY0(); 082 segtype = PathIterator.SEG_LINETO; 083 numpoints = 1; 084 } else if (thiscurve == null) { 085 //throw new NoSuchElementException("area iterator out of bounds"); 086 } else { 087 segtype = thiscurve.getSegment(coords); 088 numpoints = thiscurve.getOrder(); 089 if (numpoints == 0) { 090 numpoints = 1; 091 } 092 } 093 return segtype; 094 } 095 096}