1 package org.opentrafficsim.draw;
2
3 import org.djutils.draw.bounds.Bounds2d;
4 import org.opentrafficsim.base.geometry.OtsLocatable;
5 import org.opentrafficsim.base.geometry.OtsShape;
6
7
8
9
10
11
12
13
14
15
16 public interface ClickableLocatable extends OtsLocatable
17 {
18
19
20 double EXPANSE = 2.0;
21
22 @Override
23 default Bounds2d getBounds()
24 {
25 return getBounds(this);
26 }
27
28
29
30
31
32
33 static Bounds2d getBounds(final ClickableLocatable locatable)
34 {
35
36
37
38
39
40
41 OtsShape shape = locatable.getShape();
42 double deltaX = shape.getMaxX() - shape.getMinX();
43 double deltaY = shape.getMaxY() - shape.getMinY();
44 boolean xExpand = deltaX < EXPANSE;
45 boolean yExpand = deltaY < EXPANSE;
46 return new Bounds2d(xExpand ? EXPANSE : deltaX, yExpand ? EXPANSE : deltaY)
47 {
48
49 private static final long serialVersionUID = 20241006L;
50
51 @Override
52 public boolean contains(final double x, final double y)
53 {
54 if (xExpand || yExpand)
55 {
56 return getMinX() <= x && x <= getMaxX() && getMinY() <= y && y <= getMaxY();
57 }
58 return shape.contains(x, y);
59 }
60 };
61 }
62
63 }