Skip to content

spatial-monorepo


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):

  • isFirstSegment legs keep their natural leading depart (the true start of the whole route); every other leg's leading depart is replaced with an exit-connection step (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 trailing arrive replaced with a take-connection step carrying the real destination level name and vertical category.
  • Degenerate case: a floor segment can collapse to a single walk instruction (buildWalkInstructions on 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 for exit-connection, once for take-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) or arrive (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

IMDFArchive

walkInstructions

Instruction[]

levelId

string

isFirstSegment

boolean

incomingTransition

{ category: VerticalCategory; fromLevelId: string; } | undefined

transitionAfter

{ category: VerticalCategory; toLevelId: string; } | undefined

Returns

Instruction[]

Released under commercial licensing.