svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / geo / Polygon2D.java @ 40559
History | View | Annotate | Download (2.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.cresques.impl.geo; |
25 |
|
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.geom.GeneralPath; |
28 |
import java.awt.geom.Point2D; |
29 |
|
30 |
import java.util.Iterator; |
31 |
import java.util.Vector; |
32 |
|
33 |
import org.cresques.geo.ViewPortData; |
34 |
|
35 |
|
36 |
/**
|
37 |
* Clase que representa un pol?gono 2D
|
38 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
39 |
*/
|
40 |
public class Polygon2D extends Vector { |
41 |
GeneralPath gp = null; |
42 |
|
43 |
public Polygon2D() {
|
44 |
super();
|
45 |
gp = null;
|
46 |
} |
47 |
|
48 |
/**
|
49 |
* A?ade un vertice al po??gono
|
50 |
* @param pt punto 2D que representa el vertice a?adido
|
51 |
*/
|
52 |
public void addPoint(Point2D pt) { |
53 |
super.add(pt);
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Dibuja el pol?gono
|
58 |
* @param g Graphics sobre el que dibuja
|
59 |
* @param vp ViewPort con la vista
|
60 |
*/
|
61 |
public void draw(Graphics2D g, ViewPortData vp) { |
62 |
newGP(vp); |
63 |
g.draw(gp); |
64 |
|
65 |
//g.draw(new Line2D.Double(pt,pt0));
|
66 |
} |
67 |
|
68 |
/**
|
69 |
*
|
70 |
* @param g
|
71 |
* @param vp
|
72 |
*/
|
73 |
public void fill(Graphics2D g, ViewPortData vp) { |
74 |
newGP(vp); |
75 |
g.fill(gp); |
76 |
} |
77 |
|
78 |
/**
|
79 |
*
|
80 |
* @param vp
|
81 |
*/
|
82 |
private void newGP(ViewPortData vp) { |
83 |
//if (gp != null) return;
|
84 |
gp = new GeneralPath(); |
85 |
|
86 |
Point2D pt0 = null; |
87 |
Point2D pt = null; |
88 |
Point2D pt1 = null; |
89 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
90 |
Iterator iter = iterator();
|
91 |
|
92 |
while (iter.hasNext()) {
|
93 |
pt1 = (Point2D) iter.next();
|
94 |
vp.mat.transform(pt1, ptTmp); |
95 |
|
96 |
if (pt0 == null) { |
97 |
pt0 = ptTmp; |
98 |
gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
99 |
} else {
|
100 |
gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
101 |
} |
102 |
} |
103 |
|
104 |
gp.closePath(); |
105 |
} |
106 |
} |