View Javadoc
1   package org.opentrafficsim.editor.extensions.map;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.draw.line.PolyLine2d;
5   import org.djutils.draw.line.Polygon2d;
6   import org.djutils.draw.point.DirectedPoint2d;
7   import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
8   import org.opentrafficsim.editor.XsdTreeNode;
9   import org.opentrafficsim.road.network.lane.CrossSectionGeometry;
10  
11  /**
12   * Cross section element data for in the editor.
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 MapCrossSectionData implements CrossSectionElementData
20  {
21  
22      /** Node representing the element. */
23      private final XsdTreeNode linkNode;
24  
25      /** Geometry. */
26      private final CrossSectionGeometry geometry;
27  
28      /**
29       * Constructor.
30       * @param linkNode node representing the element
31       * @param geometry geometry
32       */
33      public MapCrossSectionData(final XsdTreeNode linkNode, final CrossSectionGeometry geometry)
34      {
35          this.linkNode = linkNode;
36          this.geometry = geometry;
37      }
38  
39      @Override
40      public DirectedPoint2d getLocation()
41      {
42          return this.geometry.getLocation();
43      }
44  
45      @Override
46      public Polygon2d getAbsoluteContour()
47      {
48          return this.geometry.absoluteContour();
49      }
50  
51      @Override
52      public Polygon2d getRelativeContour()
53      {
54          return this.geometry.getRelativeContour();
55      }
56  
57      @Override
58      public PolyLine2d getCenterLine()
59      {
60          return this.geometry.centerLine();
61      }
62  
63      /**
64       * Returns the link id.
65       * @return link id.
66       */
67      @Override
68      public String getLinkId()
69      {
70          return this.linkNode.getId();
71      }
72  
73      /**
74       * Returns the lane width at the give position.
75       * @param position position along the lane.
76       * @return lane width at the position.
77       */
78      public Length getWidth(final Length position)
79      {
80          return Length.ofSI(this.geometry.width().get(position.si / getCenterLine().getLength()));
81      }
82  
83      @Override
84      public String toString()
85      {
86          return "Cross section element of " + getLinkId();
87      }
88  
89  }