1 package org.opentrafficsim.draw;
2
3 import org.djutils.draw.line.PolyLine2d;
4 import org.djutils.draw.point.Point2d;
5 import org.opentrafficsim.base.geometry.OtsShape;
6
7 /**
8 * This class returns a line that represent the object.
9 * <p>
10 * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12 * </p>
13 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
14 */
15 public interface LineLocatable extends OtsShape
16 {
17
18 /**
19 * Returns line representation of this object in object coordinates.
20 * @return line representation of this object in object coordinates
21 */
22 PolyLine2d getLine();
23
24 /**
25 * Signed distance function. The point must be relative. As this is a line object, only positive values are returned.
26 * @param point point for which distance is returned
27 * @return distance from point to these bounds
28 */
29 @Override
30 default double signedDistance(final Point2d point)
31 {
32 return getLine().closestPointOnPolyLine(point).distance(point);
33 }
34
35 @Override
36 default boolean contains(final Point2d point)
37 {
38 return signedDistance(point) < WORLD_MARGIN_LINE;
39 }
40
41 }