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.OrientedPoint2d;
6   import org.opentrafficsim.base.geometry.OtsLocatable;
7   import org.opentrafficsim.base.geometry.OtsShape;
8   import org.opentrafficsim.core.network.Link;
9   import org.opentrafficsim.draw.network.LinkAnimation.LinkData;
10  
11  /**
12   * Animation data of a Link.
13   * <p>
14   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public class AnimationLinkData implements LinkData
20  {
21  
22      /** Link. */
23      private final Link link;
24  
25      /** Shape (cached). */
26      private OtsShape shape;
27  
28      /**
29       * Constructor.
30       * @param link link.
31       */
32      public AnimationLinkData(final Link link)
33      {
34          this.link = link;
35      }
36  
37      @Override
38      public Polygon2d getContour()
39      {
40          return this.link.getContour();
41      }
42  
43      @Override
44      public OtsShape getShape()
45      {
46          if (this.shape == null)
47          {
48              this.shape = LinkData.super.getShape();
49          }
50          return this.shape;
51      }
52  
53      @Override
54      public String getId()
55      {
56          return this.link.getId();
57      }
58  
59      @Override
60      public boolean isConnector()
61      {
62          return this.link.isConnector();
63      }
64  
65      @Override
66      public PolyLine2d getCenterLine()
67      {
68          return this.link.getDesignLine();
69      }
70  
71      @Override
72      public PolyLine2d getLine()
73      {
74          return OtsLocatable.transformLine(getCenterLine(), getLocation());
75      }
76  
77      @Override
78      public OrientedPoint2d getLocation()
79      {
80          return this.link.getLocation();
81      }
82  
83      /**
84       * Returns the link.
85       * @return link.
86       */
87      public Link getLink()
88      {
89          return this.link;
90      }
91  
92      @Override
93      public String toString()
94      {
95          return "Link " + this.link.getId();
96      }
97  
98  }