svn-gvsig-desktop / branches / libProjection_v2_0_prep / libraries / libProjection / src / org / cresques / impl / geo / Polygon2D.java @ 27135
History | View | Annotate | Download (2.64 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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 2
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.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 |
import java.util.Iterator; |
30 |
import java.util.Vector; |
31 |
|
32 |
import org.cresques.geo.ViewPortData; |
33 |
|
34 |
|
35 |
/**
|
36 |
* Clase que representa un pol?gono 2D
|
37 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
38 |
*/
|
39 |
public class Polygon2D extends Vector { |
40 |
GeneralPath gp = null; |
41 |
|
42 |
public Polygon2D() {
|
43 |
super();
|
44 |
gp = null;
|
45 |
} |
46 |
|
47 |
/**
|
48 |
* A?ade un vertice al po??gono
|
49 |
* @param pt punto 2D que representa el vertice a?adido
|
50 |
*/
|
51 |
public void addPoint(Point2D pt) { |
52 |
super.add(pt);
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Dibuja el pol?gono
|
57 |
* @param g Graphics sobre el que dibuja
|
58 |
* @param vp ViewPort con la vista
|
59 |
*/
|
60 |
public void draw(Graphics2D g, ViewPortData vp) { |
61 |
newGP(vp); |
62 |
g.draw(gp); |
63 |
|
64 |
//g.draw(new Line2D.Double(pt,pt0));
|
65 |
} |
66 |
|
67 |
/**
|
68 |
*
|
69 |
* @param g
|
70 |
* @param vp
|
71 |
*/
|
72 |
public void fill(Graphics2D g, ViewPortData vp) { |
73 |
newGP(vp); |
74 |
g.fill(gp); |
75 |
} |
76 |
|
77 |
/**
|
78 |
*
|
79 |
* @param vp
|
80 |
*/
|
81 |
private void newGP(ViewPortData vp) { |
82 |
//if (gp != null) return;
|
83 |
gp = new GeneralPath(); |
84 |
|
85 |
Point2D pt0 = null; |
86 |
Point2D pt = null; |
87 |
Point2D pt1 = null; |
88 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
89 |
Iterator iter = iterator();
|
90 |
|
91 |
while (iter.hasNext()) {
|
92 |
pt1 = (Point2D) iter.next();
|
93 |
vp.mat.transform(pt1, ptTmp); |
94 |
|
95 |
if (pt0 == null) { |
96 |
pt0 = ptTmp; |
97 |
gp.moveTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
98 |
} else {
|
99 |
gp.lineTo((float) ptTmp.getX(), (float) ptTmp.getY()); |
100 |
} |
101 |
} |
102 |
|
103 |
gp.closePath(); |
104 |
} |
105 |
} |