svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / Polygon2D.java @ 1732
History | View | Annotate | Download (1.12 KB)
1 |
package org.cresques.geo; |
---|---|
2 |
/*
|
3 |
* Created on 21-abr-2004
|
4 |
*/
|
5 |
|
6 |
import java.awt.Graphics2D; |
7 |
import java.awt.geom.GeneralPath; |
8 |
import java.awt.geom.Point2D; |
9 |
|
10 |
import java.util.Iterator; |
11 |
import java.util.Vector; |
12 |
|
13 |
/**
|
14 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
15 |
*/
|
16 |
|
17 |
public class Polygon2D extends Vector { |
18 |
GeneralPath gp = null; |
19 |
public Polygon2D() {
|
20 |
super();
|
21 |
gp = null;
|
22 |
} |
23 |
|
24 |
public void addPoint(Point2D pt) {super.add(pt);} |
25 |
|
26 |
public void draw(Graphics2D g, ViewPortData vp) { |
27 |
newGP(vp); |
28 |
g.draw(gp); |
29 |
//g.draw(new Line2D.Double(pt,pt0));
|
30 |
} |
31 |
|
32 |
public void fill(Graphics2D g, ViewPortData vp) { |
33 |
newGP(vp); |
34 |
g.fill(gp); |
35 |
} |
36 |
|
37 |
private void newGP(ViewPortData vp) { |
38 |
//if (gp != null) return;
|
39 |
gp = new GeneralPath(); |
40 |
Point2D pt0 = null, pt=null, pt1=null; |
41 |
Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0); |
42 |
Iterator iter = iterator();
|
43 |
while (iter.hasNext()) {
|
44 |
pt1 = (Point2D) iter.next();
|
45 |
vp.mat.transform(pt1, ptTmp); |
46 |
if (pt0 == null) { |
47 |
pt0 = ptTmp; |
48 |
gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
49 |
} else {
|
50 |
gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY()); |
51 |
} |
52 |
} |
53 |
gp.closePath(); |
54 |
} |
55 |
} |
56 |
|
57 |
|