root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPolyline2D.java @ 2196
History | View | Annotate | Download (6.51 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.core; |
42 |
|
43 |
import org.cresques.cts.ICoordTrans; |
44 |
|
45 |
import java.awt.Rectangle; |
46 |
import java.awt.geom.AffineTransform; |
47 |
import java.awt.geom.PathIterator; |
48 |
import java.awt.geom.Line2D; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.util.ArrayList; |
52 |
|
53 |
|
54 |
/**
|
55 |
* DOCUMENT ME!
|
56 |
*
|
57 |
* @author Fernando Gonz?lez Cort?s
|
58 |
*/
|
59 |
public class FPolyline2D implements FShape { |
60 |
protected GeneralPathX gp;
|
61 |
/**
|
62 |
* Crea un nuevo FPolyline2D.
|
63 |
*
|
64 |
* @param gpx GeneralPathX.
|
65 |
*/
|
66 |
public FPolyline2D(GeneralPathX gpx) {
|
67 |
gp = gpx; |
68 |
} |
69 |
|
70 |
/* (non-Javadoc)
|
71 |
* @see java.awt.Shape#contains(double, double)
|
72 |
*/
|
73 |
public boolean contains(double x, double y) { |
74 |
return gp.contains(x, y);
|
75 |
} |
76 |
|
77 |
/* (non-Javadoc)
|
78 |
* @see java.awt.Shape#contains(double, double, double, double)
|
79 |
*/
|
80 |
public boolean contains(double x, double y, double w, double h) { |
81 |
return gp.contains(x, y, w, h);
|
82 |
} |
83 |
|
84 |
/* (non-Javadoc)
|
85 |
* @see java.awt.Shape#intersects(double, double, double, double)
|
86 |
*/
|
87 |
public boolean intersects(double x, double y, double w, double h) { |
88 |
// M?s r?pido
|
89 |
return gp.intersects(x, y, w, h);
|
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see java.awt.Shape#getBounds()
|
94 |
*/
|
95 |
public Rectangle getBounds() { |
96 |
return gp.getBounds();
|
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
101 |
*/
|
102 |
public boolean contains(Point2D p) { |
103 |
return gp.contains(p);
|
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see java.awt.Shape#getBounds2D()
|
108 |
*/
|
109 |
public Rectangle2D getBounds2D() { |
110 |
return gp.getBounds2D();
|
111 |
} |
112 |
|
113 |
/* (non-Javadoc)
|
114 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
115 |
*/
|
116 |
public boolean contains(Rectangle2D r) { |
117 |
return gp.contains(r);
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* El m?todo intersects de java.awt.Shape que define la intersecci?n entre
|
122 |
* una polil?nea y un Rectangle2D considera la polil?nea como un Shape
|
123 |
* gen?rico y se producen errores en la selecci?n de polil?neas. Por este
|
124 |
* motivo se ha modificado este m?todo intersect() de FPolyline2D para que
|
125 |
* realize la intersecci?n estricta entre el Rectangle2D y la polil?nea en
|
126 |
* cuesti?n. El precio es un incremento de tiempo m?ximo del 50%.
|
127 |
*
|
128 |
* @param r Rect?ngulo.
|
129 |
*
|
130 |
* @return True si intersecta con el rectangulo que se pasa como par?metro.
|
131 |
*/
|
132 |
public boolean intersects(Rectangle2D r) { |
133 |
//return gp.intersects(r);
|
134 |
// M?s exacto
|
135 |
boolean bool = false; |
136 |
if (gp.intersects(r)) {
|
137 |
ArrayList arrayCoords;
|
138 |
int theType;
|
139 |
//Use this array to store segment coordinate data
|
140 |
double[] theData = new double[6]; |
141 |
PathIterator theIterator;
|
142 |
|
143 |
Point2D p1 = new Point2D.Double(r.getMinX(),r.getMinY()); |
144 |
Point2D p2 = new Point2D.Double(r.getMinX(),r.getMaxY()); |
145 |
Point2D p3 = new Point2D.Double(r.getMaxX(),r.getMaxY()); |
146 |
Point2D p4 = new Point2D.Double(r.getMaxX(),r.getMinY()); |
147 |
Line2D l1 = new Line2D.Double(p1,p2); |
148 |
Line2D l2 = new Line2D.Double(p2,p3); |
149 |
Line2D l3 = new Line2D.Double(p3,p4); |
150 |
Line2D l4 = new Line2D.Double(p4,p1); |
151 |
|
152 |
theIterator = this.getPathIterator(null); |
153 |
arrayCoords = new ArrayList(); |
154 |
while(!theIterator.isDone()) {
|
155 |
theType = theIterator.currentSegment(theData); |
156 |
if (theType==PathIterator.SEG_MOVETO) { |
157 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
158 |
} else if (theType==PathIterator.SEG_LINETO) { |
159 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
160 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-2); |
161 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),theData[0],theData[1]); |
162 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2())
|
163 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
164 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
165 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
166 |
|| r.intersectsLine(l)) { |
167 |
bool = true;
|
168 |
} |
169 |
} else {
|
170 |
System.out.println("Not supported here"); |
171 |
} |
172 |
theIterator.next(); |
173 |
} |
174 |
} |
175 |
return bool;
|
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
180 |
*/
|
181 |
public PathIterator getPathIterator(AffineTransform at) { |
182 |
return gp.getPathIterator(at);
|
183 |
} |
184 |
|
185 |
/* (non-Javadoc)
|
186 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
|
187 |
*/
|
188 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
189 |
return gp.getPathIterator(at, flatness);
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* DOCUMENT ME!
|
194 |
*
|
195 |
* @param at DOCUMENT ME!
|
196 |
*/
|
197 |
public void transform(AffineTransform at) { |
198 |
gp.transform(at); |
199 |
} |
200 |
|
201 |
/**
|
202 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
203 |
*/
|
204 |
public int getShapeType() { |
205 |
return FShape.LINE;
|
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
210 |
*/
|
211 |
public FShape cloneFShape() {
|
212 |
return new FPolyline2D((GeneralPathX) gp.clone()); |
213 |
} |
214 |
|
215 |
/* (non-Javadoc)
|
216 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
217 |
*/
|
218 |
public void reProject(ICoordTrans ct) { |
219 |
gp.reProject(ct); |
220 |
} |
221 |
|
222 |
} |