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