View Javadoc
1   package org.opentrafficsim.animation.data;
2   
3   import org.djutils.draw.line.PolyLine2d;
4   import org.djutils.draw.line.Polygon2d;
5   import org.djutils.draw.point.Point2d;
6   import org.opentrafficsim.base.geometry.OtsShape;
7   import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
8   import org.opentrafficsim.road.network.lane.CrossSectionElement;
9   
10  /**
11   * Animation data of a CrossSectionElement.
12   * <p>
13   * Copyright (c) 2023-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   * @param <T> cross-section element type.
18   */
19  public class AnimationCrossSectionElementData<T extends CrossSectionElement> implements CrossSectionElementData
20  {
21  
22      /** Cross section element. */
23      private final T element;
24  
25      /**
26       * Constructor.
27       * @param element cross section element.
28       */
29      public AnimationCrossSectionElementData(final T element)
30      {
31          this.element = element;
32      }
33  
34      @Override
35      public Polygon2d getContour()
36      {
37          return this.element.getContour();
38      }
39  
40      @Override
41      public OtsShape getShape()
42      {
43          return this.element.getShape();
44      }
45  
46      @Override
47      public PolyLine2d getCenterLine()
48      {
49          return this.element.getCenterLine();
50      }
51  
52      @Override
53      public String getLinkId()
54      {
55          return this.element.getId();
56      }
57  
58      @Override
59      public Point2d getLocation()
60      {
61          return this.element.getLocation();
62      }
63  
64      /**
65       * Returns the cross section element.
66       * @return cross-section element.
67       */
68      public T getElement()
69      {
70          return this.element;
71      }
72  
73      @Override
74      public String toString()
75      {
76          return "Cross section element " + getElement().getId();
77      }
78  
79  }