View Javadoc
1   package org.opentrafficsim.animation.data;
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   import org.opentrafficsim.road.network.lane.CrossSectionLink;
9   
10  /**
11   * Priority data for animation.
12   * <p>
13   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   */
18  public class AnimationPriorityData implements PriorityData
19  {
20  
21      /** Link. */
22      private final CrossSectionLink link;
23  
24      /** Bounds. */
25      private final Bounds2d bounds = new Bounds2d(2.0, 2.0);
26  
27      /** Relative contour. */
28      private final Polygon2d relativeContour;
29  
30      /** Absolute contour. */
31      private final Polygon2d absoluteContour;
32  
33      /**
34       * Constructor.
35       * @param link link.
36       */
37      public AnimationPriorityData(final CrossSectionLink link)
38      {
39          this.link = link;
40          this.absoluteContour = OtsShape.boundsAsAbsoluteContour(this);
41          this.relativeContour =
42                  new Polygon2d(OtsShape.toRelativeTransform(getLocation()).transform(this.absoluteContour.iterator()));
43      }
44  
45      @Override
46      public DirectedPoint2d getLocation()
47      {
48          return this.link.getDesignLine().getLocationFractionExtended(0.5);
49      }
50  
51      @Override
52      public Polygon2d getAbsoluteContour()
53      {
54          return this.absoluteContour;
55      }
56  
57      @Override
58      public Polygon2d getRelativeContour()
59      {
60          return this.relativeContour;
61      }
62  
63      @Override
64      public Bounds2d getRelativeBounds()
65      {
66          return this.bounds;
67      }
68  
69      @Override
70      public boolean isAllStop()
71      {
72          return this.link.getPriority().isAllStop();
73      }
74  
75      @Override
76      public boolean isBusStop()
77      {
78          return this.link.getPriority().isBusStop();
79      }
80  
81      @Override
82      public boolean isNone()
83      {
84          return this.link.getPriority().isNone();
85      }
86  
87      @Override
88      public boolean isPriority()
89      {
90          return this.link.getPriority().isPriority();
91      }
92  
93      @Override
94      public boolean isStop()
95      {
96          return this.link.getPriority().isStop();
97      }
98  
99      @Override
100     public boolean isYield()
101     {
102         return this.link.getPriority().isYield();
103     }
104 
105     @Override
106     public String toString()
107     {
108         return "Priority " + this.link.getId();
109     }
110 
111 }