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.line.Ray2d;
7 import org.djutils.draw.point.OrientedPoint2d;
8 import org.opentrafficsim.base.geometry.OtsShape;
9 import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
10 import org.opentrafficsim.editor.XsdTreeNode;
11 import org.opentrafficsim.road.network.lane.CrossSectionGeometry;
12
13
14
15
16
17
18
19
20
21 public class MapCrossSectionData implements CrossSectionElementData
22 {
23
24
25 private final XsdTreeNode linkNode;
26
27
28 private final OrientedPoint2d location;
29
30
31 private final CrossSectionGeometry geometry;
32
33
34 private OtsShape shape;
35
36
37
38
39
40
41 public MapCrossSectionData(final XsdTreeNode linkNode, final CrossSectionGeometry geometry)
42 {
43 this.linkNode = linkNode;
44 Ray2d ray = geometry.centerLine().getLocationFractionExtended(0.5);
45 this.location = new OrientedPoint2d(ray.x, ray.y, ray.phi);
46 this.geometry = geometry;
47 }
48
49 @Override
50 public OrientedPoint2d getLocation()
51 {
52 return this.location;
53 }
54
55 @Override
56 public Polygon2d getContour()
57 {
58 return this.geometry.contour();
59 }
60
61 @Override
62 public OtsShape getShape()
63 {
64 if (this.shape == null)
65 {
66 this.shape = CrossSectionElementData.super.getShape();
67 }
68 return this.shape;
69 }
70
71 @Override
72 public PolyLine2d getCenterLine()
73 {
74 return this.geometry.centerLine();
75 }
76
77
78
79
80
81 @Override
82 public String getLinkId()
83 {
84 return this.linkNode.getId();
85 }
86
87
88
89
90
91
92 public Length getWidth(final Length position)
93 {
94 return Length.instantiateSI(this.geometry.width().apply(position.si / getCenterLine().getLength()));
95 }
96
97 @Override
98 public String toString()
99 {
100 return "Cross section element of " + getLinkId();
101 }
102
103 }