diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt index ca2428bca6f..f9f5ca81f7c 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/pathfinding/PathfindingBlocksEndpointV2.kt @@ -18,6 +18,7 @@ import fr.sncf.osrd.stdcm.graph.extendLookaheadUntil import fr.sncf.osrd.stdcm.infra_exploration.initInfraExplorer import fr.sncf.osrd.utils.* import fr.sncf.osrd.utils.indexing.* +import fr.sncf.osrd.utils.units.Distance.Companion.min import fr.sncf.osrd.utils.units.Length import fr.sncf.osrd.utils.units.Offset import fr.sncf.osrd.utils.units.meters @@ -385,6 +386,14 @@ private fun getBlockOffset( ) } +/** + * Returns the block of the signal next to a waypoint block. + * + * @param waypointBlock waypoint block. + * @param infra full infra. + * @param rollingStockLength length of the rolling stock. + * @return next signal block. + */ fun findNextSignalBlockOnWaypointBlock( waypointBlock: PathfindingEdgeLocationId, infra: FullInfra, @@ -405,16 +414,8 @@ private fun getNextSignalOffset( val blockLength = infra.blockInfra.getBlockLength(blockId).distance val nextSignalPosition = signalsPositions.firstOrNull { it.distance >= blockOffset.distance } - // some blocks are < 1m long (even 0m), we can't get further in the block - val maxHeadOffset = - if (blockOffset.distance < 1.meters) { - blockOffset.distance - } else { - (nextSignalPosition?.distance ?: blockLength) - 1.meters - } - val minTailOffset = blockOffset.distance + rollingStockLength.meters - val finalOffset = if (minTailOffset <= maxHeadOffset) minTailOffset else maxHeadOffset + val maxHeadOffset = nextSignalPosition?.distance ?: blockLength - return Offset(finalOffset) + return Offset(min(minTailOffset, maxHeadOffset)) } diff --git a/core/src/test/kotlin/fr/sncf/osrd/pathfinding/PathfindingV2Test.kt b/core/src/test/kotlin/fr/sncf/osrd/pathfinding/PathfindingV2Test.kt index ea235a10e47..69b21f3fa45 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/pathfinding/PathfindingV2Test.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/pathfinding/PathfindingV2Test.kt @@ -362,7 +362,8 @@ class PathfindingV2Test : ApiTest() { .act(RqFake("POST", "/v2/pathfinding/blocks", reversedShortTrainRequestBody)) val reversedShortTrainResponse = TakesUtils.readBodyResponse(reversedShortTrainRawResponse) val reversedShortTrainParsed = - (pathfindingResponseAdapter.fromJson(reversedShortTrainResponse) as? PathfindingBlockSuccess)!! + (pathfindingResponseAdapter.fromJson(reversedShortTrainResponse) + as? PathfindingBlockSuccess)!! val longTrainRawResponse = PathfindingBlocksEndpointV2(infraManager) @@ -376,7 +377,8 @@ class PathfindingV2Test : ApiTest() { .act(RqFake("POST", "/v2/pathfinding/blocks", reversedLongTrainRequestBody)) val reversedLongTrainResponse = TakesUtils.readBodyResponse(reversedLongTrainRawResponse) val reversedLongTrainParsed = - (pathfindingResponseAdapter.fromJson(reversedLongTrainResponse) as? PathfindingBlockSuccess)!! + (pathfindingResponseAdapter.fromJson(reversedLongTrainResponse) + as? PathfindingBlockSuccess)!! assertEquals(3, nonStopAtNextSignalParsed.pathItemPositions.size) assertEquals(0.meters, nonStopAtNextSignalParsed.pathItemPositions[0].distance) @@ -396,7 +398,7 @@ class PathfindingV2Test : ApiTest() { assertEquals(3, longTrainParsed.pathItemPositions.size) assertEquals(0.meters, longTrainParsed.pathItemPositions[0].distance) assertEquals(12250.meters, longTrainParsed.pathItemPositions[1].distance) - assertEquals(26516.5.meters, longTrainParsed.pathItemPositions[2].distance) + assertEquals(26517.5.meters, longTrainParsed.pathItemPositions[2].distance) assertEquals(3, reversedLongTrainParsed.pathItemPositions.size) assertEquals(0.meters, reversedLongTrainParsed.pathItemPositions[0].distance)