Skip to content

Commit dcf77be

Browse files
Merge pull request opentripplanner#7081 from leonardehrenfried/remove-generic-location
Remove `GenericLocation` from street model
2 parents 49dec4a + bfdbd4f commit dcf77be

3 files changed

Lines changed: 64 additions & 16 deletions

File tree

application/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestBuilder.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.locationtech.jts.geom.Coordinate;
99
import org.locationtech.jts.geom.Envelope;
1010
import org.opentripplanner.framework.geometry.SphericalDistanceLibrary;
11-
import org.opentripplanner.model.GenericLocation;
1211
import org.opentripplanner.routing.api.request.StreetMode;
1312

1413
public class StreetSearchRequestBuilder {
@@ -70,12 +69,12 @@ public StreetSearchRequestBuilder withWheelchair(Consumer<WheelchairRequest.Buil
7069
return this;
7170
}
7271

73-
public StreetSearchRequestBuilder withFrom(GenericLocation from) {
72+
public StreetSearchRequestBuilder withFrom(@Nullable Coordinate from) {
7473
this.fromEnvelope = createEnvelope(from);
7574
return this;
7675
}
7776

78-
public StreetSearchRequestBuilder withTo(GenericLocation to) {
77+
public StreetSearchRequestBuilder withTo(@Nullable Coordinate to) {
7978
this.toEnvelope = createEnvelope(to);
8079
return this;
8180
}
@@ -131,12 +130,7 @@ public StreetSearchRequest build() {
131130
}
132131

133132
@Nullable
134-
private static Envelope createEnvelope(GenericLocation location) {
135-
if (location == null) {
136-
return null;
137-
}
138-
139-
Coordinate coordinate = location.getCoordinate();
133+
private static Envelope createEnvelope(@Nullable Coordinate coordinate) {
140134
if (coordinate == null) {
141135
return null;
142136
}

application/src/main/java/org/opentripplanner/street/search/request/StreetSearchRequestMapper.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.time.Instant;
44
import java.util.List;
5+
import javax.annotation.Nullable;
6+
import org.locationtech.jts.geom.Coordinate;
7+
import org.opentripplanner.model.GenericLocation;
58
import org.opentripplanner.routing.api.request.RouteRequest;
69
import org.opentripplanner.routing.api.request.preference.AccessibilityPreferences;
710
import org.opentripplanner.routing.api.request.preference.BikePreferences;
@@ -29,8 +32,8 @@ public static StreetSearchRequestBuilder mapInternal(RouteRequest request) {
2932
return StreetSearchRequest.of()
3033
.withStartTime(time)
3134
.withArriveBy(request.arriveBy())
32-
.withFrom(request.from())
33-
.withTo(request.to())
35+
.withFrom(mapGenericLocation(request.from()))
36+
.withTo(mapGenericLocation(request.to()))
3437
.withWheelchairEnabled(request.journey().wheelchair())
3538
.withGeoidElevation(preferences.system().geoidElevation())
3639
.withTurnReluctance(preferences.street().turnReluctance())
@@ -54,6 +57,15 @@ public static StreetSearchRequestBuilder mapToTransferRequest(RouteRequest reque
5457

5558
// private methods
5659

60+
@Nullable
61+
private static Coordinate mapGenericLocation(@Nullable GenericLocation location) {
62+
if (location != null) {
63+
return location.getCoordinate();
64+
} else {
65+
return null;
66+
}
67+
}
68+
5769
private static void mapWheelchair(WheelchairRequest.Builder b, WheelchairPreferences wheelchair) {
5870
b
5971
.withStop(mapAccessibility(wheelchair.stop()))

application/src/test/java/org/opentripplanner/street/search/request/StreetSearchRequestMapperTest.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,55 @@
2424

2525
class StreetSearchRequestMapperTest {
2626

27+
private static final double DELTA = 0.00001;
28+
private static final Instant INSTANT = Instant.parse("2022-11-10T10:00:00Z");
29+
30+
@Test
31+
void mapFromToCoordinates() {
32+
var builder = builder();
33+
34+
var from = GenericLocation.fromCoordinate(10, 11);
35+
var to = GenericLocation.fromCoordinate(20, 21);
36+
37+
var req = builder.withDateTime(INSTANT).withFrom(from).withTo(to).buildRequest();
38+
39+
var subject = StreetSearchRequestMapper.mapInternal(req).build();
40+
41+
assertEquals(INSTANT, subject.startTime());
42+
43+
var fromEnvelope = subject.fromEnvelope();
44+
assertEquals(10.9954339685, fromEnvelope.getMinX(), DELTA);
45+
assertEquals(9.99550339902, fromEnvelope.getMinY(), DELTA);
46+
assertEquals(11.0045660314, fromEnvelope.getMaxX(), DELTA);
47+
assertEquals(10.0044966009, fromEnvelope.getMaxY(), DELTA);
48+
49+
var toEnvelope = subject.toEnvelope();
50+
assertEquals(20.9952146804, toEnvelope.getMinX(), DELTA);
51+
assertEquals(19.9955033990, toEnvelope.getMinY(), DELTA);
52+
assertEquals(21.0047853195, toEnvelope.getMaxX(), DELTA);
53+
assertEquals(20.0044966009, toEnvelope.getMaxY(), DELTA);
54+
}
55+
56+
@Test
57+
void mapFromToStopIds() {
58+
var builder = builder();
59+
60+
var from = GenericLocation.fromStopId("S1", "A", "STOP1");
61+
var to = GenericLocation.fromStopId("S2", "A", "STOP2");
62+
63+
var req = builder.withDateTime(INSTANT).withFrom(from).withTo(to).buildRequest();
64+
65+
var subject = StreetSearchRequestMapper.mapInternal(req).build();
66+
67+
assertNull(subject.fromEnvelope());
68+
assertNull(subject.toEnvelope());
69+
}
70+
2771
@Test
2872
void mapVehicleWalking() {
2973
var builder = builder();
3074

31-
Instant dateTime = Instant.parse("2022-11-10T10:00:00Z");
75+
Instant dateTime = INSTANT;
3276
builder.withDateTime(dateTime);
3377
var from = new GenericLocation(null, id("STOP"), null, null);
3478
builder.withFrom(from);
@@ -54,10 +98,9 @@ void mapVehicleWalking() {
5498
void mapTransferRequest(boolean arriveBy) {
5599
var from = new GenericLocation(null, id("STOP"), null, null);
56100
var to = GenericLocation.fromCoordinate(60.0, 20.0);
57-
var dateTime = Instant.parse("2022-11-10T10:00:00Z");
58101
var builder = builder()
59102
.withArriveBy(arriveBy)
60-
.withDateTime(dateTime)
103+
.withDateTime(INSTANT)
61104
.withFrom(from)
62105
.withTo(to)
63106
.withPreferences(it -> it.withWalk(walk -> walk.withSpeed(2.4)))
@@ -67,12 +110,11 @@ void mapTransferRequest(boolean arriveBy) {
67110

68111
var subject = StreetSearchRequestMapper.mapToTransferRequest(request).build();
69112

70-
assertEquals(Instant.EPOCH, subject.startTime());
71113
assertNull(subject.fromEnvelope());
72114
assertNull(subject.toEnvelope());
73115
assertTrue(subject.wheelchairEnabled());
74116
assertEquals(2.4, subject.walk().speed());
75-
assertEquals(Instant.ofEpochSecond(0), subject.startTime());
117+
assertEquals(Instant.EPOCH, subject.startTime());
76118
// arrive by must always be false for transfer requests
77119
assertFalse(subject.arriveBy());
78120
}

0 commit comments

Comments
 (0)