Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontrol / src / org / gvsig / fmap / mapcontrol / tools / snapping / SnappingVisitor.java @ 23645

History | View | Annotate | Download (1.46 KB)

1
package org.gvsig.fmap.mapcontrol.tools.snapping;
2

    
3
import java.awt.geom.Point2D;
4

    
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial;
7

    
8
import com.vividsolutions.jts.index.ItemVisitor;
9

    
10
/**
11
 * @author fjp
12
 *
13
 * Visitor adecuado para recorrer el ?ndice espacial de JTS y no obligar
14
 * a dar 2 pasadas. En la misma pasada que se visita, se calcula la distancia
15
 * m?nima.
16
 */
17
public class SnappingVisitor implements ItemVisitor {
18

    
19
        ISnapperVectorial snapper;
20
        Point2D snapPoint = null;
21
        Point2D queryPoint = null;
22
        Point2D lastPointEntered = null;
23

    
24
        double minDist = Double.MAX_VALUE;
25
        double distActual;
26
        double tolerance;
27

    
28
        public SnappingVisitor(ISnapperVectorial snapper, Point2D queryPoint, double tolerance, Point2D lastPointEntered)
29
        {
30
                this.snapper = snapper;
31
                this.tolerance = tolerance;
32
                this.queryPoint = queryPoint;
33
                this.lastPointEntered = lastPointEntered;
34
                distActual = tolerance;
35
                // snapper.setSnapPoint(null);
36
        }
37

    
38
        public void visitItem(Object item) {
39
                Geometry geom = (Geometry) item;
40
                Point2D aux  = snapper.getSnapPoint(queryPoint, geom, distActual, lastPointEntered);
41
                if (aux != null)
42
                {
43
                        snapPoint = aux;
44
                        minDist = snapPoint.distance(queryPoint);
45
                        distActual = minDist;
46
                        // snapper.setSnapPoint(snapPoint);
47
                }
48

    
49
        }
50

    
51

    
52
        public Point2D getSnapPoint()
53
        {
54

    
55
                return snapPoint;
56
        }
57

    
58
//        public double getMinDist() {
59
//                return minDist;
60
//        }
61

    
62
}