Statistics
| Revision:

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 2 luisw
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 91 luisw
        public void draw(Graphics2D g, ViewPortData vp) {
27 32 luisw
                newGP(vp);
28 2 luisw
                g.draw(gp);
29
                //g.draw(new Line2D.Double(pt,pt0));
30
        }
31
32 91 luisw
        public void fill(Graphics2D g, ViewPortData vp) {
33 32 luisw
                newGP(vp);
34 2 luisw
                g.fill(gp);
35
        }
36
37 91 luisw
        private void newGP(ViewPortData vp) {
38 32 luisw
                //if (gp != null) return;
39 2 luisw
                gp = new GeneralPath();
40
                Point2D pt0 = null, pt=null, pt1=null;
41 32 luisw
                Point2D.Double ptTmp = new Point2D.Double(0.0, 0.0);
42 2 luisw
                Iterator iter = iterator();
43
                while (iter.hasNext()) {
44
                        pt1 = (Point2D) iter.next();
45 32 luisw
                        vp.mat.transform(pt1, ptTmp);
46 2 luisw
                        if (pt0 == null) {
47 32 luisw
                                pt0 = ptTmp;
48
                                gp.moveTo((float)ptTmp.getX(), (float)ptTmp.getY());
49 2 luisw
                        } else {
50 32 luisw
                                gp.lineTo((float)ptTmp.getX(), (float)ptTmp.getY());
51 2 luisw
                        }
52
                }
53
                gp.closePath();
54
        }
55
}
56