Skip to content

Commit 3bae1a1

Browse files
Merge pull request opentripplanner#6780 from Aubin-MaaS/north-based-angles
Use North-based angle in internal representation
2 parents d4e5bb8 + b72ca53 commit 3bae1a1

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,15 @@ public boolean isSlopeOverride() {
553553
}
554554

555555
/**
556-
* Return the azimuth of the first segment in this edge in integer degrees clockwise from South.
557-
* TODO change everything to clockwise from North
556+
* Return the azimuth of the first segment in this edge in integer degrees clockwise from North.
558557
*/
559558
public int getInAngle() {
560559
return IntUtils.round((this.inAngle * 180) / 128.0);
561560
}
562561

563-
/** Return the azimuth of the last segment in this edge in integer degrees clockwise from South. */
562+
/**
563+
* Return the azimuth of the last segment in this edge in integer degrees clockwise from North.
564+
*/
564565
public int getOutAngle() {
565566
return IntUtils.round((this.outAngle * 180) / 128.0);
566567
}
@@ -1226,14 +1227,12 @@ public static LineStringInOutAngles of(LineString geometry) {
12261227

12271228
/**
12281229
* Conversion from radians to internal representation as a single signed byte.
1229-
* We also reorient the angles since OTP seems to use South as a reference
1230-
* while the azimuth functions use North.
1231-
* FIXME Use only North as a reference, not a mix of North and South!
1230+
* <p>
12321231
* Range restriction happens automatically due to Java signed overflow behavior.
12331232
* 180 degrees exists as a negative rather than a positive due to the integer range.
12341233
*/
12351234
private static byte convertRadianToByte(double angleRadians) {
1236-
return (byte) Math.round((angleRadians * 128) / Math.PI + 128);
1235+
return (byte) Math.round((angleRadians * 128) / Math.PI);
12371236
}
12381237
}
12391238
}

application/src/test/java/org/opentripplanner/street/model/edge/StreetEdgeTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
55
import static org.junit.jupiter.api.Assertions.assertFalse;
6-
import static org.junit.jupiter.api.Assertions.assertNotNull;
76
import static org.junit.jupiter.api.Assertions.assertNull;
87
import static org.junit.jupiter.api.Assertions.assertTrue;
98
import static org.opentripplanner.street.model.StreetTraversalPermission.ALL;
109
import static org.opentripplanner.street.model._data.StreetModelForTest.intersectionVertex;
1110
import static org.opentripplanner.street.model._data.StreetModelForTest.streetEdge;
1211
import static org.opentripplanner.street.model._data.StreetModelForTest.streetEdgeBuilder;
1312

14-
import java.time.Instant;
1513
import org.junit.jupiter.api.BeforeEach;
1614
import org.junit.jupiter.api.Test;
1715
import org.locationtech.jts.geom.Coordinate;
@@ -25,7 +23,6 @@
2523
import org.opentripplanner.routing.util.ElevationUtils;
2624
import org.opentripplanner.routing.util.SlopeCosts;
2725
import org.opentripplanner.street.model.StreetTraversalPermission;
28-
import org.opentripplanner.street.model.TurnRestriction;
2926
import org.opentripplanner.street.model._data.StreetModelForTest;
3027
import org.opentripplanner.street.model.vertex.IntersectionVertex;
3128
import org.opentripplanner.street.model.vertex.LabelledIntersectionVertex;
@@ -35,7 +32,6 @@
3532
import org.opentripplanner.street.search.request.StreetSearchRequest;
3633
import org.opentripplanner.street.search.request.StreetSearchRequestBuilder;
3734
import org.opentripplanner.street.search.state.State;
38-
import org.opentripplanner.street.search.state.StateData;
3935

4036
public class StreetEdgeTest {
4137

@@ -68,15 +64,15 @@ void testInAndOutAngles() {
6864
StreetEdge e1 = streetEdge(v1, v2, 1.0, ALL);
6965

7066
// Edge has same first and last angle.
71-
assertEquals(90, e1.getInAngle());
72-
assertEquals(90, e1.getOutAngle());
67+
assertEquals(-90, e1.getInAngle());
68+
assertEquals(-90, e1.getOutAngle());
7369

7470
// 2 new ones
7571
StreetVertex u = intersectionVertex("test1", 1.0, 2.0);
7672
StreetVertex v = intersectionVertex("test2", 2.0, 2.0);
7773

78-
// Second edge, heading straight North
79-
StreetEdge e2 = streetEdge(u, v, 1.0, ALL);
74+
// Second edge, heading straight South
75+
StreetEdge e2 = streetEdge(v, u, 1.0, ALL);
8076

8177
// 180 degrees could be expressed as 180 or -180. Our implementation happens to use -180.
8278
assertEquals(180, Math.abs(e2.getInAngle()));

application/src/test/java/org/opentripplanner/street/search/intersection_model/SimpleIntersectionTraversalCalculatorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public void testCalculateTurnAngle() {
4848
edge(v2, v3, 1.0, false);
4949

5050
// Edge has same first and last angle.
51-
assertEquals(90, e1.getInAngle());
52-
assertEquals(90, e1.getOutAngle());
51+
assertEquals(-90, e1.getInAngle());
52+
assertEquals(-90, e1.getOutAngle());
5353

5454
// 2 new ones
5555
IntersectionVertex v4 = vertex("test2", new Coordinate(1.0, 1.0), false, false);
5656

5757
// Third edge
5858
StreetEdge e3 = edge(v2, v4, 1.0, false);
5959

60-
assertEquals(0, e3.getInAngle());
61-
assertEquals(0, e3.getOutAngle());
60+
assertEquals(-180, e3.getInAngle());
61+
assertEquals(-180, e3.getOutAngle());
6262

6363
// Difference should be about 90.
6464
int diff = (e1.getOutAngle() - e3.getInAngle());

0 commit comments

Comments
 (0)