Revision 44617 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/curve/spline/AbstractSpline.java

View differences:

AbstractSpline.java
33 33
import org.apache.commons.lang3.StringUtils;
34 34
import org.cresques.cts.ICoordTrans;
35 35
import org.gvsig.fmap.geom.Geometry;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38 36

  
39
import org.gvsig.fmap.geom.exception.ReprojectionRuntimeException;
40 37
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
41 38
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
42 39
import org.gvsig.fmap.geom.jts.primitive.curve.AbstractCurve;
......
49 46
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
50 47
import org.gvsig.fmap.geom.primitive.GeneralPathX;
51 48
import org.gvsig.fmap.geom.primitive.IGeneralPathX;
49
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
52 50
import org.gvsig.fmap.geom.primitive.Point;
53 51

  
54 52

  
......
63 61
     */
64 62
    private static final long serialVersionUID = -1562503359430991082L;
65 63

  
66
    private static final Logger logger = LoggerFactory.getLogger(AbstractSpline.class);
67

  
68 64
    protected ArrayListCoordinateSequence coordinates;
69 65
    protected PointJTS anyVertex;
70 66
    protected static final double SUBSEGMENTS = 30.0;
......
79 75

  
80 76
    /**
81 77
    *
78
     * @param type
79
     * @param subtype
80
     * @param coordinates
81
     * @param aVertex
82 82
    */
83 83
   public AbstractSpline(int type, int subtype, Coordinate[] coordinates, PointJTS aVertex) {
84 84
       this(type, subtype);
......
86 86
       anyVertex = aVertex;
87 87
   }
88 88

  
89
    /*
90
     * (non-Javadoc)
91
     *
92
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
93
     */
89
    @Override
94 90
    public com.vividsolutions.jts.geom.Geometry getJTS() {
95 91
        return JTSUtils.createJTSLineString(getSplineCoordinates());
96 92
    }
