View Javadoc

1   package org.catacomb.interlish.content;
2   
3   
4   import java.util.ArrayList;
5   
6   import org.catacomb.datalish.SColor;
7   
8   public class RShape {
9   
10      public static final int OPEN = 0;
11      public static final int CLOSED = 1;
12      public static final int FILLED = 2;
13  
14      double[] xpts;
15      double[] ypts;
16  
17      double lineWidth;
18      SColor lineColor;
19      SColor fillColor;
20  
21      int closure;
22  
23  
24      public RShape(double[] x, double[] y, double lineW,
25                    SColor lineC, SColor fillC, int rsc) {
26          xpts = x;
27          ypts = y;
28          lineWidth = lineW;
29          lineColor = lineC;
30          fillColor = fillC;
31          closure = rsc;
32      }
33  
34  
35      public double[] getXPts() {
36          return xpts;
37      }
38  
39      public double[] getYPts() {
40          return ypts;
41      }
42  
43      public double getLineWidth() {
44          return lineWidth;
45      }
46  
47      public SColor getLineColor() {
48          return lineColor;
49      }
50  
51      public SColor getFillColor() {
52          return fillColor;
53      }
54  
55      public int getOCF() {
56          return closure; // ADHOC ocf expects 0, 1, 2 for Open, Closed, Filled;
57      }
58  
59      public double meanRadius() {
60          double d = 0.;
61          for (int i = 0; i < xpts.length; i++) {
62              d += Math.sqrt(xpts[i] * xpts[i] + ypts[i] * ypts[i]);
63          }
64          d /= xpts.length;
65          return d;
66      }
67  
68  
69      public ArrayList<double[]> getBoundarySegments() {
70          ArrayList<double[]> ret = new ArrayList<double[]>();
71          for (int i = 0; i < xpts.length-1; i++) {
72              double[] seg = {xpts[i], ypts[i], xpts[i+1], ypts[i+1]};
73              ret.add(seg);
74          }
75          if (closure == CLOSED || closure == FILLED) {
76              int n = xpts.length;
77              double[] cseg = {xpts[n-1], ypts[n-1], xpts[0], ypts[0]};
78              ret.add(cseg);
79          }
80          return ret;
81      }
82  
83  
84  }