View Javadoc
1   package org.opentrafficsim.editor.extensions.map;
2   
3   import org.djutils.draw.bounds.Bounds2d;
4   import org.djutils.draw.line.Polygon2d;
5   import org.djutils.draw.point.DirectedPoint2d;
6   import org.opentrafficsim.base.geometry.OtsShape;
7   import org.opentrafficsim.draw.road.PriorityAnimation.PriorityData;
8   
9   /**
10   * Priority data for in the editor.
11   * <p>
12   * Copyright (c) 2024-2024 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 MapPriorityData implements PriorityData
18  {
19  
20      /** Link data. */
21      private final MapLinkData linkData;
22  
23      /** Location. */
24      private final DirectedPoint2d location;
25  
26      /** Bounds. */
27      private final Bounds2d bounds = new Bounds2d(2.0, 2.0);
28  
29      /** Absolute contour. */
30      private final Polygon2d absoluteContour;
31  
32      /** Relative contour. */
33      private final Polygon2d relativeContour;
34  
35      /**
36       * Constructor.
37       * @param linkData link data.
38       */
39      public MapPriorityData(final MapLinkData linkData)
40      {
41          this.location = linkData.getCenterLine().getLocationFractionExtended(0.5);
42          this.linkData = linkData;
43          this.absoluteContour = OtsShape.boundsAsAbsoluteContour(this);
44          this.relativeContour =
45                  new Polygon2d(OtsShape.toRelativeTransform(this.location).transform(this.absoluteContour.iterator()));
46      }
47  
48      @Override
49      public DirectedPoint2d getLocation()
50      {
51          return this.location;
52      }
53  
54      @Override
55      public Polygon2d getAbsoluteContour()
56      {
57          return this.absoluteContour;
58      }
59  
60      @Override
61      public Polygon2d getRelativeContour()
62      {
63          return this.relativeContour;
64      }
65  
66      @Override
67      public Bounds2d getRelativeBounds()
68      {
69          return this.bounds;
70      }
71  
72      @Override
73      public boolean isAllStop()
74      {
75          return "ALL_STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
76      }
77  
78      @Override
79      public boolean isBusStop()
80      {
81          return "BUS_STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
82      }
83  
84      @Override
85      public boolean isNone()
86      {
87          return "NONE".equals(this.linkData.getNode().getAttributeValue("Priority"));
88      }
89  
90      @Override
91      public boolean isPriority()
92      {
93          return "PRIORITY".equals(this.linkData.getNode().getAttributeValue("Priority"));
94      }
95  
96      @Override
97      public boolean isStop()
98      {
99          return "STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
100     }
101 
102     @Override
103     public boolean isYield()
104     {
105         return "YIELD".equals(this.linkData.getNode().getAttributeValue("Priority"));
106     }
107 
108     @Override
109     public String toString()
110     {
111         return "Priority " + this.linkData.getId();
112     }
113 
114 }