1 package org.opentrafficsim.road.network.lane.object;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.exceptions.Throw;
5 import org.opentrafficsim.core.network.LateralDirectionality;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.opentrafficsim.road.network.lane.LanePosition;
8
9 /**
10 * Local distraction.
11 * <p>
12 * Copyright (c) 2024-2025s Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14 * </p>
15 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
16 */
17 public class LocalDistraction extends AbstractLaneBasedObject
18 {
19
20 /** Range of the distraction (upstream of the location). */
21 private final Length range;
22
23 /** Level of the distraction. */
24 private final double distractionLevel;
25
26 /** Side of the distraction. */
27 private final LateralDirectionality side;
28
29 /**
30 * Constructor.
31 * @param id id
32 * @param position position
33 * @param range range of the distraction (upstream of the location)
34 * @param distractionLevel level of the distraction in the range [0...1)
35 * @param side side if the distraction
36 * @throws NetworkException when the position is not correct
37 * @throws IllegalArgumentException when the range is not a positive {@code Length}, or the level is not in range [0...1)
38 * @throws NullPointerException when side is {@code null}
39 */
40 public LocalDistraction(final String id, final LanePosition position, final Length range, final double distractionLevel,
41 final LateralDirectionality side) throws NetworkException
42 {
43 super(id, position.lane(), position.position(), LaneBasedObject.makeLine(position.lane(), position.position()));
44 Throw.when(range == null || range.lt0(), IllegalArgumentException.class, "Distance should be a positive Length.");
45 Throw.when(distractionLevel < 0 || distractionLevel >= 1.0, IllegalArgumentException.class,
46 "Distraction level should be in the range [0...1).");
47 Throw.whenNull(side, "side");
48 this.range = range;
49 this.distractionLevel = distractionLevel;
50 this.side = side;
51 position.lane().addLaneBasedObject(this);
52 }
53
54 /**
55 * Returns the range of the distraction, which applies upstream of the location.
56 * @return range of the distraction
57 */
58 public Length getRange()
59 {
60 return this.range;
61 }
62
63 /**
64 * Returns the distraction level as normalized task demand.
65 * @return distraction level
66 */
67 public double getDistractionLevel()
68 {
69 return this.distractionLevel;
70 }
71
72 /**
73 * Returns the side of the distraction, relative to the driving direction.
74 * @return side of the distraction
75 */
76 public LateralDirectionality getSide()
77 {
78 return this.side;
79 }
80
81 }