1 package org.opentrafficsim.road.network;
2
3 import static org.junit.Assert.assertEquals;
4
5 import org.junit.Test;
6 import org.opentrafficsim.core.OTS_SCALAR;
7 import org.opentrafficsim.core.geometry.OTSLine3D;
8 import org.opentrafficsim.core.geometry.OTSPoint3D;
9 import org.opentrafficsim.core.network.LinkLocation;
10 import org.opentrafficsim.core.network.OTSNode;
11 import org.opentrafficsim.road.network.lane.CrossSectionLink;
12 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
13
14
15
16
17
18
19
20
21
22
23
24 public class LinkLocationTest implements OTS_SCALAR
25 {
26
27
28
29 @Test
30 public void linkLocationTest()
31 {
32
33 OTSNode nodeFrom = new OTSNode("From", new OTSPoint3D(0, 0, 0));
34 OTSNode nodeTo = new OTSNode("To", new OTSPoint3D(1000, 0, 0));
35 OTSLine3D line = new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(0, 0, 0), new OTSPoint3D(1000, 0, 0)});
36 CrossSectionLink link = new CrossSectionLink("Link", nodeFrom, nodeTo, line, LaneKeepingPolicy.KEEP_RIGHT);
37 Length.Rel linkLength = line.getLength();
38
39 Length.Rel referenceLocationDistance = new Length.Rel(123, METER);
40 LinkLocation referenceLocation = new LinkLocation(link, referenceLocationDistance);
41 assertEquals("link should be the provided Link", link, referenceLocation.getLink());
42 assertEquals("longitudinalPosition should be " + referenceLocationDistance, referenceLocationDistance.getSI(),
43 referenceLocation.getLongitudinalPosition().getSI(), 0.0001);
44 for (int position = 0; position < 1000; position += 100)
45 {
46 final double fraction = position / linkLength.getSI();
47 LinkLocation linkLocation = new LinkLocation(link, fraction);
48 assertEquals("link should be the provided Link", link, linkLocation.getLink());
49 assertEquals("fractionalLongitudinalPosition should be " + fraction, fraction, linkLocation
50 .getFractionalLongitudinalPosition(), 0.000001);
51 assertEquals("longitudinalPosition should be " + position, position, linkLocation.getLongitudinalPosition()
52 .getSI(), 0.0001);
53
54 linkLocation = new LinkLocation(link, new Length.Rel(position, METER));
55 assertEquals("link should be the provided Link", link, linkLocation.getLink());
56 assertEquals("fractionalLongitudinalPosition should be " + fraction, fraction, linkLocation
57 .getFractionalLongitudinalPosition(), 0.000001);
58 assertEquals("longitudinalPosition should be " + position, position, linkLocation.getLongitudinalPosition()
59 .getSI(), 0.0001);
60 double delta = referenceLocationDistance.getSI() - position;
61 assertEquals("distance from reference should be " + delta, delta, linkLocation.distance(referenceLocation)
62 .getSI(), 0.0001);
63
64 }
65 }
66 }