Skip to content

Commit

Permalink
core: remove block borders condition
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Jan 14, 2025
1 parent 471e876 commit bac5a63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Block>,
infra: FullInfra,
Expand All @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit bac5a63

Please sign in to comment.