svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / snapping / SnappingVisitor.java @ 5223
History | View | Annotate | Download (1.13 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 |
ISnapper snapper; |
18 |
Point2D snapPoint = null; |
19 |
Point2D queryPoint = null; |
20 |
double minDist = Double.MAX_VALUE; |
21 |
double distActual;
|
22 |
double tolerance;
|
23 |
|
24 |
public SnappingVisitor(ISnapper snapper, Point2D queryPoint, double tolerance) |
25 |
{ |
26 |
this.snapper = snapper;
|
27 |
this.tolerance = tolerance;
|
28 |
this.queryPoint = queryPoint;
|
29 |
distActual = tolerance; |
30 |
} |
31 |
|
32 |
public void visitItem(Object item) { |
33 |
IGeometry geom = (IGeometry) item; |
34 |
Point2D aux = snapper.getSnapPoint(queryPoint, geom, distActual);
|
35 |
if (aux != null) |
36 |
{ |
37 |
snapPoint = aux; |
38 |
minDist = snapPoint.distance(queryPoint); |
39 |
distActual = minDist; |
40 |
} |
41 |
|
42 |
} |
43 |
|
44 |
|
45 |
public Point2D getSnapPoint() |
46 |
{ |
47 |
|
48 |
return snapPoint;
|
49 |
} |
50 |
|
51 |
public double getMinDist() { |
52 |
return minDist;
|
53 |
} |
54 |
|
55 |
} |