1 package org.catacomb.graph.drawing;
2
3
4 import org.catacomb.be.Position;
5 import org.catacomb.graph.gui.Painter;
6 import org.catacomb.report.E;
7 import org.catacomb.util.ArrayUtil;
8
9
10
11 public class GenericShape extends FixedDrawingComponent {
12
13
14
15
16 public double curviness;
17
18 public String closure;
19
20 public String symmetry;
21
22
23 public double[] xpts;
24 public double[] ypts;
25
26
27 public GenericShape() {
28 }
29
30
31 public GenericShape(Shape sh, Position cpos, double scl) {
32 double[][] bdry = sh.getBoundaryPoints();
33 xpts = fromScaledPoints(bdry[0], cpos.getX(), scl);
34 ypts = fromScaledPoints(bdry[1], cpos.getY(), scl);
35
36
37
38 curviness = sh.getCurviness();
39 setLineColor(sh.getLineColor());
40 setLineWidth(sh.getLineWidth());
41 if (sh.isFilled()) {
42 setFilled();
43 setFillColor(sh.getFillColor());
44
45 } else if (sh.isClosed()) {
46 setClosed();
47 } else {
48 setOpen();
49 }
50 }
51
52
53
54 private double[] fromScaledPoints(double[] va, double c, double scl) {
55 int n = va.length;
56 double[] ret = new double[n];
57 for (int i = 0; i < n; i++) {
58 ret[i] = (va[i] - c) / scl;
59 }
60 return ret;
61 }
62
63
64 public void reReference() {
65 super.reReference();
66
67 setFilled();
68 if (closure != null) {
69 if (closure.equals("open")) {
70 setOpen();
71
72 } else if (closure.equals("filled")) {
73 setFilled();
74
75 } else if (closure.equals("closed")) {
76 setClosed();
77
78 } else {
79 E.warning("unrecognized closure " + closure);
80 }
81 }
82 }
83
84
85
86
87
88 public void instruct(Painter p, double offx, double offy, double scale) {
89 int np = xpts.length;
90 double[] xdr = new double[np];
91 double[] ydr = new double[np];
92 for (int i = 0; i < np; i++) {
93 xdr[i] = offx + scale * xpts[i];
94 ydr[i] = offy + scale * ypts[i];
95 }
96 if (isFilled()) {
97 p.fillPolygon(xdr, ydr, np, getFillColor());
98 }
99
100 if (p_width > 0.5) {
101 if (isClosed() || isFilled()) {
102 p.drawPolygon(xdr, ydr, np, p_color, p_width, true);
103 } else {
104 p.drawPolyline(xdr, ydr, np, p_color, p_width, true);
105 }
106 }
107
108
109
110
111
112
113
114 }
115
116
117
118
119 public void applyToShape(Shape shp) {
120 shp.setCurviness(curviness);
121 shp.setSymmetryString(symmetry);
122
123 shp.setXpts(ArrayUtil.copyDArray(xpts));
124 shp.setYpts(ArrayUtil.copyDArray(ypts));
125 }
126
127
128
129
130 }