1 package org.opentrafficsim.draw;
2
3 import org.djutils.draw.bounds.Bounds2d;
4 import org.djutils.draw.line.PolyLine2d;
5 import org.djutils.draw.point.Point2d;
6 import org.opentrafficsim.base.geometry.OtsShape;
7
8 /**
9 * This class returns bounds that respond to {@code contains(x, y)} by checking a clickable expanse around a line.
10 * <p>
11 * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13 * </p>
14 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
15 */
16 public interface ClickableLineLocatable extends ClickableLocatable
17 {
18
19 @Override
20 default Bounds2d getBounds()
21 {
22 OtsShape shape = getShape();
23 return new Bounds2d(shape.getMaxX() - shape.getMinX(), shape.getMaxY() - shape.getMinY())
24 {
25 /** */
26 private static final long serialVersionUID = 20241006L;
27
28 @Override
29 public boolean contains(final double x, final double y)
30 {
31 Point2d point = new Point2d(x, y);
32 return getLine().closestPointOnPolyLine(point).distance(point) < 0.5 * EXPANSE; // 0.5 as on both sides of line
33 }
34 };
35 }
36
37 /**
38 *
39 * Returns line representation of this object in object coordinates.
40 * @return line representation of this object in object coordinates.
41 */
42 PolyLine2d getLine();
43
44 }