Skip to content

Commit

Permalink
core: pathfinding: fix missing waypoints in edge cases
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Jan 27, 2025
1 parent 9314f35 commit f8226ab
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/src/main/kotlin/fr/sncf/osrd/graph/Pathfinding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import java.util.*
import java.util.stream.Collectors
import kotlin.math.max

/**
* This class implements a pathfinding on an abstract graph, where the paths may end and start in
* the middle of edges.
*
* This should be considered as legacy, in the sense that we've had *a lot* of small increments and
* new features that weren't planned from the start. Although it works fine, it's very hard to
* navigate and modify. If we need to make any significant change in there, the best course of
* action would probably be to rewrite this whole class.
*/
@SuppressFBWarnings(
value = ["FE_FLOATING_POINT_EQUALITY"],
justification = "No arithmetic is done on values where we test for equality, only copies"
Expand Down Expand Up @@ -231,14 +240,19 @@ class Pathfinding<NodeT : Any, EdgeT : Any, OffsetType>(
val stepTargets = ArrayList(step.targets)
stepTargets.add(target)

// Handle overlapping consecutive waypoints
// Handle overlapping consecutive waypoints at the end of the edge (the only
// case we need to explicitly handle)
var newNReachedTargets = step.nReachedTargets + 1
while (
newNReachedTargets < targetsOnEdges.size &&
step.range.start == edgeToLength!!.apply(step.range.edge) &&
newNReachedTargets < targetsOnEdges.size &&
targetsOnEdges[newNReachedTargets]
.apply(step.range.edge)
.contains(EdgeLocation(step.range.edge, step.range.end))
) newNReachedTargets++
) {
newNReachedTargets++
stepTargets.add(EdgeLocation(step.range.edge, step.range.end))
}

registerStep(
newRange,
Expand Down

0 comments on commit f8226ab

Please sign in to comment.