source: trunk/src/org/expeditee/io/flowlayout/AreaPolygon.java@ 911

Last change on this file since 911 was 911, checked in by davidb, 10 years ago

Refactored name to correct spelling mistake

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1package org.expeditee.io.flowlayout;
2
3import java.awt.Point;
4import java.awt.Polygon;
5
6public class AreaPolygon extends Polygon
7{
8
9 private static final long serialVersionUID = 1863373131107377026L;
10
11 double area;
12
13 public AreaPolygon(Polygon polygon)
14 {
15 super(polygon.xpoints,polygon.ypoints,polygon.npoints);
16 area = calcArea();
17 }
18
19 protected double calcArea()
20 {
21 int n = npoints;
22 int[] x_pts = xpoints;
23 int[] y_pts = ypoints;
24
25 double area = 0;
26
27 for (int i = 0; i < n; i++) {
28 int j = (i + 1) % n;
29 area += x_pts[i] * y_pts[j];
30 area -= x_pts[j] * y_pts[i];
31 }
32
33 area /= 2.0;
34
35 return Math.abs(area);
36 }
37
38 public double getArea()
39 {
40 return area;
41 }
42
43 public boolean completelyContains(Polygon p)
44 {
45 boolean inside = true;
46
47 int p_n = p.npoints;
48 int[] p_x = p.xpoints;
49 int[] p_y = p.ypoints;
50
51 for (int i=0; i<p_n; i++) {
52 if (!contains(p_x[i],p_y[i])) {
53 inside = false;
54 break;
55 }
56 }
57
58 return inside;
59 }
60
61 public boolean isPerimeterPoint(Point pt)
62 {
63 int n = npoints;
64 int[] poly_x_pts = xpoints;
65 int[] poly_y_pts = ypoints;
66
67 boolean isVertex = false;
68
69
70 for (int i = 0; i < n; i++) {
71 if ((poly_x_pts[i]==pt.x) && (poly_y_pts[i]==pt.y)) {
72 isVertex = true;
73 break;
74 }
75 }
76
77 return isVertex;
78 }
79
80}
Note: See TracBrowser for help on using the repository browser.