Revision 38599

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Point2DZ.java
22 22
package org.gvsig.fmap.geom.primitive.impl;
23 23

  
24 24
import org.cresques.cts.IProjection;
25

  
26 25
import org.gvsig.fmap.geom.Geometry;
27 26
import org.gvsig.fmap.geom.primitive.FShape;
28 27
import org.gvsig.fmap.geom.primitive.Point;
29 28
import org.gvsig.fmap.geom.type.GeometryType;
30 29

  
31 30
/**
32
 * Punto 3D.
31
 * 3D point implementation.
33 32
 * 
34 33
 * @author Vicente Caballero Navarro
34
 * @author gvSIG team
35 35
 */
36 36
public class Point2DZ extends Point2D implements Point {
37 37

  
38
    public static final String PERSISTENCE_DEFINITION_NAME =
39
        "Point2DimensionsZ";
40
    private static final long serialVersionUID = 1L;
38
	private static final long serialVersionUID = 3113070237182638858L;
41 39

  
42
    /**
43
     * The constructor with the GeometryType like and argument
44
     * is used by the {@link GeometryType}{@link #create()} to create the
45
     * geometry
46
     * 
47
     * @param type
48
     *            The geometry type
49
     */
50
    public Point2DZ(GeometryType geomType) {
51
        super(geomType);
52
        coordinates[2] = 0;
53
    }
40
	public static final String PERSISTENCE_DEFINITION_NAME = "Point2DimensionsZ";
41
	private double z = 0.0d;
54 42

  
55
    /**
56
     * Constructor used in the {@link Geometry#cloneGeometry()} method
57
     * 
58
     * @param id
59
     * @param projection
60
     * @param x
61
     * @param y
62
     * @param z
63
     */
64
    Point2DZ(GeometryType geomType, String id, IProjection projection,
65
        double x, double y, double z) {
66
        super(geomType, id, projection, x, y);
67
        coordinates[2] = z;
68
    }
43
	/**
44
	 * The constructor with the GeometryType like and argument is used by the
45
	 * {@link GeometryType}{@link #create()} to create the geometry
46
	 * 
47
	 * @param type
48
	 *            The geometry type
49
	 */
50
	public Point2DZ(GeometryType geomType) {
51
		super(geomType);
52
	}
69 53

  
70
    public Point2DZ(double x, double y, double z) {
71
        super(TYPES.POINT, SUBTYPES.GEOM3D);
72
        coordinates[0] = x;
73
        coordinates[1] = y;
74
        coordinates[2] = z;
75
    }
54
	/**
55
	 * Constructor used in the {@link Geometry#cloneGeometry()} method
56
	 * 
57
	 * @param id
58
	 * @param projection
59
	 * @param x
60
	 * @param y
61
	 * @param z
62
	 */
63
	Point2DZ(GeometryType geomType, String id, IProjection projection,
64
			double x, double y, double z) {
65
		super(geomType, id, projection, x, y);
66
		this.z = z;
67
	}
76 68

  
77
    /*
78
     * (non-Javadoc)
79
     * 
80
     * @see org.gvsig.fmap.geom.primitive.impl.Point2D#getShapeType()
81
     */
82
    public int getShapeType() {
83
        return TYPES.POINT;
69
    public Point2DZ(double x, double y, double z, GeometryType geometryType) {
70
        super(geometryType);
71
        this.x = x;
72
        this.y = y;
73
        this.z = z;
84 74
    }
85 75

  
86
    /*
87
     * (non-Javadoc)
88
     * 
89
     * @see org.gvsig.fmap.geom.primitive.impl.Point2D#cloneFShape()
90
     */
91
    public FShape cloneFShape() {
92
        return new Point2DZ(getGeometryType(), id, projection, coordinates[0],
93
            coordinates[1], coordinates[2]);
94
    }
76
	public Point2DZ(double x, double y, double z) {
77
		super(TYPES.POINT, SUBTYPES.GEOM3D);
78
		this.x = x;
79
		this.y = y;
80
		this.z = z;
81
	}
95 82

  
96
    /*
97
     * (non-Javadoc)
98
     * 
99
     * @see org.gvsig.fmap.geom.primitive.impl.Point2D#getDimension()
100
     */
101
    public int getDimension() {
102
        return 3;
103
    }
83
	public int getShapeType() {
84
		return TYPES.POINT;
85
	}
104 86

  
105
    /*
106
     * (non-Javadoc)
107
     * 
108
     * @see org.gvsig.fmap.geom.primitive.impl.Point2D#equals(java.lang.Object)
109
     */
110
    public boolean equals(Object other) {
111
        if (!super.equals(other)) {
112
            return false;
113
        }
87
	public FShape cloneFShape() {
88
		return new Point2DZ(getGeometryType(), id, projection, x, y, z);
89
	}
114 90

  
115
        Point2DZ pother = (Point2DZ) other;
116
        if (Math.abs(this.coordinates[2] - pother.coordinates[2]) > 0.0000001) {
117
            return false;
118
        }
119
        return true;
120
    }
91
	public int getDimension() {
92
		return 3;
93
	}
121 94

  
122
    public void setCoordinates(double[] values) {
123
        super.setCoordinates(values);
124
        if (values.length > 2) {
125
            coordinates[2] = values[2];
126
        }
127
    }
95
	public boolean equals(Object other) {
96
		if (!super.equals(other)) {
97
			return false;
98
		}
128 99

  
129
    public String toString() {
130
        StringBuffer buffer = new StringBuffer();
131
        buffer.append("Point2DZ(");
132
        toStringCoordinates(buffer);
133
        buffer.append(")");
134
        return buffer.toString();
135
    }
100
		Point2DZ pother = (Point2DZ) other;
101
		if (Math.abs(this.z - pother.z) > 0.0000001) {
102
			return false;
103
		}
104
		return true;
105
	}
106

  
107
	public void setCoordinates(double[] values) {
108
		super.setCoordinates(values);
109
		if (values.length > 2) {
110
			z = values[2];
111
		}
112
	}
113

  
114
	public void setCoordinateAt(int dimension, double value) {
115
		if (dimension == Geometry.DIMENSIONS.Z) {
116
			this.z = value;
117
		} else {
118
			super.setCoordinateAt(dimension, value);
119
		}
120
	}
121

  
122
	public double getCoordinateAt(int dimension) {
123
		return (dimension == Geometry.DIMENSIONS.Z) ? this.z : super
124
				.getCoordinateAt(dimension);
125
	}
126

  
127
	public double getOrdinate(int dimension) {
128
		return (dimension == Geometry.DIMENSIONS.Z) ? this.z : super
129
				.getCoordinateAt(dimension);
130
	}
131

  
132
	public double[] getCoordinates() {
133
		return new double[] { getX(), getY(), this.z };
134
	}
135

  
136
	protected String getFullTypeName() {
137
		return "Point2DZ";
138
	}
139

  
136 140
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Point2D.java
22 22
package org.gvsig.fmap.geom.primitive.impl;
23 23

  
24 24
import java.awt.Rectangle;
25
import java.awt.Shape;
25 26
import java.awt.geom.AffineTransform;
26 27
import java.awt.geom.PathIterator;
27 28
import java.awt.geom.Rectangle2D;
28
import java.util.ArrayList;
29 29

  
30 30
import org.cresques.cts.ICoordTrans;
31 31
import org.cresques.cts.IProjection;
......
43 43
import org.gvsig.fmap.geom.type.GeometryType;
44 44

  
45 45
/**
46
 * Punto 2D.
46
 * 2D point implementation.
47 47
 * 
48 48
 * @author Vicente Caballero Navarro
49
 * @author gvSIG team
49 50
 */
50 51
public class Point2D extends AbstractPrimitive implements Point, DirectPosition {
52
	
53
	private static final long serialVersionUID = 1836257305083881299L;
51 54

  
52 55
    protected static final String COORDINATES_FIELD = "coordinates";
56
    protected double x;
57
    protected double y;
53 58

  
54
    private static final long serialVersionUID = 1836257305083881299L;
55
    protected double[] coordinates;
56

  
57 59
    /**
58 60
     * The constructor with the GeometryType like and argument
59 61
     * is used by the {@link GeometryType}{@link #create()} to create the
......
63 65
     *            The geometry type
64 66
     */
65 67
    public Point2D(GeometryType geometryType) {
66
        this(geometryType, null, null, 0.0, 0.0);
68
    	super(geometryType, null, null);
69
        this.x = 0.0d;
70
        this.y = 0.0d;
67 71
    }
68 72

  
69 73
    /**
......
72 76
    Point2D(GeometryType geometryType, String id, IProjection projection,
73 77
        double x, double y) {
74 78
        super(geometryType, id, projection);
75
        coordinates = new double[getDimension()];
76
        coordinates[0] = x;
77
        coordinates[1] = y;
79
        this.x = x;
80
        this.y = y;
78 81
    }
79 82

  
80 83
    public Point2D(double x, double y) {
81 84
        super(TYPES.POINT, SUBTYPES.GEOM2D);
82
        coordinates = new double[getDimension()];
83
        coordinates[0] = x;
84
        coordinates[1] = y;
85
        this.x = x;
86
        this.y = y;
85 87
    }
86 88

  
89
    public Point2D(GeometryType geometryType, double x, double y) {
90
        super(geometryType, null, null);
91
        this.x = x;
92
        this.y = y;
93
    }
94

  
87 95
    public Point2D(int type, int subtype) {
88 96
        super(type, subtype);
89
        coordinates = new double[getDimension()];
97
        this.x = 0.0d;
98
        this.y = 0.0d;
90 99
    }
91 100

  
92 101
    public Point2D(java.awt.geom.Point2D point) {
93 102
        super(TYPES.POINT, SUBTYPES.GEOM2D);
94
        coordinates = new double[getDimension()];
95
        coordinates[0] = point.getX();
96
        coordinates[1] = point.getY();
103
        this.x = point.getX();
104
        this.y = point.getY();
97 105
    }
98 106

  
99 107
    /**
......
104 112
     *            Matriz de transformaci?n.
105 113
     */
106 114
    public void transform(AffineTransform at) {
115
        double[] coordinates = getCoordinates();
107 116
        at.transform(coordinates, 0, coordinates, 0, 1);
117
        setCoordinates(coordinates);
108 118
    }
109 119

  
110
    /*
111
     * (non-Javadoc)
112
     * 
113
     * @see java.awt.Shape#contains(double, double)
114
     */
115 120
    public boolean contains(double x, double y) {
116
        if ((x == coordinates[0]) || (y == coordinates[1])) {
121
        if ((this.x == x) || (this.y == y)) {
117 122
            return true;
118 123
        } else {
119 124
            return false;
120 125
        }
121 126
    }
122 127

  
123
    /*
124
     * (non-Javadoc)
125
     * 
126
     * @see java.awt.Shape#contains(double, double, double, double)
127
     */
128 128
    public boolean contains(double x, double y, double w, double h) {
129 129
        return false;
130 130
    }
131 131

  
132
    /*
133
     * (non-Javadoc)
134
     * 
135
     * @see java.awt.Shape#intersects(double, double, double, double)
136
     */
137 132
    public boolean intersects(double x, double y, double w, double h) {
138 133
        Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
139 134

  
140
        return rAux.contains(coordinates[0], coordinates[1]);
135
        return rAux.contains(this.x, this.y);
141 136
    }
142 137

  
143
    /*
144
     * (non-Javadoc)
145
     * 
146
     * @see java.awt.Shape#getBounds()
147
     */
148 138
    public Rectangle getBounds() {
149
        return new Rectangle((int) coordinates[0], (int) coordinates[1], 0, 0);
139
        return new Rectangle((int) x, (int) y, 0, 0);
150 140
    }
151 141

  
152
    /**
153
     * Devuelve la coordenada x del punto.
154
     * 
155
     * @return Coordenada x.
156
     */
157 142
    public double getX() {
158
        return coordinates[0];
143
        return x;
159 144
    }
160 145

  
161
    /**
162
     * Devuelve la coordenada y del punto.
163
     * 
164
     * @return Coordenada y.
165
     */
166 146
    public double getY() {
167
        return coordinates[1];
147
        return y;
168 148
    }
169 149

  
170
    /*
171
     * (non-Javadoc)
172
     * 
173
     * @see java.awt.Shape#contains(java.awt.geom.Point2D)
174
     */
175 150
    public boolean contains(java.awt.geom.Point2D p) {
176 151
        return false;
177 152
    }
178 153

  
179
    /*
180
     * (non-Javadoc)
181
     * 
182
     * @see java.awt.Shape#getBounds2D()
183
     */
184 154
    public Rectangle2D getBounds2D() {
185
        return new Rectangle2D.Double(coordinates[0] - 0.01,
186
            coordinates[1] - 0.01, 0.02, 0.02);
155
        return new Rectangle2D.Double(x - 0.01, y - 0.01, 0.02, 0.02);
187 156
    }
188 157

  
189
    /*
190
     * (non-Javadoc)
191
     * 
192
     * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
193
     */
194 158
    public boolean contains(Rectangle2D r) {
195 159
        return false;
196 160
    }
197 161

  
198
    /*
199
     * (non-Javadoc)
200
     * 
201
     * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
202
     */
203 162
    public boolean intersects(Rectangle2D r) {
204
        return r.contains(coordinates[0], coordinates[1]);
163
        return r.contains(x, y);
205 164
    }
206 165

  
207
    /*
208
     * (non-Javadoc)
209
     * 
210
     * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
211
     */
166
    public Shape getShape(AffineTransform affineTransform) {
167
        return this;
168
    }
169

  
212 170
    public PathIterator getPathIterator(AffineTransform at) {
213 171
        return new PointIterator(getPoint2D(), at);
214 172
    }
215 173

  
216
    /*
217
     * (non-Javadoc)
218
     * 
219
     * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform,
220
     * double)
221
     */
222 174
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
223 175
        return new PointIterator(getPoint2D(), at);
224 176
    }
225 177

  
226 178
    private java.awt.geom.Point2D getPoint2D() {
227
        return new java.awt.geom.Point2D.Double(coordinates[0], coordinates[1]);
179
        return new java.awt.geom.Point2D.Double(x, y);
228 180
    }
229 181

  
230
    /**
231
     * @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
232
     */
233 182
    public int getShapeType() {
234 183
        return TYPES.POINT;
235 184
    }
236 185

  
237
    /*
238
     * (non-Javadoc)
239
     * 
240
     * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
241
     */
242 186
    public FShape cloneFShape() {
243
        return new Point2D(getGeometryType(), id, projection, coordinates[0],
244
            coordinates[1]);
187
        return new Point2D(getGeometryType(), id, projection, x, y);
245 188
    }
246 189

  
247
    /*
248
     * (non-Javadoc)
249
     * 
250
     * @see
251
     * com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans
252
     * )
253
     */
254 190
    public void reProject(ICoordTrans ct) {
255 191
        java.awt.geom.Point2D p = getPoint2D();
256 192
        p = ct.convert(p, p);
257
        coordinates[0] = p.getX();
258
        coordinates[1] = p.getY();
193
        this.x = p.getX();
194
        this.y = p.getY();
259 195
    }
260 196

  
261
    /*
262
     * (non-Javadoc)
263
     * 
264
     * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
265
     */
266 197
    public Handler[] getStretchingHandlers() {
267
        ArrayList handlers = new ArrayList();
268
        handlers.add(new PointHandler(0, coordinates[0], coordinates[1]));
269
        return (Handler[]) handlers.toArray(new Handler[0]);
198
        return new Handler[] { new PointHandler(0, x, y, this) };
270 199
    }
271 200

  
272
    /*
273
     * (non-Javadoc)
274
     * 
275
     * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
276
     */
277 201
    public Handler[] getSelectHandlers() {
278
        ArrayList handlers = new ArrayList();
279
        handlers.add(new PointHandler(0, coordinates[0], coordinates[1]));
280
        return (Handler[]) handlers.toArray(new Handler[0]);
202
        return new Handler[] { new PointHandler(0, x, y, this) };
281 203
    }
282 204

  
283 205
    /**
284
     * DOCUMENT ME!
285 206
     * 
286 207
     * @author Vicente Caballero Navarro
208
     * @author gvSIG team
287 209
     */
288 210
    class PointHandler extends AbstractHandler implements FinalHandler {
289 211

  
290
        /**
291
         * Crea un nuevo PointHandler.
292
         * 
293
         * @param x
294
         *            DOCUMENT ME!
295
         * @param y
296
         *            DOCUMENT ME!
297
         */
298
        public PointHandler(int i, double x, double y) {
212
        private final Point gvSIGPoint;
213

  
214
        public PointHandler(int i, double x, double y, Point gvSIGPoint) {
215
            this.gvSIGPoint = gvSIGPoint;
299 216
            point = new java.awt.geom.Point2D.Double(x, y);
300 217
            index = i;
301 218
        }
302 219

  
303
        /**
304
         * DOCUMENT ME!
305
         * 
306
         * @param x
307
         *            DOCUMENT ME!
308
         * @param y
309
         *            DOCUMENT ME!
310
         * 
311
         * @return DOCUMENT ME!
312
         */
313
        public void move(double x, double y) {
314
            coordinates[0] = coordinates[0] + x;
315
            coordinates[1] = coordinates[1] + y;
220
        public void move(double movex, double movey) {
221
            gvSIGPoint.setX(gvSIGPoint.getX() + movex);
222
            gvSIGPoint.setY(gvSIGPoint.getY() + movey);
316 223
        }
317 224

  
318
        /**
319
         * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
320
         */
321
        public void set(double x, double y) {
322
            coordinates[0] = x;
323
            coordinates[1] = y;
225
        public void set(double setx, double sety) {
226
            gvSIGPoint.setX(setx);
227
            gvSIGPoint.setY(sety);
324 228
        }
325 229
    }
326 230

  
327
    /*
328
     * (non-Javadoc)
329
     * 
330
     * @see org.gvsig.geometries.iso.GM_Object#coordinateDimension()
331
     */
332 231
    public int getDimension() {
333 232
        return 2;
334 233
    }
335 234

  
336 235
    public Envelope getEnvelope() {
337
        return new Envelope2D(coordinates[0] - 0.01, coordinates[1] - 0.01,
338
            coordinates[0] + 0.02, coordinates[1] + 0.02);
236
        return new Envelope2D(x - 0.01, y - 0.01, x + 0.02, y + 0.02);
339 237
    }
340 238

  
341 239
    public GeneralPathX getGeneralPath() {
342
        // TODO Auto-generated method stub
343 240
        return null;
344 241
    }
345 242

  
......
348 245
    }
349 246

  
350 247
    public double getOrdinate(int dim) {
351
        if (dim == 0) {
248
        if (dim == Geometry.DIMENSIONS.X) {
352 249
            return getX();
353 250
        } else
354
            if (dim == 1) {
251
            if (dim == Geometry.DIMENSIONS.Y) {
355 252
                return getY();
356 253
            } else {
357 254
                return 0;
......
373 270

  
374 271
    }
375 272

  
376
    /*
377
     * (non-Javadoc)
378
     * 
379
     * @see org.gvsig.fmap.geom.primitive.Point#getCoordinates()
380
     */
381 273
    public double[] getCoordinates() {
382
        return coordinates;
274
        return new double[] { x, y };
383 275
    }
384 276

  
385
    /*
386
     * (non-Javadoc)
387
     * 
388
     * @see org.gvsig.fmap.geom.primitive.Point#getDoordinateAt(int)
389
     */
390 277
    public double getCoordinateAt(int dimension) {
391
        return coordinates[dimension];
278
        switch (dimension) {
279
        case Geometry.DIMENSIONS.X:
280
            return x;
281
        case Geometry.DIMENSIONS.Y:
282
            return y;
283
        default:
284
            throw new ArrayIndexOutOfBoundsException(dimension);
285
        }
392 286
    }
393 287

  
394
    /*
395
     * (non-Javadoc)
396
     * 
397
     * @see org.gvsig.fmap.geom.primitive.Point#setCoordinateAt(int, double)
398
     */
399 288
    public void setCoordinateAt(int dimension, double value) {
400
        coordinates[dimension] = value;
289
        switch (dimension) {
290
        case Geometry.DIMENSIONS.X:
291
            this.x = value;
292
            break;
293
        case Geometry.DIMENSIONS.Y:
294
            this.y = value;
295
            break;
296
        default:
297
            throw new ArrayIndexOutOfBoundsException(dimension);
298
        }
401 299
    }
402 300

  
403
    /*
404
     * (non-Javadoc)
405
     * 
406
     * @see org.gvsig.fmap.geom.primitive.Point#setCoordinates(double[])
407
     */
408 301
    public void setCoordinates(double[] values) {
409
        coordinates = values;
302
        this.x = values[Geometry.DIMENSIONS.X];
303
        this.y = values[Geometry.DIMENSIONS.Y];
410 304
    }
411 305

  
412
    /*
413
     * (non-Javadoc)
414
     * 
415
     * @see org.gvsig.fmap.geom.primitive.Point#setX(double)
416
     */
417 306
    public void setX(double x) {
418
        coordinates[0] = x;
307
        this.x = x;
419 308
    }
420 309

  
421
    /*
422
     * (non-Javadoc)
423
     * 
424
     * @see org.gvsig.fmap.geom.primitive.Point#setY(double)
425
     */
426 310
    public void setY(double y) {
427
        coordinates[1] = y;
311
        this.y = y;
428 312
    }
429 313

  
430 314
    public String toString() {
431 315
        StringBuffer buffer = new StringBuffer();
432
        buffer.append("Point2D(");
433
        toStringCoordinates(buffer);
316
        double[] coordinates = getCoordinates();
317
        buffer.append(getFullTypeName()).append("(").append(coordinates[0]);
318
        for (int i = 1; i < coordinates.length; i++) {
319
            buffer.append(",").append(coordinates[i]);
320
        }
434 321
        buffer.append(")");
435 322
        return buffer.toString();
436 323
    }
437 324

  
438
    protected void toStringCoordinates(StringBuffer buffer) {
439
        buffer.append(coordinates[0]);
440
        for (int i = 1; i < coordinates.length; i++) {
441
            buffer.append(",").append(coordinates[i]);
442
        }
325
    protected String getFullTypeName() {
326
        return "Point2D";
443 327
    }
328
    
329
    public int getType() {
330
        return TYPES.POINT;
331
    }
444 332
}

Also available in: Unified diff