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.OrientedPoint2d;
6   import org.opentrafficsim.core.gtu.GtuGenerator.GtuGeneratorPosition;
7   import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
8   
9   /**
10   * Animation data of a GtuGeneratorPosition.
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   */
17  public class AnimationGtuGeneratorPositionData implements GtuGeneratorPositionData
18  {
19  
20      /** Position. */
21      private final GtuGeneratorPosition position;
22  
23      /**
24       * Constructor.
25       * @param position position within a generator.
26       */
27      public AnimationGtuGeneratorPositionData(final GtuGeneratorPosition position)
28      {
29          this.position = position;
30      }
31  
32      @Override
33      public OrientedPoint2d getLocation()
34      {
35          return this.position.getLocation();
36      }
37  
38      @Override
39      public Bounds2d getBounds()
40      {
41          // this correlates to how generators are drawn as three chevrons
42          return new Bounds2d(0.0, 4.75, -1.0, 1.0);
43      }
44  
45      @Override
46      public Polygon2d getContour()
47      {
48          throw new UnsupportedOperationException("GtuGeneratorPosition does not have a contour.");
49      }
50  
51      @Override
52      public int getQueueCount()
53      {
54          return this.position.getQueueCount();
55      }
56  
57      /**
58       * Returns the generator position.
59       * @return generator position.
60       */
61      public GtuGeneratorPosition getGeneratorPosition()
62      {
63          return this.position;
64      }
65  
66      @Override
67      public String toString()
68      {
69          return "Generator position " + this.position.getId();
70      }
71  
72  }