Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / ring / Ring3D.java @ 42267

History | View | Annotate | Download (5.14 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts.primitive.ring;
24

    
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.PathIterator;
27

    
28
import com.vividsolutions.jts.geom.Coordinate;
29

    
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
32
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
33
import org.gvsig.fmap.geom.primitive.GeneralPathX;
34
import org.gvsig.fmap.geom.primitive.Ring;
35

    
36

    
37
/**
38
 * @author fdiaz
39
 *
40
 */
41
public class Ring3D extends Line3D implements Ring {
42

    
43
    /**
44
     *
45
     */
46
    private static final long serialVersionUID = 9116088317343114306L;
47

    
48
    /**
49
     */
50
    protected Ring3D() {
51
        super();
52
    }
53

    
54
    /**
55
     * @param coordinates
56
     */
57
    public Ring3D(Coordinate[] coordinates) {
58
        super(coordinates);
59
    }
60

    
61
    /* (non-Javadoc)
62
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
63
     */
64
    public Geometry cloneGeometry() {
65
        return new Ring3D((Coordinate[]) coordinates.clone());
66
    }
67

    
68
    /*
69
     * (non-Javadoc)
70
     *
71
     * @see
72
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
73
     * )
74
     */
75
    public PathIterator getPathIterator(AffineTransform at) {
76
        RingIterator pi = new RingIterator(at);
77
        return pi;
78
    }
79

    
80
    private class RingIterator extends GeneralPathXIterator {
81

    
82
        /** Transform applied on the coordinates during iteration */
83
        private AffineTransform at;
84

    
85
        /** True when the point has been read once */
86
        private boolean done;
87
        private int index = 0;
88

    
89
        /**
90
         * Creates a new PointIterator object.
91
         *
92
         * @param p
93
         *            The polygon
94
         * @param at
95
         *            The affine transform applied to coordinates during
96
         *            iteration
97
         */
98
        public RingIterator(AffineTransform at) {
99
            super(new GeneralPathX());
100
            if (at == null) {
101
                at = new AffineTransform();
102
            }
103

    
104
            this.at = at;
105
            done = false;
106
        }
107

    
108
        /**
109
         * Return the winding rule for determining the interior of the path.
110
         *
111
         * @return <code>WIND_EVEN_ODD</code> by default.
112
         */
113
        public int getWindingRule() {
114
            return PathIterator.WIND_EVEN_ODD;
115
        }
116

    
117
        /**
118
         * @see java.awt.geom.PathIterator#next()
119
         */
120
        public void next() {
121
            if(isClosed()){
122
                done = (coordinates.size() == index++);
123
            } else {
124
                done = ((coordinates.size()+1) == index++);
125
            }
126
        }
127

    
128
        /**
129
         * @see java.awt.geom.PathIterator#isDone()
130
         */
131
        public boolean isDone() {
132
            return done;
133
        }
134

    
135
        /**
136
         * @see java.awt.geom.PathIterator#currentSegment(double[])
137
         */
138
        public int currentSegment(double[] coords) {
139
            if(!isClosed() && index==coordinates.size()){
140
                coords[0] = coordinates.getX(0);
141
                coords[1] = coordinates.getY(0);
142
                at.transform(coords, 0, coords, 0, 1);
143
                return PathIterator.SEG_LINETO;
144
            }
145
            coords[0] = coordinates.getX(index);
146
            coords[1] = coordinates.getY(index);
147
            at.transform(coords, 0, coords, 0, 1);
148

    
149
            if (index == 0) {
150
                return PathIterator.SEG_MOVETO;
151
            } else {
152
                return PathIterator.SEG_LINETO;
153
            }
154
        }
155

    
156
        /*
157
         * (non-Javadoc)
158
         *
159
         * @see java.awt.geom.PathIterator#currentSegment(float[])
160
         */
161
        public int currentSegment(float[] coords) {
162
            if(!isClosed() && index==coordinates.size()){
163
                coords[0] = (float) coordinates.getX(0);
164
                coords[1] = (float) coordinates.getY(0);
165
                at.transform(coords, 0, coords, 0, 1);
166
                return PathIterator.SEG_LINETO;
167
            }
168
            coords[0] = (float) coordinates.getX(index);
169
            coords[1] = (float) coordinates.getY(index);
170
            at.transform(coords, 0, coords, 0, 1);
171

    
172
            if (index == 0) {
173
                return PathIterator.SEG_MOVETO;
174
            } else {
175
                return PathIterator.SEG_LINETO;
176
            }
177
        }
178
    }
179

    
180
}