spatial-monorepo / wayfinding/src / finalizeSegmentInstructions
Function: finalizeSegmentInstructions()
finalizeSegmentInstructions(
archive,walkInstructions,levelId,isFirstSegment,incomingTransition,transitionAfter):Instruction[]
Defined in: packages/wayfinding/src/grid-multifloor.ts:372
Turns one floor segment's raw walk instructions into the final instruction list for its Leg, layering take-connection/exit-connection steps around floor transitions (issue #484):
isFirstSegmentlegs keep their natural leadingdepart(the true start of the whole route); every other leg's leadingdepartis replaced with anexit-connectionstep (you've just left the elevator/stairs/etc. that got you onto this floor).- A leg with
transitionAfter(i.e. not the final leg) has its trailingarrivereplaced with atake-connectionstep carrying the real destination level name and vertical category. - Degenerate case: a floor segment can collapse to a single walk instruction (
buildWalkInstructionson a 0/1-point path — the entry and exit portals coincide, e.g. a pass-through floor with no walking at all) while both an incoming and an outgoing transition apply. Naively replacing that lone instruction twice — once forexit-connection, once fortake-connection— would silently discard the exit step, since the second replacement overwrites the first. Emit both connection steps back to back instead of collapsing them into one. - Issue #943: the same collapse can happen with only one side needed — the first segment's origin (or the last segment's destination) lands exactly on a portal cell, so its lone walk instruction is a genuine
depart(first segment) orarrive(last segment), not a pass-through. The general single-instruction replacement below would consume that sole instruction for the connection step, silently dropping the depart/arrive. Mirror the dual-collision guard: keep the genuine depart/arrive and emit the connection step alongside it instead of overwriting it.
Parameters
archive
walkInstructions
levelId
string
isFirstSegment
boolean
incomingTransition
{ category: VerticalCategory; fromLevelId: string; } | undefined
transitionAfter
{ category: VerticalCategory; toLevelId: string; } | undefined