......
99 95

  
100 96

  
101 97
    static class Spline {
102
        private double y[];
103
        private double y2[];
98
        private final double y[];
99
        private final double y2[];
104 100

  
105 101
        /**
106 102
         * The constructor calculates the second derivatives of the interpolating function
......
136 132

  
137 133
    }
138 134

  
139
    /*
140
     * (non-Javadoc)
141
     *
142
     * @see
143
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(org.gvsig
144
     * .fmap.geom.primitive.Point)
145
     */
146
    public void addVertex(Point point) {
135
    public OrientablePrimitive addVertex(Point point) {
147 136
        point = fixPoint(point);
148 137
        coordinates.add(((PointJTS) point).getJTSCoordinate());
149 138
        anyVertex = (PointJTS) point;
139
        return (OrientablePrimitive) this;
150 140
    }
151 141

  
152
    /*
153
     * (non-Javadoc)
154
     *
155
     * @see
156
     * org.gvsig.fmap.geom.primitive.Curve#setPoints(org.gvsig.fmap.geom.primitive
157
     * .Point, org.gvsig.fmap.geom.primitive.Point)
158
     */
159 142
    public void setPoints(Point initialPoint, Point endPoint) {
160 143
        initialPoint = fixPoint(initialPoint);
161 144
        endPoint = fixPoint(endPoint);
......
166 149
    }
167 150

  
168 151
    /**
169
     * @param initialPoint
152
     * @param point
170 153
     * @return
171 154
     */
172 155
    protected abstract Point fixPoint(Point point);
173 156

  
174
    /*
175
     * (non-Javadoc)
176
     *
177
     * @see
178
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int,
179
     * int)
180
     */
181 157
    public double getCoordinateAt(int index, int dimension) {
182 158
        return coordinates.getOrdinate(index, dimension);
183 159
    }
184 160

  
185
    /*
186
     * (non-Javadoc)
187
     *
188
     * @see
189
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#setCoordinateAt(int,
190
     * int, double)
191
     */
192
    public void setCoordinateAt(int index, int dimension, double value) {
161
    public OrientablePrimitive setCoordinateAt(int index, int dimension, double value) {
193 162
        coordinates.setOrdinate(index, dimension, value);
163
        return (OrientablePrimitive) this;
194 164
    }
195 165

  
196
    /*
197
     * (non-Javadoc)
198
     *
199
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#removeVertex(int)
200
     */
201 166
    public void removeVertex(int index) {
202 167
        coordinates.remove(index);
203 168
    }
204 169

  
205
    /*
206
     * (non-Javadoc)
207
     *
208
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getNumVertices()
209
     */
210 170
    public int getNumVertices() {
211 171
        return coordinates.size();
212 172
    }
213 173

  
214
    /*
215
     * (non-Javadoc)
216
     *
217
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#insertVertex(int,
218
     * org.gvsig.fmap.geom.primitive.Point)
219
     */
220
    public void insertVertex(int index, Point p) {
174
    public OrientablePrimitive insertVertex(int index, Point p) {
221 175
        p = fixPoint(p);
222 176
        coordinates.add(index, ((PointJTS) p).getJTSCoordinate());
177
        return (OrientablePrimitive) this;
223 178
    }
224 179

  
225
    /*
226
     * (non-Javadoc)
227
     *
228
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#setVertex(int,
229
     * org.gvsig.fmap.geom.primitive.Point)
230
     */
231
    public void setVertex(int index, Point p) {
180
    public OrientablePrimitive setVertex(int index, Point p) {
232 181
        p = fixPoint(p);
233 182
        coordinates.set(index, ((PointJTS) p).getJTSCoordinate());
183
        return (OrientablePrimitive) this;
234 184
    }
235 185

  
236
    /*
237
     * (non-Javadoc)
238
     *
239
     * @see
240
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#setGeneralPath(org.
241
     * gvsig.fmap.geom.primitive.GeneralPathX)
242
     */
243 186
    public void setGeneralPath(GeneralPathX generalPathX) {
244 187

  
245 188
        PathIterator it = generalPathX.getPathIterator(null);
......
296 239
        }
297 240
    }
298 241

  
299
    /*
300
     * (non-Javadoc)
301
     *
302
     * @see
303
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#addMoveToVertex(org
304
     * .gvsig.fmap.geom.primitive.Point)
305
     */
306 242
    public void addMoveToVertex(Point point) {
307 243
        throw new UnsupportedOperationException();
308 244
    }
309 245

  
310
    /*
311
     * (non-Javadoc)
312
     *
313
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#closePrimitive()
314
     */
315 246
    public void closePrimitive() {
316 247
        if (!coordinates.isEmpty() && !isClosed()) {
317 248
            coordinates.add((Coordinate)coordinates.get(0).clone());
318 249
        }
319 250
    }
320 251

  
321
    /*
322
     * (non-Javadoc)
323
     *
324
     * @see
325
     * org.gvsig.fmap.geom.primitive.OrientablePrimitive#ensureCapacity(int)
326
     */
327
    public void ensureCapacity(int capacity) {
252
    public OrientablePrimitive ensureCapacity(int capacity) {
328 253
        coordinates.ensureCapacity(capacity);
254
        return (OrientablePrimitive) this;
329 255
    }
330 256

  
331
    /*
332
     * (non-Javadoc)
333
     *
334
     * @see org.gvsig.fmap.geom.Geometry#reProject(org.cresques.cts.ICoordTrans)
335
     */
257
    @Override
336 258
    public void reProject(ICoordTrans ct) {
337 259
        if (ct == null) {
338 260
            return;
339 261
        }
340 262
        ArrayListCoordinateSequence tmpCoordinates = new ArrayListCoordinateSequence();
341 263
        tmpCoordinates.ensureCapacity(coordinates.size());
342
        for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) {
343
            Coordinate coordinate = (Coordinate) iterator.next();
344

  
264
        for (Coordinate coordinate : coordinates) {
345 265
            java.awt.geom.Point2D p = new java.awt.geom.Point2D.Double(coordinate.x, coordinate.y);
346 266
            try {
347 267
                p = ct.convert(p, p);
......
350 270
                tmpCoordinates.add(coordinate);
351 271
            } catch (Exception exc) {
352 272
                /*
353
                 * This can happen when the reprojection lib is unable
354
                 * to reproject (for example the source point
355
                 * is out of the valid range and some computing
356
                 * problem happens)
357
                 */
273
                * This can happen when the reprojection lib is unable
274
                * to reproject (for example the source point
275
                * is out of the valid range and some computing
276
                * problem happens)
277
                */
358 278
            }
359 279
        }
360 280
        coordinates=tmpCoordinates;
361 281
        this.setProjection(ct.getPDest());
362 282
    }
363 283

  
364
    /*
365
     * (non-Javadoc)
366
     *
367
     * @see
368
     * org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
369
     */
284
    @Override
370 285
    public void transform(AffineTransform at) {
371 286
        if (at == null) {
372 287
            return;
373 288
        }
374 289

  
375
        for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) {
376
            Coordinate coordinate = (Coordinate) iterator.next();
290
        for (Coordinate coordinate : coordinates) {
377 291
            java.awt.geom.Point2D p = new java.awt.geom.Point2D.Double(coordinate.x, coordinate.y);
378 292

  
379 293
            at.transform(p, p);
......
382 296
        }
383 297
    }
384 298

  
385
    /*
386
     * (non-Javadoc)
387
     *
388
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
389
     */
299
    @Override
390 300
    public int getDimension() {
391 301
        return anyVertex.getDimension();
392 302
    }
393 303

  
394
    /*
395
     * (non-Javadoc)
396
     *
397
     * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
398
     */
304
    @Override
399 305
    public Shape getShape(AffineTransform affineTransform) {
400 306
        return new DefaultGeneralPathX(new SplineIterator(affineTransform),false,0);
401 307
    }
402 308

  
403
    /*
404
     * (non-Javadoc)
405
     *
406
     * @see org.gvsig.fmap.geom.Geometry#getShape()
407
     */
309
    @Override
408 310
    public Shape getShape() {
409 311
        return getShape(null);
410 312
    }
411 313

  
412
    /*
413
     * (non-Javadoc)
414
     *
415
     * @see
416
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
417
     * )
418
     */
314
    @Override
419 315
    public PathIterator getPathIterator(AffineTransform at) {
420 316
        SplineIterator pi = new SplineIterator(at);
421 317
        return pi;
422 318
    }
423 319

  
424
    /*
425
     * (non-Javadoc)
426
     *
427
     * @see
428
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
429
     * , double)
430
     */
320
    @Override
431 321
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
432 322
        return getPathIterator(at);
433 323
    }
434 324

  
435
    /*
436
     * (non-Javadoc)
437
     *
438
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
439
     */
325
    @Override
440 326
    public GeneralPathX getGeneralPath() {
441 327
        return new DefaultGeneralPathX(new SplineIterator(null),false,0);
442 328
    }
......
444 330
    public class SplineIterator extends GeneralPathXIterator {
445 331

  
446 332
        /** Transform applied on the coordinates during iteration */
447
        private AffineTransform at;
333
        private final AffineTransform at;
448 334

  
449 335
        /** True when the point has been read once */
450 336
        private boolean done;
......
452 338

  
453 339
        /**
454 340
         * Creates a new PointIterator object.
455
         *
456
         * @param p
457
         *            The polygon
458 341
         * @param at
459 342
         *            The affine transform applied to coordinates during
460 343
         *            iteration
......
474 357
         *
475 358
         * @return <code>WIND_EVEN_ODD</code> by default.
476 359
         */
360
        @Override
477 361
        public int getWindingRule() {
478 362
            return PathIterator.WIND_EVEN_ODD;
479 363
        }
480 364

  
481
        /**
482
         * @see java.awt.geom.PathIterator#next()
483
         */
365
        @Override
484 366
        public void next() {
485 367
            done = (getJTS().getCoordinates().length == ++index);
486 368
        }
487 369

  
488
        /**
489
         * @see java.awt.geom.PathIterator#isDone()
490
         */
370
        @Override
491 371
        public boolean isDone() {
492 372
            return done;
493 373
        }
494 374

  
495
        /**
496
         * @see java.awt.geom.PathIterator#currentSegment(double[])
497
         */
375
        @Override
498 376
        public int currentSegment(double[] coords) {
499 377
            Coordinate[] jtsCoordinates = getJTS().getCoordinates();
500 378
            coords[0] = jtsCoordinates[index].x;
......
508 386
            }
509 387
        }
510 388

  
511
        /*
512
         * (non-Javadoc)
513
         *
514
         * @see java.awt.geom.PathIterator#currentSegment(float[])
515
         */
389
        @Override
516 390
        public int currentSegment(float[] coords) {
517 391
            Coordinate[] jtsCoordinates = getJTS().getCoordinates();
518 392
            coords[0] = (float)jtsCoordinates[index].x;
......
528 402
    }
529 403

  
530 404

  
531
    /*
532
     * (non-Javadoc)
533
     *
534
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
535
     */
405
    @Override
536 406
    public boolean is3D() {
537 407
        return anyVertex.is3D();
538 408
    }
539 409

  
540 410

  
541
    /* (non-Javadoc)
542
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
543
     */
411
    @Override
544 412
    public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException {
545 413
        Collections.reverse(coordinates);
546 414
    }
......
548 416
    protected ArrayListCoordinateSequence cloneCoordinates() {
549 417
        ArrayListCoordinateSequence cloned = new ArrayListCoordinateSequence();
550 418
        cloned.ensureCapacity(coordinates.size());
551
        for (Iterator iterator = coordinates.iterator(); iterator.hasNext();) {
552
            Coordinate coordinate = (Coordinate) iterator.next();
419
        for (Coordinate coordinate : coordinates) {
553 420
            cloned.add((Coordinate)coordinate.clone());
554 421
        }
555 422
        return cloned;
......
559 426
    public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException {
560 427
        ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence();
561 428
        coordinates2D.ensureCapacity(coordinates.size());
562
        for (Iterator iterator = coordinates.iterator(); iterator.hasNext();) {
563
            Coordinate coordinate = (Coordinate) iterator.next();
429
        for (Coordinate coordinate : coordinates) {
564 430
            coordinates2D.add(new Coordinate(coordinate.x, coordinate.y));
565 431
        }
566 432
        Spline2D s = new Spline2D(coordinates2D);

Also available in: Unified diff