Skip to content

Commit

Permalink
core: lint
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Jan 8, 2025
1 parent dcf6a2f commit 34d5a93
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ fun runPathfinding(
for (waypoint in step) {
val waypointBlocks = findWaypointBlocks(infra, waypoint, direction)
if (request.stopAtNextSignal && stepIndex != 0) {
allStarts.addAll(waypointBlocks.map { findNextSignalBlockOnWaypointBlock(it, infra, request.rollingStockLength) })
allStarts.addAll(
waypointBlocks.map {
findNextSignalBlockOnWaypointBlock(
it,
infra,
request.rollingStockLength
)
}
)
} else {
allStarts.addAll(waypointBlocks)
}
Expand Down Expand Up @@ -377,26 +385,33 @@ private fun getBlockOffset(
)
}

public fun findNextSignalBlockOnWaypointBlock(
fun findNextSignalBlockOnWaypointBlock(
waypointBlock: PathfindingEdgeLocationId<Block>,
infra: FullInfra,
rollingStockLength: Double
): PathfindingEdgeLocationId<Block> {
val nextSignalOffset = getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, rollingStockLength)
val nextSignalOffset =
getNextSignalOffset(waypointBlock.edge, waypointBlock.offset, infra, rollingStockLength)
return PathfindingEdgeLocationId(waypointBlock.edge, nextSignalOffset)
}

private fun getNextSignalOffset(blockId: BlockId, blockOffset: Offset<Block>, infra: FullInfra, rollingStockLength: Double): Offset<Block> {
private fun getNextSignalOffset(
blockId: BlockId,
blockOffset: Offset<Block>,
infra: FullInfra,
rollingStockLength: Double
): Offset<Block> {
val signalsPositions = infra.blockInfra.getSignalsPositions(blockId)
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 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take {
convertWorkScheduleCollection(infra.rawInfra, request.workSchedules)
trainsRequirements.add(convertedWorkSchedules)
val spacingRequirements = trainsRequirements.flatMap { it.spacingRequirements }
val steps = parseSteps(infra, request.pathItems, request.startTime, request.rollingStock.length.distance.meters)
val steps =
parseSteps(
infra,
request.pathItems,
request.startTime,
request.rollingStock.length.distance.meters
)

// Run the STDCM pathfinding
val path =
Expand Down

0 comments on commit 34d5a93

Please sign in to comment.