/Users/lyon/j4p/src/ip/transforms/Polygons.java
|
1 package ip.transforms;
2
3
4 import java.awt.*;
5 import java.util.Enumeration;
6 import java.util.Vector;
7
8
9 public class Polygons {
10 private Vector v = new Vector();
11 private Enumeration e = null;
12
13 public void addElement(Polygon p) {
14 v.addElement(p);
15 }
16
17 public void removeElementAt(int i) {
18 v.removeElementAt(i);
19 }
20
21 public Polygon elementAt(int i) {
22 return (Polygon) v.elementAt(i);
23 }
24
25 public boolean hasMore() {
26 return e.hasMoreElements();
27 }
28
29 public Polygon next() {
30 if (e == null) e = getEnumeration();
31 if (!hasMore()) return null;
32 return (Polygon) e.nextElement();
33 }
34
35 private Enumeration getEnumeration() {
36 return v.elements();
37 }
38
39 public int size() {
40 return v.size();
41 }
42
43 public void drawPolys(Graphics g) {
44 g.setColor(Color.green);
45 Polygon p;
46 for (int i = 0; i < v.size(); i++) {
47 p = (Polygon) v.elementAt(i);
48 g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
49 }
50 }
51
52 public void listPolys() {
53 for (int i = 0; i < v.size(); i++)
54 printPoly((Polygon) v.elementAt(i));
55 }
56
57 private void printPoly(Polygon p) {
58 System.out.println("i x y");
59 int n = p.npoints;
60 for (int i = 0; i < n - 1; i++)
61 System.out.println(i + " " + p.xpoints[i] + " " + p.ypoints[i]);
62 System.out.println(n - 1 + " " + p.xpoints[n - 1] + " " + p.ypoints[n - 1]);
63 }
64
65 public static void drawPoly(Graphics g, Polygon p) {
66 g.setColor(Color.green);
67 g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
68 }
69
70 public void polyStats() {
71 int numberOfPolys = size();
72 Polygon p;
73 int n = 0;
74 int maxN = 0;
75 int minN = 10000;
76 for (int i = 0; i < numberOfPolys; i++) {
77 p = (Polygon) elementAt(i);
78 n += p.npoints;
79 if (p.npoints > maxN) maxN = p.npoints;
80 if (p.npoints < minN) minN = p.npoints;
81 }
82
83 int avgSize = n / numberOfPolys;
84 System.out.println("numberOfPolys=" + numberOfPolys);
85 System.out.println("numberOfPoints=" + n);
86 System.out.println("avgSize=" + avgSize);
87 System.out.println("maxN=" + maxN);
88 System.out.println("minN=" + minN);
89 }
90
91
92 }
93
94
95
96