Revision 790
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPolyline2D.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.Rectangle; |
4 | 4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.Line2D; |
|
5 | 6 |
import java.awt.geom.PathIterator; |
6 | 7 |
import java.awt.geom.Point2D; |
7 | 8 |
import java.awt.geom.Rectangle2D; |
9 |
import java.util.ArrayList; |
|
8 | 10 |
|
9 | 11 |
|
10 | 12 |
|
... | ... | |
64 | 66 |
return gp.contains(r); |
65 | 67 |
} |
66 | 68 |
|
67 |
/* (non-Javadoc) |
|
68 |
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D) |
|
69 |
/** |
|
70 |
* El m?todo intersects de java.awt.Shape que define la intersecci?n entre una |
|
71 |
* polil?nea y un Rectangle2D considera la polil?nea como un Shape gen?rico y se |
|
72 |
* producen errores en la selecci?n de polil?neas. Por este motivo se ha modificado |
|
73 |
* este m?todo intersect() de FPolyline2D para que realize la intersecci?n estricta |
|
74 |
* entre el Rectangle2D y la polil?nea en cuesti?n. El precio es un incremento de |
|
75 |
* tiempo m?ximo del 50%. |
|
69 | 76 |
*/ |
70 | 77 |
public boolean intersects(Rectangle2D r) { |
71 |
return gp.intersects(r); |
|
78 |
//return gp.intersects(r); |
|
79 |
boolean bool = false; |
|
80 |
if (gp.intersects(r)) { |
|
81 |
ArrayList arrayCoords; |
|
82 |
int theType; |
|
83 |
//Use this array to store segment coordinate data |
|
84 |
double[] theData = new double[6]; |
|
85 |
PathIterator theIterator; |
|
86 |
|
|
87 |
Point2D p1 = new Point2D.Double(r.getMinX(),r.getMinY()); |
|
88 |
Point2D p2 = new Point2D.Double(r.getMinX(),r.getMaxY()); |
|
89 |
Point2D p3 = new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
90 |
Point2D p4 = new Point2D.Double(r.getMaxX(),r.getMinY()); |
|
91 |
Line2D l1 = new Line2D.Double(p1,p2); |
|
92 |
Line2D l2 = new Line2D.Double(p2,p3); |
|
93 |
Line2D l3 = new Line2D.Double(p3,p4); |
|
94 |
Line2D l4 = new Line2D.Double(p4,p1); |
|
95 |
|
|
96 |
theIterator = this.getPathIterator(null); |
|
97 |
arrayCoords = new ArrayList(); |
|
98 |
while(!theIterator.isDone()) { |
|
99 |
theType = theIterator.currentSegment(theData); |
|
100 |
if (theType==PathIterator.SEG_MOVETO) { |
|
101 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
102 |
} else if (theType==PathIterator.SEG_LINETO) { |
|
103 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
104 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-2); |
|
105 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),theData[0],theData[1]); |
|
106 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2()) |
|
107 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
|
108 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
|
109 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
|
110 |
|| r.intersectsLine(l)) { |
|
111 |
bool = true; |
|
112 |
} |
|
113 |
} else { |
|
114 |
System.out.println("Not supported here"); |
|
115 |
} |
|
116 |
theIterator.next(); |
|
117 |
} |
|
118 |
} |
|
119 |
return bool; |
|
72 | 120 |
} |
73 | 121 |
|
74 | 122 |
/* (non-Javadoc) |
Also available in: Unified diff