AnimationCrossSectionElementData.java

  1. package org.opentrafficsim.animation.data;

  2. import org.djutils.draw.line.PolyLine2d;
  3. import org.djutils.draw.line.Polygon2d;
  4. import org.djutils.draw.point.Point2d;
  5. import org.opentrafficsim.base.geometry.OtsShape;
  6. import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
  7. import org.opentrafficsim.road.network.lane.CrossSectionElement;

  8. /**
  9.  * Animation data of a CrossSectionElement.
  10.  * <p>
  11.  * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  13.  * </p>
  14.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  15.  * @param <T> cross-section element type.
  16.  */
  17. public class AnimationCrossSectionElementData<T extends CrossSectionElement> implements CrossSectionElementData
  18. {

  19.     /** Cross section element. */
  20.     private final T element;

  21.     /**
  22.      * Constructor.
  23.      * @param element cross section element.
  24.      */
  25.     public AnimationCrossSectionElementData(final T element)
  26.     {
  27.         this.element = element;
  28.     }

  29.     @Override
  30.     public Polygon2d getContour()
  31.     {
  32.         return this.element.getContour();
  33.     }

  34.     @Override
  35.     public OtsShape getShape()
  36.     {
  37.         return this.element.getShape();
  38.     }

  39.     @Override
  40.     public PolyLine2d getCenterLine()
  41.     {
  42.         return this.element.getCenterLine();
  43.     }

  44.     @Override
  45.     public String getLinkId()
  46.     {
  47.         return this.element.getId();
  48.     }

  49.     @Override
  50.     public Point2d getLocation()
  51.     {
  52.         return this.element.getLocation();
  53.     }

  54.     /**
  55.      * Returns the cross section element.
  56.      * @return cross-section element.
  57.      */
  58.     public T getElement()
  59.     {
  60.         return this.element;
  61.     }

  62.     @Override
  63.     public String toString()
  64.     {
  65.         return "Cross section element " + getElement().getId();
  66.     }

  67. }