1 package org.opentrafficsim.base;
2
3 import java.awt.Color;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djunits.value.vdouble.vector.LengthVector;
7 import org.djutils.exceptions.Throw;
8
9 /**
10 * Data container for an element of a stripe road marking. Elements can be continuous lines, dashed lines, or gaps between
11 * lines. For example, this can entail a complicated road marking consisting of a continuous line, a narrow gap, a colored wide
12 * area (included as a wide line), a narrow gap, and a dashed line.
13 * <p>
14 * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16 * </p>
17 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18 * @param width width
19 * @param color color
20 * @param dashes dashes
21 */
22 public record StripeElement(Length width, Color color, LengthVector dashes)
23 {
24
25 /* This class is in ots-base, as it is used by both ots-road and ots-draw. */
26
27 /**
28 * Constructor checks.
29 * @param width width
30 * @param color color
31 * @param dashes dashes
32 */
33 public StripeElement
34 {
35 Throw.whenNull(width, "width");
36 Throw.when(color == null && dashes != null, IllegalArgumentException.class, "Dashes mean nothing when color is null.");
37 }
38
39 /**
40 * Creates a continuous stripe element.
41 * @param width width
42 * @param color color
43 * @return continuous stripe element
44 */
45 public static StripeElement continuous(final Length width, final Color color)
46 {
47 Throw.whenNull(width, "width");
48 return new StripeElement(width, color, null);
49 }
50
51 /**
52 * Creates a dashed stripe element.
53 * @param width width
54 * @param color color
55 * @param dashes dashes (gap, dash, gap, dash, ...)
56 * @return dashed stripe element
57 */
58 public static StripeElement dashed(final Length width, final Color color, final LengthVector dashes)
59 {
60 Throw.whenNull(width, "width");
61 Throw.whenNull(color, "color");
62 Throw.whenNull(dashes, "dashes");
63 return new StripeElement(width, color, dashes);
64 }
65
66 /**
67 * Creates a gap stripe element.
68 * @param width width
69 * @return gap stripe element
70 */
71 public static StripeElement gap(final Length width)
72 {
73 return new StripeElement(width, null, null);
74 }
75
76 /**
77 * Returns whether this is a continuous stripe element (i.e. a line without dashes).
78 * @return whether this is a continuous stripe element
79 */
80 public boolean isContinuous()
81 {
82 return this.color != null && this.dashes == null;
83 }
84
85 /**
86 * Returns whether this is a gap stripe element.
87 * @return whether this is a gap stripe element
88 */
89 public boolean isGap()
90 {
91 return this.color == null;
92 }
93
94 /**
95 * Returns whether this is a dashed stripe element.
96 * @return whether this is a dashed stripe element
97 */
98 public boolean isDashed()
99 {
100 return this.color != null && this.dashes != null;
101 }
102
103 /**
104 * Method to determine how stripes synchronize within a link.
105 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
106 */
107 public enum StripeLateralSync
108 {
109 /** Dashes applied to stripe line. */
110 NONE(false),
111
112 /** Dashes applied to link middle line to determine fractions, which are then used on the stripe line. */
113 LINK(true);
114
115 /** Whether the dashes are applied on the median line of the link. */
116 private final boolean linkBased;
117
118 /**
119 * Constructor.
120 * @param linkBased whether the dashes are applied on the median line of the link
121 */
122 StripeLateralSync(final boolean linkBased)
123 {
124 this.linkBased = linkBased;
125 }
126
127 /**
128 * Returns whether the dashes are applied on the median line of the link.
129 * @return whether the dashes are applied on the median line of the link
130 */
131 public boolean isLinkBased()
132 {
133 return this.linkBased;
134 }
135 }
136
137 }