001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.renderer.shape;
018:
019: import java.awt.geom.AffineTransform;
020: import java.awt.geom.PathIterator;
021:
022: /**
023: * java.awt.Shape Wrapper around geometry.
024: *
025: * @author jeichar
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/main/java/org/geotools/renderer/shape/PolygonShape.java $
027: */
028: public class PolygonShape extends AbstractShape {
029: /**
030: * DOCUMENT ME!
031: *
032: * @param geom
033: */
034: public PolygonShape(SimpleGeometry geom) {
035: super (geom);
036: }
037:
038: /* (non-Javadoc)
039: * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
040: */
041: public PathIterator getPathIterator(final AffineTransform at) {
042: return new PathIterator() {
043: int currentPart = 0;
044: int currentIndex = 0;
045:
046: public int getWindingRule() {
047: return WIND_EVEN_ODD;
048: }
049:
050: public boolean isDone() {
051: // TODO Auto-generated method stub
052: return currentPart == geom.coords.length;
053: }
054:
055: public void next() {
056: if (isDone()) {
057: return;
058: }
059:
060: if ((currentIndex + 1) >= geom.coords[currentPart].length) {
061: currentIndex = 0;
062: currentPart++;
063: } else {
064: currentIndex++;
065: }
066: }
067:
068: public int currentSegment(float[] coords) {
069: if (currentIndex == 0) {
070: coords[0] = (float) geom.coords[currentPart][currentIndex];
071: currentIndex++;
072: coords[1] = (float) geom.coords[currentPart][currentIndex];
073:
074: if (at != null) {
075: at.transform(coords, 0, coords, 0, 1);
076: }
077:
078: return SEG_MOVETO;
079: } else if ((currentIndex + 2) == geom.coords[currentPart].length) {
080: coords[0] = (float) geom.coords[currentPart][currentIndex];
081: currentIndex++;
082: coords[1] = (float) geom.coords[currentPart][currentIndex];
083: currentIndex = -1;
084: currentPart++;
085:
086: if (at != null) {
087: at.transform(coords, 0, coords, 0, 1);
088: }
089:
090: return SEG_CLOSE;
091: } else {
092: coords[0] = (float) geom.coords[currentPart][currentIndex];
093: currentIndex++;
094: coords[1] = (float) geom.coords[currentPart][currentIndex];
095:
096: if (at != null) {
097: at.transform(coords, 0, coords, 0, 1);
098: }
099:
100: return SEG_LINETO;
101: }
102: }
103:
104: public int currentSegment(double[] coords) {
105: if (currentIndex == 0) {
106: coords[0] = (float) geom.coords[currentPart][currentIndex];
107: currentIndex++;
108: coords[1] = (float) geom.coords[currentPart][currentIndex];
109:
110: if (at != null) {
111: at.transform(coords, 0, coords, 0, 1);
112: }
113:
114: return SEG_MOVETO;
115: } else if ((currentIndex + 2) == geom.coords[currentPart].length) {
116: coords[0] = (float) geom.coords[currentPart][currentIndex];
117: currentIndex++;
118: coords[1] = (float) geom.coords[currentPart][currentIndex];
119: currentIndex = -1;
120: currentPart++;
121:
122: if (at != null) {
123: at.transform(coords, 0, coords, 0, 1);
124: }
125:
126: return SEG_CLOSE;
127: } else {
128: coords[0] = (float) geom.coords[currentPart][currentIndex];
129: currentIndex++;
130: coords[1] = (float) geom.coords[currentPart][currentIndex];
131:
132: if (at != null) {
133: at.transform(coords, 0, coords, 0, 1);
134: }
135:
136: return SEG_LINETO;
137: }
138: }
139: };
140: }
141:
142: /* (non-Javadoc)
143: * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
144: */
145: public PathIterator getPathIterator(AffineTransform at,
146: double flatness) {
147: return getPathIterator(at);
148: }
149: }
|