Skip to content

Commit 06bdb78

Browse files
authored
Merge pull request opentripplanner#6598 from HSLdevcom/accept-short-arealinks
Boarding location linking accepts very short links instead of throwing an exception
2 parents d3239c2 + d43e013 commit 06bdb78

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

application/src/main/java/org/opentripplanner/routing/linking/VertexLinker.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,16 @@ private boolean addAreaVertex(
654654
.filter(v -> distSquared(v, newVertex) >= DUPLICATE_NODE_EPSILON_DEGREES_SQUARED)
655655
.sorted((v1, v2) -> Double.compare(distSquared(v1, newVertex), distSquared(v2, newVertex))
656656
)
657-
.findFirst()
658-
.get();
659-
return addVisibilityEdges(newVertex, nearest, areaGroup, scope, tempEdges, true);
657+
.findFirst();
658+
if (!nearest.isPresent()) {
659+
// This can happen when all (probably the single one) visibility points are very close
660+
// to the linked vertex. Such situation can arise in boarding location linking which skips
661+
// the snapping logic of normal linking and calls addPermanentAreaVertex directly
662+
nearest = areaGroup.visibilityVertices().stream().findFirst();
663+
}
664+
if (nearest.isPresent()) {
665+
return addVisibilityEdges(newVertex, nearest.get(), areaGroup, scope, tempEdges, true);
666+
}
660667
}
661668
return false;
662669
} else if (scope == Scope.PERMANENT) {

application/src/test/java/org/opentripplanner/routing/linking/LinkStopToPlatformTest.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.opentripplanner.street.model.vertex.LabelledIntersectionVertex;
2929
import org.opentripplanner.street.model.vertex.TransitStopVertex;
3030
import org.opentripplanner.street.model.vertex.Vertex;
31+
import org.opentripplanner.street.model.vertex.VertexFactory;
3132
import org.opentripplanner.street.search.TraverseMode;
3233
import org.opentripplanner.street.search.TraverseModeSet;
3334
import org.opentripplanner.test.support.GeoJsonIo;
@@ -46,14 +47,15 @@ private Graph prepareTest(Coordinate[] platform, int[] visible, Coordinate[] sto
4647
var deduplicator = new Deduplicator();
4748
var siteRepository = new SiteRepository();
4849
Graph graph = new Graph(deduplicator);
50+
var vertexFactory = new VertexFactory(graph);
51+
4952
var timetableRepository = new TimetableRepository(siteRepository, deduplicator);
5053
ArrayList<IntersectionVertex> vertices = new ArrayList<>();
5154
Coordinate[] closedGeom = new Coordinate[platform.length + 1];
5255

5356
for (int i = 0; i < platform.length; i++) {
5457
Coordinate c = platform[i];
55-
var vertex = new LabelledIntersectionVertex(String.valueOf(i), c.x, c.y, false, false);
56-
graph.addVertex(vertex);
58+
var vertex = vertexFactory.intersection(String.valueOf(i), c.x, c.y);
5759
vertices.add(vertex);
5860
closedGeom[i] = c;
5961
}
@@ -109,8 +111,7 @@ private Graph prepareTest(Coordinate[] platform, int[] visible, Coordinate[] sto
109111
graph.index(timetableRepository.getSiteRepository());
110112

111113
for (RegularStop s : transitStops) {
112-
var v = TransitStopVertex.of().withStop(s).build();
113-
graph.addVertex(v);
114+
vertexFactory.transitStop(TransitStopVertex.of().withStop(s));
114115
}
115116

116117
return graph;
@@ -212,6 +213,43 @@ void testLinkStopNearPlatformVertex() {
212213
assertEquals(10, graph.getEdges().size());
213214
}
214215

216+
/**
217+
* Link an interior vertex which is very close to a visibility vertex by
218+
* calling directly addPermanentAreaVertex used in boarding location linking
219+
* A connecting edge pair is created despite of the small distance
220+
*/
221+
@Test
222+
void testAddPermanentAreaVertex() {
223+
Coordinate[] platform = {
224+
new Coordinate(10, 60.002),
225+
new Coordinate(10.004, 60.002),
226+
new Coordinate(10.004, 60),
227+
new Coordinate(10, 60),
228+
};
229+
// add one entrance to bottom left corner
230+
int[] visibilityPoints = { 3 };
231+
232+
// No stops
233+
Coordinate[] stops = {};
234+
235+
Graph graph = prepareTest(platform, visibilityPoints, stops);
236+
237+
// dig up the AreaGroup
238+
AreaGroup ag = null;
239+
var edge = graph.getEdges().stream().findFirst().get();
240+
if (edge instanceof AreaEdge ae) {
241+
ag = ae.getArea();
242+
}
243+
assertNotNull(ag);
244+
245+
var vertexFactory = new VertexFactory(graph);
246+
var v = vertexFactory.intersection("boardingLocation", 10.00000001, 60.00000001);
247+
graph.getLinker().addPermanentAreaVertex(v, ag);
248+
249+
// vertex links to the single visibility point with 2 edges
250+
assertEquals(10, graph.getEdges().size());
251+
}
252+
215253
/**
216254
* Link a stop which is inside an area and very close to its edge.
217255
* Linking snaps directly to the edge without short connecting edges

0 commit comments

Comments
 (0)