Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / snapping / SnappingVisitor.java @ 6771

History | View | Annotate | Download (1.34 KB)

1
package com.iver.cit.gvsig.gui.cad.snapping;
2

    
3
import java.awt.geom.Point2D;
4

    
5
import com.iver.cit.gvsig.fmap.core.IGeometry;
6
import com.vividsolutions.jts.index.ItemVisitor;
7

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

    
17
        ISnapperVectorial snapper;
18
        Point2D snapPoint = null;
19
        Point2D queryPoint = null;
20
        Point2D lastPointEntered = null;
21
        
22
        double minDist = Double.MAX_VALUE;
23
        double distActual;
24
        double tolerance;
25
        
26
        public SnappingVisitor(ISnapperVectorial snapper, Point2D queryPoint, double tolerance, Point2D lastPointEntered)
27
        {
28
                this.snapper = snapper;
29
                this.tolerance = tolerance;
30
                this.queryPoint = queryPoint;
31
                this.lastPointEntered = lastPointEntered;
32
                distActual = tolerance;
33
                // snapper.setSnapPoint(null);
34
        }
35
        
36
        public void visitItem(Object item) {
37
                IGeometry geom = (IGeometry) item;
38
                Point2D aux  = snapper.getSnapPoint(queryPoint, geom, distActual, lastPointEntered);
39
                if (aux != null)
40
                {
41
                        snapPoint = aux;
42
                        minDist = snapPoint.distance(queryPoint);
43
                        distActual = minDist;
44
                        // snapper.setSnapPoint(snapPoint);
45
                }
46
                
47
        }
48
        
49
        
50
        public Point2D getSnapPoint()
51
        {
52
                
53
                return snapPoint;
54
        }
55

    
56
//        public double getMinDist() {
57
//                return minDist;
58
//        }
59

    
60
}