Skip to content

Commit 0c9dab0

Browse files
authored
Merge pull request opentripplanner#6530 from HSLdevcom/entrance-bug
Fix entrances being removed from walk steps
2 parents f9b2937 + 21dbabe commit 0c9dab0

5 files changed

Lines changed: 98 additions & 2 deletions

File tree

application/src/main/java/org/opentripplanner/model/plan/WalkStepBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public String directionTextNoParens() {
138138
return str;
139139
}
140140

141+
public boolean hasEntrance() {
142+
return entrance != null;
143+
}
144+
141145
public WalkStepBuilder addStreetNotes(Set<StreetNote> notes) {
142146
this.streetNotes.addAll(notes);
143147
return this;

application/src/main/java/org/opentripplanner/routing/algorithm/mapping/StatesToWalkStepsMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ private void processState(State backState, State forwardState) {
275275
boolean isOnSameStreet = lastStep
276276
.directionTextNoParens()
277277
.equals(threeBack.directionTextNoParens());
278-
if (twoBack.distance() < MAX_ZAG_DISTANCE && isOnSameStreet) {
278+
if (twoBack.distance() < MAX_ZAG_DISTANCE && isOnSameStreet && !twoBack.hasEntrance()) {
279279
if (isUTurn(twoBack, lastStep)) {
280280
steps.remove(lastIndex - 1);
281281
processUTurn(lastStep, twoBack);
282-
} else {
282+
} else if (!lastStep.hasEntrance()) {
283283
// total hack to remove zags.
284284
steps.remove(lastIndex);
285285
steps.remove(lastIndex - 1);

application/src/test/java/org/opentripplanner/routing/algorithm/mapping/StatesToWalkStepsMapperTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ void elevator() {
3434
assertTrue(elevatorStep.getAbsoluteDirection().isEmpty());
3535
}
3636

37+
@Test
38+
void stationEntrance() {
39+
var walkSteps = buildWalkSteps(
40+
TestStateBuilder.ofWalking()
41+
.streetEdge("name", 1)
42+
.entrance("name")
43+
.streetEdge()
44+
.areaEdge("name", 10)
45+
);
46+
assertEquals(3, walkSteps.size());
47+
assertEquals(RelativeDirection.DEPART, walkSteps.get(0).getRelativeDirection());
48+
assertEquals(RelativeDirection.ENTER_OR_EXIT_STATION, walkSteps.get(1).getRelativeDirection());
49+
assertEquals(RelativeDirection.CONTINUE, walkSteps.get(2).getRelativeDirection());
50+
}
51+
3752
@Test
3853
void enterStation() {
3954
final TestStateBuilder builder = TestStateBuilder.ofWalking()

application/src/test/java/org/opentripplanner/street/model/_data/StreetModelForTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.opentripplanner.service.vehiclerental.street.VehicleRentalPlaceVertex;
1414
import org.opentripplanner.street.model.RentalFormFactor;
1515
import org.opentripplanner.street.model.StreetTraversalPermission;
16+
import org.opentripplanner.street.model.edge.AreaEdgeBuilder;
17+
import org.opentripplanner.street.model.edge.AreaGroup;
1618
import org.opentripplanner.street.model.edge.StreetEdge;
1719
import org.opentripplanner.street.model.edge.StreetEdgeBuilder;
1820
import org.opentripplanner.street.model.vertex.IntersectionVertex;
@@ -87,6 +89,29 @@ public static StreetEdge streetEdge(
8789
return streetEdgeBuilder(vA, vB, length, perm).buildAndConnect();
8890
}
8991

92+
public static StreetEdge areaEdge(
93+
StreetVertex vA,
94+
StreetVertex vB,
95+
String name,
96+
StreetTraversalPermission perm
97+
) {
98+
Coordinate[] coords = new Coordinate[2];
99+
coords[0] = vA.getCoordinate();
100+
coords[1] = vB.getCoordinate();
101+
LineString geom = GeometryUtils.getGeometryFactory().createLineString(coords);
102+
103+
AreaGroup AREA = new AreaGroup(null);
104+
105+
return new AreaEdgeBuilder()
106+
.withFromVertex(vA)
107+
.withToVertex(vB)
108+
.withGeometry(geom)
109+
.withPermission(perm)
110+
.withName(name)
111+
.withArea(AREA)
112+
.buildAndConnect();
113+
}
114+
90115
public static StreetEdge streetEdge(
91116
StreetVertex from,
92117
StreetVertex to,

application/src/test/java/org/opentripplanner/street/search/state/TestStateBuilder.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.opentripplanner.street.model.edge.StreetTransitStopLink;
3232
import org.opentripplanner.street.model.vertex.ElevatorOffboardVertex;
3333
import org.opentripplanner.street.model.vertex.ElevatorOnboardVertex;
34+
import org.opentripplanner.street.model.vertex.StationEntranceVertex;
3435
import org.opentripplanner.street.model.vertex.StreetVertex;
3536
import org.opentripplanner.street.model.vertex.TransitStopVertex;
3637
import org.opentripplanner.street.search.TraverseMode;
@@ -131,6 +132,40 @@ public TestStateBuilder streetEdge() {
131132
return this;
132133
}
133134

135+
public TestStateBuilder streetEdge(String name, int distance) {
136+
count++;
137+
var from = (StreetVertex) currentState.vertex;
138+
var to = StreetModelForTest.intersectionVertex(count, count);
139+
var edge = StreetModelForTest.streetEdgeBuilder(
140+
from,
141+
to,
142+
distance,
143+
StreetTraversalPermission.PEDESTRIAN
144+
)
145+
.withName(name)
146+
.buildAndConnect();
147+
148+
var states = edge.traverse(currentState);
149+
if (states.length != 1) {
150+
throw new IllegalStateException("Only single state transitions are supported.");
151+
}
152+
currentState = states[0];
153+
return this;
154+
}
155+
156+
public TestStateBuilder areaEdge(String name, int distance) {
157+
count++;
158+
var from = (StreetVertex) currentState.vertex;
159+
var to = StreetModelForTest.intersectionVertex(count, count);
160+
var area = StreetModelForTest.areaEdge(from, to, name, StreetTraversalPermission.PEDESTRIAN);
161+
var states = area.traverse(currentState);
162+
if (states.length != 1) {
163+
throw new IllegalStateException("Only single state transitions are supported.");
164+
}
165+
currentState = states[0];
166+
return this;
167+
}
168+
134169
/**
135170
* Traverse a street edge and switch to Car mode
136171
*/
@@ -205,6 +240,23 @@ public TestStateBuilder elevator() {
205240
return this;
206241
}
207242

243+
public TestStateBuilder entrance(String name) {
244+
count++;
245+
var from = (StreetVertex) currentState.vertex;
246+
var to = new StationEntranceVertex(count, count, 12345, "A", Accessibility.POSSIBLE);
247+
248+
var edge = StreetModelForTest.streetEdgeBuilder(
249+
from,
250+
to,
251+
30,
252+
StreetTraversalPermission.PEDESTRIAN
253+
)
254+
.withName(name)
255+
.buildAndConnect();
256+
currentState = edge.traverse(currentState)[0];
257+
return this;
258+
}
259+
208260
public TestStateBuilder stop(RegularStop stop) {
209261
return arriveAtStop(stop);
210262
}

0 commit comments

Comments
 (0)