1 package org.opentrafficsim.base; 2 3 import java.awt.Color; 4 import java.io.Serializable; 5 6 import org.djunits.value.vdouble.scalar.Length; 7 import org.djunits.value.vdouble.vector.LengthVector; 8 import org.djutils.exceptions.Throw; 9 10 /** 11 * Data container for an element of a stripe road marking. Elements can be continuous lines, dashed lines, or gaps between 12 * lines. For example, this can entail a complicated road marking consisting of a continuous line, a narrow gap, a colored wide 13 * area (included as a wide line), a narrow gap, and a dashed line. 14 * <p> 15 * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 16 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 17 * </p> 18 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a> 19 * @param width width 20 * @param color color 21 * @param dashes dashes 22 */ 23 public record StripeElement(Length width, Color color, LengthVector dashes) implements Serializable 24 { 25 26 /* This class is in ots-base, as it is used by both ots-road and ots-draw. */ 27 28 /** 29 * Constructor checks. 30 * @param width width 31 * @param color color 32 * @param dashes dashes 33 */ 34 public StripeElement 35 { 36 Throw.whenNull(width, "width"); 37 Throw.when(color == null && dashes != null, IllegalArgumentException.class, "Dashes mean nothing when color is null."); 38 } 39 40 /** 41 * Creates a continuous stripe element. 42 * @param width width 43 * @param color color 44 * @return continuous stripe element 45 */ 46 public static StripeElement continuous(final Length width, final Color color) 47 { 48 Throw.whenNull(width, "color"); 49 return new StripeElement(width, color, null); 50 } 51 52 /** 53 * Creates a dashed stripe element. 54 * @param width width 55 * @param color color 56 * @param dashes dashes (gap, dash, gap, dash, ...) 57 * @return dashed stripe element 58 */ 59 public static StripeElement dashed(final Length width, final Color color, final LengthVector dashes) 60 { 61 Throw.whenNull(width, "color"); 62 Throw.whenNull(width, "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 }