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