1 package nl.tudelft.simulation.dsol.animation.gis;
2
3 import java.awt.geom.Rectangle2D;
4 import java.io.IOException;
5 import java.io.ObjectInputStream;
6 import java.io.ObjectOutputStream;
7 import java.io.Serializable;
8
9
10
11
12
13
14
15
16
17
18
19
20 public abstract class SerializableRectangle2d extends Rectangle2D implements Serializable
21 {
22
23 private static final long serialVersionUID = 20201015L;
24
25
26
27
28 protected SerializableRectangle2d()
29 {
30 super();
31 }
32
33
34
35
36
37 public static class Double extends SerializableRectangle2d implements Serializable
38 {
39
40 private static final long serialVersionUID = 20201015L;
41
42
43 private Rectangle2D.Double rectangle;
44
45
46
47
48 public Double()
49 {
50 this.rectangle = new Rectangle2D.Double();
51 }
52
53
54
55
56
57
58
59
60 public Double(final double x, final double y, final double w, final double h)
61 {
62 this.rectangle = new Rectangle2D.Double(x, y, w, h);
63 }
64
65
66 @Override
67 public Rectangle2D createIntersection(final Rectangle2D r)
68 {
69 return this.rectangle.createIntersection(r);
70 }
71
72
73 @Override
74 public Rectangle2D createUnion(final Rectangle2D r)
75 {
76 return this.rectangle.createUnion(r);
77 }
78
79
80 @Override
81 public Rectangle2D getBounds2D()
82 {
83 return this.rectangle.getBounds2D();
84 }
85
86
87 @Override
88 public double getHeight()
89 {
90 return this.rectangle.getHeight();
91 }
92
93
94 @Override
95 public double getWidth()
96 {
97 return this.rectangle.getWidth();
98 }
99
100
101 @Override
102 public double getX()
103 {
104 return this.rectangle.getX();
105 }
106
107
108 @Override
109 public double getY()
110 {
111 return this.rectangle.getY();
112 }
113
114
115 @Override
116 public boolean isEmpty()
117 {
118 return this.rectangle.isEmpty();
119 }
120
121
122 @Override
123 public int outcode(final double x, final double y)
124 {
125 return this.rectangle.outcode(x, y);
126 }
127
128
129 @Override
130 public void setRect(final double x, final double y, final double w, final double h)
131 {
132 this.rectangle.setRect(x, y, w, h);
133 }
134
135
136 @Override
137 public void setRect(final Rectangle2D r)
138 {
139 this.rectangle.setRect(r);
140 }
141
142
143 @Override
144 public String toString()
145 {
146 return this.rectangle.toString();
147 }
148
149
150
151
152
153
154 private void writeObject(final ObjectOutputStream out) throws java.io.IOException
155 {
156 out.writeDouble(this.rectangle.getX());
157 out.writeDouble(this.rectangle.getY());
158 out.writeDouble(this.rectangle.getWidth());
159 out.writeDouble(this.rectangle.getHeight());
160 }
161
162
163
164
165
166
167 private void readObject(final ObjectInputStream in) throws IOException
168 {
169 this.rectangle = new Rectangle2D.Double(in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble());
170 }
171 }
172
173
174
175
176
177 public static class Float extends SerializableRectangle2d
178 {
179
180
181 private Rectangle2D rectangle;
182
183
184
185
186 public Float()
187 {
188 this.rectangle = new Rectangle2D.Float();
189 }
190
191
192
193
194
195
196
197
198 public Float(final float x, final float y, final float w, final float h)
199 {
200 this.rectangle = new Rectangle2D.Float(x, y, w, h);
201 }
202
203
204 @Override
205 public Rectangle2D createIntersection(final Rectangle2D r)
206 {
207 return this.rectangle.createIntersection(r);
208 }
209
210
211 @Override
212 public Rectangle2D createUnion(final Rectangle2D r)
213 {
214 return this.rectangle.createUnion(r);
215 }
216
217
218 @Override
219 public Rectangle2D getBounds2D()
220 {
221 return this.rectangle.getBounds2D();
222 }
223
224
225 @Override
226 public double getHeight()
227 {
228 return this.rectangle.getHeight();
229 }
230
231
232 @Override
233 public double getWidth()
234 {
235 return this.rectangle.getWidth();
236 }
237
238
239 @Override
240 public double getX()
241 {
242 return this.rectangle.getX();
243 }
244
245
246 @Override
247 public double getY()
248 {
249 return this.rectangle.getY();
250 }
251
252
253 @Override
254 public boolean isEmpty()
255 {
256 return this.rectangle.isEmpty();
257 }
258
259
260 @Override
261 public int outcode(final double x, final double y)
262 {
263 return this.rectangle.outcode(x, y);
264 }
265
266
267
268
269
270
271
272 public void setRect(final float x, final float y, final float w, final float h)
273 {
274 this.rectangle.setRect(x, y, w, h);
275 }
276
277
278 @Override
279 public void setRect(final double x, final double y, final double w, final double h)
280 {
281 this.rectangle.setRect(x, y, w, h);
282 }
283
284
285 @Override
286 public void setRect(final Rectangle2D r)
287 {
288 this.rectangle.setRect(r);
289 }
290
291
292 @Override
293 public String toString()
294 {
295 return this.rectangle.toString();
296 }
297
298
299
300
301
302
303 private void writeObject(final ObjectOutputStream out) throws IOException
304 {
305 out.writeDouble(this.rectangle.getX());
306 out.writeDouble(this.rectangle.getY());
307 out.writeDouble(this.rectangle.getWidth());
308 out.writeDouble(this.rectangle.getHeight());
309 }
310
311
312
313
314
315
316 private void readObject(final ObjectInputStream in) throws IOException
317 {
318 this.rectangle = new Rectangle2D.Float();
319 this.rectangle.setRect(in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble());
320 }
321 }
322 }