Skip to content

Commit b72ca53

Browse files
committed
make everything count from North
1 parent 27cb855 commit b72ca53

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
@@ -558,14 +558,15 @@ public boolean isSlopeOverride() {
558558
}
559559

560560
/**
561-
* Return the azimuth of the first segment in this edge in integer degrees clockwise from South.
562-
* TODO change everything to clockwise from North
561+
* Return the azimuth of the first segment in this edge in integer degrees clockwise from North.
563562
*/
564563
public int getInAngle() {
565564
return IntUtils.round((this.inAngle * 180) / 128.0);
566565
}
567566

568-
/** Return the azimuth of the last segment in this edge in integer degrees clockwise from South. */
567+
/**
568+
* Return the azimuth of the last segment in this edge in integer degrees clockwise from North.
569+
*/
569570
public int getOutAngle() {
570571
return IntUtils.round((this.outAngle * 180) / 128.0);
571572
}
@@ -1231,14 +1232,12 @@ public static LineStringInOutAngles of(LineString geometry) {
12311232

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

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)