1
2 package org.catacomb.graph.gui;
3
4
5 import org.catacomb.be.Position;
6 import org.catacomb.report.E;
7 import org.catacomb.util.MathUtil;
8
9
10 public final class PickableRegion implements Pickable {
11
12 double[] xb;
13 double[] yb;
14 String label;
15
16 String tag;
17
18 double xref;
19 double yref;
20
21
22 Object oref;
23
24 int icache;
25
26
27
28 public PickableRegion(double[][] axay, Object obj) {
29 this(axay[0], axay[1], obj);
30 }
31
32
33
34 public PickableRegion(double[] axb, double[] ayb, Object obj) {
35 if (axb == null || axb.length < 2) {
36 E.error("need at least 2 elts but got " + axb);
37 }
38
39 if (axb.length < 3) {
40 xb = mmxx(axb);
41 yb = mxxm(ayb);
42 } else {
43 xb = axb;
44 yb = ayb;
45 }
46 oref = obj;
47
48
49
50
51 xref = xb[0];
52 yref = yb[0];
53 }
54
55
56
57 public double[] getXPts() {
58 return xb;
59 }
60
61 public double[] getYPts() {
62 return yb;
63 }
64
65
66 public boolean contains(double xq, double yq) {
67 return Geom.pointIsInside(xb, yb, xq, yq);
68 }
69
70
71
72 public void setReferencePoint(Position p) {
73 setReferencePoint(p.getX(), p.getY());
74 }
75
76
77 public Position getReferencePoint() {
78 return new Position(xref, yref);
79 }
80
81
82 public void setPoints(double[][] axy) {
83 xb = axy[0];
84 yb = axy[1];
85 }
86
87 public void setPoints(double[] ax, double[] ay) {
88 xb = ax;
89 yb = ay;
90 }
91
92 public void setReferencePoint(double xr, double yr) {
93 xref = xr;
94 yref = yr;
95 }
96
97 public void moveTo(Position pos) {
98 moveTo(pos.getX(), pos.getY());
99 }
100
101 public void moveTo(double cx, double cy) {
102 double dx = cx - xref;
103 double dy = cy - yref;
104 for (int i = 0; i < xb.length; i++) {
105 xb[i] += dx;
106 yb[i] += dy;
107 }
108 xref = cx;
109 yref = cy;
110 }
111
112 public void scaleTo(double z) {
113 scaleTo(z, z);
114 }
115
116 public void scaleTo(double xsz, double ysz) {
117 MathUtil.scaleRangeTo(2. * xsz, xb);
118 MathUtil.scaleRangeTo(2. * ysz, yb);
119 }
120
121
122
123 public double getXReference() {
124 return xref;
125 }
126
127 public double getYReference() {
128 return yref;
129 }
130
131
132 public Object getRef() {
133 return oref;
134 }
135
136
137 public void setCache(int ic) {
138 icache = ic;
139 }
140
141 public int getCache() {
142 return icache;
143 }
144
145
146
147
148
149 public double[] mxxm(double[] v) {
150 double min = MathUtil.min(v);
151 double max = MathUtil.max(v);
152 double[] ret = {min, max, max, min};
153 return ret;
154 }
155
156
157 public double[] mmxx(double[] v) {
158 double min = MathUtil.min(v);
159 double max = MathUtil.max(v);
160 double[] ret = {min, min, max, max};
161 return ret;
162 }
163
164
165
166 public void setRegionTag(String s) {
167 tag = s;
168 }
169
170 public String getRegionTag() {
171 return tag;
172 }
173
174
175 }