@expofp/wayfinding 0.0.0-experimental.2632d13 → 0.0.0-experimental.3b0db16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,20 +3,17 @@ import { createAStarPathFinder } from './pathfinder/aStarPathFinder.js';
3
3
  export function createGraphCache() {
4
4
  let cached = null;
5
5
  let cachedOnlyAccessible = false;
6
- let cachedLines = null;
7
6
  return {
8
7
  getOrBuild(dataSource, onlyAccessible) {
9
- // Keyed on `onlyAccessible` and on the identity of the lines the source serves: a
10
- // source may hand out a new array when its data changes (a campus graph is
11
- // partitioned again once the venue model arrives), and a graph built from the
12
- // old one would route over nodes the source no longer has.
13
- const lines = dataSource.getLines();
14
- if (cached && cachedOnlyAccessible === onlyAccessible && cachedLines === lines)
8
+ // Cache is keyed only on `onlyAccessible`, not on dataSource identity, so it
9
+ // never invalidates if the floorplan data changes. Safe because each floorplan
10
+ // loads a fresh engine (hence a fresh cache) — a cached graph never outlives
11
+ // its dataSource. Add an identity check + invalidation if that ever stops holding.
12
+ if (cached && cachedOnlyAccessible === onlyAccessible)
15
13
  return cached;
16
14
  const pathFinder = createAStarPathFinder();
17
15
  cached = buildGraph(dataSource, pathFinder, { oriented: true, onlyAccessible });
18
16
  cachedOnlyAccessible = onlyAccessible;
19
- cachedLines = lines;
20
17
  return cached;
21
18
  },
22
19
  };
@@ -17,17 +17,6 @@ const MERGE_ANGLE_THRESHOLD = degToRad(5);
17
17
  export function canMergeSegments(lastSegment, segment) {
18
18
  if (lastSegment.virtual !== segment.virtual)
19
19
  return false;
20
- // Merging discards the junction point, which is only safe inside one layer.
21
- // A segment whose endpoints sit on different layers IS the floor/venue
22
- // transition, and collapsing it erases that level from the route. Stairs
23
- // normally share x/y across floors, so such a link has zero length and
24
- // `lineAngle` returns atan2(0, 0) === 0 — an angle that spuriously matches
25
- // any horizontal neighbour and would otherwise merge right through it.
26
- if ((lastSegment.p0.layer ?? '') !== (lastSegment.p1.layer ?? '') ||
27
- (segment.p0.layer ?? '') !== (segment.p1.layer ?? '') ||
28
- (lastSegment.p1.layer ?? '') !== (segment.p0.layer ?? '')) {
29
- return false;
30
- }
31
20
  const lastAngle = lineAngle(lastSegment.p0, lastSegment.p1);
32
21
  const angle = lineAngle(segment.p0, segment.p1);
33
22
  let diff = Math.abs(angle - lastAngle);
@@ -2,11 +2,8 @@ import { type RouteLine } from '../types.js';
2
2
  interface TransitionPointsInput {
3
3
  /** Full route including virtual lines */
4
4
  readonly routeLines: RouteLine[];
5
- /**
6
- * Floors to scope to — one per venue when several venues show a level at once.
7
- * `null` = no floor scoping (returns transitions on every floor).
8
- */
9
- readonly currentLayerNames: readonly string[] | null;
5
+ /** Floor to scope to. `null` = no floor scoping (returns transitions on every floor). */
6
+ readonly currentLayerName: string | null;
10
7
  /** Floor names ordered low → high (from layerStore.floors) */
11
8
  readonly floorOrder: string[];
12
9
  }
@@ -23,7 +20,7 @@ export interface TransitionPointDef {
23
20
  }
24
21
  /**
25
22
  * Computes deduplicated, correctly-directed transition points for the
26
- * current floors.
23
+ * current floor.
27
24
  *
28
25
  * Works directly with the full `routeLines` array (including virtual lines)
29
26
  * and does NOT depend on `routeNextFloor` — the target floor is read from
@@ -55,7 +55,7 @@ function resolveTransitTarget(crossFloorLines, floorsWithPhysicalLines, currentL
55
55
  // ---------------------------------------------------------------------------
56
56
  /**
57
57
  * Computes deduplicated, correctly-directed transition points for the
58
- * current floors.
58
+ * current floor.
59
59
  *
60
60
  * Works directly with the full `routeLines` array (including virtual lines)
61
61
  * and does NOT depend on `routeNextFloor` — the target floor is read from
@@ -63,8 +63,7 @@ function resolveTransitTarget(crossFloorLines, floorsWithPhysicalLines, currentL
63
63
  * @param input
64
64
  */
65
65
  export function computeTransitionPoints(input) {
66
- const { routeLines, currentLayerNames, floorOrder } = input;
67
- const isCurrentFloor = (layer) => currentLayerNames === null || currentLayerNames.some((name) => layersMatch(layer, name));
66
+ const { routeLines, currentLayerName, floorOrder } = input;
68
67
  // 1. Only virtual lines that actually cross floors
69
68
  const crossFloorLines = routeLines.filter((line) => line.virtual && !layersMatch(line.p0.layer, line.p1.layer));
70
69
  // 2. Floors that have physical (non-virtual) route lines — used to skip transit floors
@@ -75,11 +74,14 @@ export function computeTransitionPoints(input) {
75
74
  floorsWithPhysicalLines.add(line.p1.layer.toLowerCase());
76
75
  }
77
76
  }
78
- // 3. Keep only lines touching a current floor (when set)
79
- const relevantLines = crossFloorLines.filter((line) => isCurrentFloor(line.p0.layer) || isCurrentFloor(line.p1.layer));
80
- // 4. Pick the endpoint on a current floor; the other is the target
77
+ // 3. Keep only lines touching the current floor (when set)
78
+ const relevantLines = currentLayerName
79
+ ? crossFloorLines.filter((line) => layersMatch(line.p0.layer, currentLayerName) ||
80
+ layersMatch(line.p1.layer, currentLayerName))
81
+ : crossFloorLines;
82
+ // 4. Pick the endpoint on the current floor; the other is the target
81
83
  const points = relevantLines.map((line) => {
82
- const pickP0 = isCurrentFloor(line.p0.layer);
84
+ const pickP0 = currentLayerName ? layersMatch(line.p0.layer, currentLayerName) : true;
83
85
  const visible = pickP0 ? line.p0 : line.p1;
84
86
  const target = pickP0 ? line.p1 : line.p0;
85
87
  // Follow virtual chain through transit floors (e.g. L1→L2(transit)→L3 → targetLayer=L3)
@@ -91,8 +93,8 @@ export function computeTransitionPoints(input) {
91
93
  targetLayer: resolvedTarget,
92
94
  direction: resolveDirection(floorOrder, visible.layer, resolvedTarget),
93
95
  // Current-floor endpoint at `p0` → route departs here → "exit" (clickable
94
- // to advance); at `p1` → arrives here → "entry". No scoping → default "exit".
95
- role: pickP0 ? 'exit' : 'entry',
96
+ // to advance); at `p1` → arrives here → "entry". Null layer → default "exit".
97
+ role: currentLayerName ? (pickP0 ? 'exit' : 'entry') : 'exit',
96
98
  };
97
99
  });
98
100
  // 5. Deduplicate by coordinates. Drop entries that collide with an exit
@@ -1,7 +1,7 @@
1
1
  import type { Box } from '@expofp/geometry';
2
2
  import type { RenderableDef } from '@expofp/renderer';
3
3
  import { type GpsProjectionConfig, type GraphDataSource, type Route, type RouteEndpoint, type RouteLine, type RoutePoint, type TransitionPointDef } from './core/index.js';
4
- import { type IconConfig, type RendererPort, type WayfindingLayers, type WayfindingRendererConfig } from './renderer/index.js';
4
+ import { type IconConfig, type RendererPort, type WayfindingLayers } from './renderer/index.js';
5
5
  import { type FloorContext, type IconProvider, type PositionInput, type SetRouteInput } from './runtime/index.js';
6
6
  /** Plan GPS calibration plus optional snap / reroute distance overrides (meters). */
7
7
  export type GpsConfig = GpsProjectionConfig & {
@@ -20,8 +20,6 @@ export interface WayfindingConfig {
20
20
  readonly floorContext: FloorContext;
21
21
  /** The layers from `initWayfindingLayers()` — the block the host mounted, which this fills. */
22
22
  readonly layers: WayfindingLayers;
23
- /** Route line colors; defaults apply for anything omitted. */
24
- readonly rendererConfig?: WayfindingRendererConfig;
25
23
  /** Plan GPS calibration; the snap and reroute thresholds are derived from it. */
26
24
  readonly gpsConfig?: GpsConfig;
27
25
  /**
@@ -5,7 +5,6 @@ export function createWayfinding(config) {
5
5
  const { dataSource, renderer: rendererPort, iconProvider, floorContext, layers, gpsConfig, } = config;
6
6
  const engine = createWayfindingEngine(dataSource);
7
7
  const renderer = createWayfindingRenderer(rendererPort, layers, {
8
- ...config.rendererConfig,
9
8
  screenSpaceIcons: config.screenSpaceIcons,
10
9
  });
11
10
  const snapThresholdMeters = getThresholdOrDefault(gpsConfig?.snapThreshold, SNAP_THRESHOLD_METERS);
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { createWayfinding } from './createWayfinding.js';
9
9
  export type { WayfindingLayerOptions, WayfindingLayers } from './renderer/index.js';
10
10
  export { initWayfindingLayers, resolveWayfindingLayers } from './renderer/index.js';
11
11
  export type { GraphDataSource } from './core/index.js';
12
- export type { IconConfig, RendererPort, RouteColors, TrailOptions, WayfindingRendererConfig, } from './renderer/index.js';
12
+ export type { IconConfig, RendererPort, TrailOptions } from './renderer/index.js';
13
13
  export type { FloorContext, IconAsset, IconName, IconProvider } from './runtime/index.js';
14
14
  export type { GraphLine, Route, RouteEndpoint, RouteLine, RoutePoint, TransitionPointDef, } from './core/index.js';
15
15
  export type { PositionInput, SetRouteInput } from './runtime/index.js';
@@ -1,5 +1,5 @@
1
1
  export { createWayfindingRenderer } from './createWayfindingRenderer.js';
2
2
  export type { WayfindingLayerOptions, WayfindingLayers } from './layers.js';
3
3
  export { initWayfindingLayers, resolveWayfindingLayers } from './layers.js';
4
- export type { IconConfig, RendererPort, RouteColors, TrailOptions, WayfindingRenderer, WayfindingRendererConfig, } from './types.js';
4
+ export type { IconConfig, RendererPort, TrailOptions, WayfindingRenderer } from './types.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -39,16 +39,16 @@ export function createWayfindingRuntime({ engine, renderer, iconProvider, floorC
39
39
  let hasSnappedCurrentRoute = false;
40
40
  // Live snap state of the latest tick (not sticky) — drives the greyed-out source variant.
41
41
  let snappedToRoute = false;
42
- function getActiveFloors() {
42
+ function getCurrentRouteLayer() {
43
43
  if (floorContext.showAllFloors())
44
44
  return null;
45
- return floorContext.getActiveFloors();
45
+ return floorContext.getActiveFloor();
46
46
  }
47
47
  function getVisibleLines() {
48
- const floors = getActiveFloors();
49
- if (floors === null)
48
+ const layer = getCurrentRouteLayer();
49
+ if (layer === null)
50
50
  return routeLines.filter((line) => !line.virtual);
51
- return routeLines.filter((line) => floors.includes(line.p0.layer) && !line.virtual);
51
+ return routeLines.filter((line) => line.p0.layer === layer && !line.virtual);
52
52
  }
53
53
  // Non-virtual lines across all floors — the same set emitted via `onRouteUpdate`
54
54
  // (see `computeRouteUpdate`), so reroute drift is measured against the full route.
@@ -73,7 +73,7 @@ export function createWayfindingRuntime({ engine, renderer, iconProvider, floorC
73
73
  return;
74
74
  const data = computeRouteRenderData({
75
75
  routeLines,
76
- activeFloors: getActiveFloors(),
76
+ currentRouteLayer: getCurrentRouteLayer(),
77
77
  snap,
78
78
  });
79
79
  routeLinesView.draw(data, preserveProgress);
@@ -9,22 +9,22 @@ interface RouteRenderData {
9
9
  }
10
10
  /**
11
11
  * Pure pipeline that produces the data needed to render the route: the
12
- * passed/remaining split for the visible floors plus the remaining
12
+ * passed/remaining split for the visible floor plus the remaining
13
13
  * distance to the destination.
14
14
  *
15
- * The full non-virtual route is sliced down to the visible floors for rendering.
15
+ * The full non-virtual route is sliced down to the visible floor for rendering.
16
16
  * The remaining distance is read from `snap.distance` (computed once by the
17
17
  * runtime snap, `snapPositionToRoute`); with no snap it falls back to the full
18
18
  * route length.
19
19
  * @param root0
20
20
  * @param root0.routeLines
21
- * @param root0.activeFloors
21
+ * @param root0.currentRouteLayer
22
22
  * @param root0.snap
23
23
  */
24
- export declare function computeRouteRenderData({ routeLines, activeFloors, snap, }: {
24
+ export declare function computeRouteRenderData({ routeLines, currentRouteLayer, snap, }: {
25
25
  readonly routeLines: RouteLine[];
26
- /** null = show-all mode; otherwise the active route floors. */
27
- readonly activeFloors: readonly string[] | null;
26
+ /** null = show-all mode; otherwise the active route floor. */
27
+ readonly currentRouteLayer: string | null;
28
28
  readonly snap: RouteSnapResult | null;
29
29
  }): RouteRenderData;
30
30
  export {};
@@ -1,30 +1,32 @@
1
1
  import { getRouteLength, splitRouteByPoint, } from '../core/index.js';
2
2
  /**
3
3
  * Pure pipeline that produces the data needed to render the route: the
4
- * passed/remaining split for the visible floors plus the remaining
4
+ * passed/remaining split for the visible floor plus the remaining
5
5
  * distance to the destination.
6
6
  *
7
- * The full non-virtual route is sliced down to the visible floors for rendering.
7
+ * The full non-virtual route is sliced down to the visible floor for rendering.
8
8
  * The remaining distance is read from `snap.distance` (computed once by the
9
9
  * runtime snap, `snapPositionToRoute`); with no snap it falls back to the full
10
10
  * route length.
11
11
  * @param root0
12
12
  * @param root0.routeLines
13
- * @param root0.activeFloors
13
+ * @param root0.currentRouteLayer
14
14
  * @param root0.snap
15
15
  */
16
- export function computeRouteRenderData({ routeLines, activeFloors, snap, }) {
16
+ export function computeRouteRenderData({ routeLines, currentRouteLayer, snap, }) {
17
17
  const nonVirtualOrdered = routeLines.filter((line) => !line.virtual);
18
- const clipToVisibleFloors = (lines) => activeFloors === null ? lines : lines.filter((line) => activeFloors.includes(line.p0.layer));
18
+ const clipToVisibleFloor = (lines) => currentRouteLayer === null
19
+ ? lines
20
+ : lines.filter((line) => line.p0.layer === currentRouteLayer);
19
21
  if (!snap?.snapped) {
20
22
  return {
21
23
  passed: [],
22
- remaining: clipToVisibleFloors(nonVirtualOrdered),
24
+ remaining: clipToVisibleFloor(nonVirtualOrdered),
23
25
  distance: getRouteLength(nonVirtualOrdered),
24
26
  };
25
27
  }
26
28
  // Split the full route at the snap point first, then filter each side to the visible
27
- // floors, so an already-passed floor renders fully as passed even when the snap is on a
29
+ // floor, so an already-passed floor renders fully as passed even when the snap is on a
28
30
  // later floor.
29
31
  const { passed, remaining } = splitRouteByPoint(nonVirtualOrdered, snap.snappedPoint);
30
32
  // Ref-equal result means no segment matched the snap layer (bestIndex === -1); only on a
@@ -37,8 +39,8 @@ export function computeRouteRenderData({ routeLines, activeFloors, snap, }) {
37
39
  ? [{ ...remaining[0], p0: snap.snappedPoint }, ...remaining.slice(1)]
38
40
  : remaining;
39
41
  return {
40
- passed: clipToVisibleFloors(passed),
41
- remaining: clipToVisibleFloors(adjustedRemaining),
42
+ passed: clipToVisibleFloor(passed),
43
+ remaining: clipToVisibleFloor(adjustedRemaining),
42
44
  distance: snap.distance,
43
45
  };
44
46
  }
@@ -14,6 +14,6 @@ export interface TrailView {
14
14
  export declare function createTrailView({ renderer, iconProvider, floorContext, }: {
15
15
  renderer: Pick<WayfindingRenderer, 'setTrail'>;
16
16
  iconProvider: Pick<IconProvider, 'getIcon'>;
17
- floorContext: Pick<FloorContext, 'showAllFloors' | 'getActiveFloors'>;
17
+ floorContext: Pick<FloorContext, 'showAllFloors' | 'getActiveFloor'>;
18
18
  }): TrailView;
19
19
  //# sourceMappingURL=trailView.d.ts.map
@@ -2,7 +2,7 @@ export function createTrailView({ renderer, iconProvider, floorContext, }) {
2
2
  const activeSlots = new Set();
3
3
  /**
4
4
  * Trails share one global layer (not per-floor). In scoped-floor mode the
5
- * trail renders only when both endpoints lie on an active floor —
5
+ * trail renders only when both endpoints lie on the active floor —
6
6
  * otherwise the line would bleed through on unrelated floors.
7
7
  * @param fromLayer
8
8
  * @param toLayer
@@ -10,8 +10,10 @@ export function createTrailView({ renderer, iconProvider, floorContext, }) {
10
10
  function isTrailVisible(fromLayer, toLayer) {
11
11
  if (floorContext.showAllFloors())
12
12
  return true;
13
- const activeFloors = floorContext.getActiveFloors();
14
- return activeFloors.includes(fromLayer) && activeFloors.includes(toLayer);
13
+ const activeFloor = floorContext.getActiveFloor();
14
+ if (!activeFloor)
15
+ return false;
16
+ return fromLayer === activeFloor && toLayer === activeFloor;
15
17
  }
16
18
  function clearSlot(slot) {
17
19
  renderer.setTrail(slot, null, null);
@@ -9,7 +9,7 @@ interface TransitionView {
9
9
  export declare function createTransitionView({ renderer, iconProvider, floorContext, onTransitionClick, }: {
10
10
  renderer: Pick<WayfindingRenderer, 'setIcon' | 'clearIcons'>;
11
11
  iconProvider: Pick<IconProvider, 'getIcon'>;
12
- floorContext: Pick<FloorContext, 'showAllFloors' | 'getActiveFloors' | 'getFloorOrder'>;
12
+ floorContext: Pick<FloorContext, 'showAllFloors' | 'getActiveFloor' | 'getFloorOrder'>;
13
13
  onTransitionClick: (point: TransitionPointDef) => void;
14
14
  }): TransitionView;
15
15
  export {};
@@ -6,20 +6,21 @@ export function createTransitionView({ renderer, iconProvider, floorContext, onT
6
6
  renderer.clearIcons(TRANSITION_ICON_NAME);
7
7
  // `null` here means "don't scope to a floor" (computeTransitionPoints
8
8
  // returns transitions for every floor). Only emit `null` in show-all
9
- // mode — in scoped mode with no resolvable active floor we must
9
+ // mode — in scoped mode with an unresolvable active floor we must
10
10
  // hide transitions instead of accidentally placing them on all floors.
11
- let currentLayerNames;
11
+ let currentLayerName;
12
12
  if (floorContext.showAllFloors()) {
13
- currentLayerNames = null;
13
+ currentLayerName = null;
14
14
  }
15
15
  else {
16
- currentLayerNames = floorContext.getActiveFloors();
17
- if (!currentLayerNames.length)
16
+ const activeFloor = floorContext.getActiveFloor();
17
+ if (!activeFloor)
18
18
  return;
19
+ currentLayerName = activeFloor;
19
20
  }
20
21
  const transitionPoints = computeTransitionPoints({
21
22
  routeLines,
22
- currentLayerNames,
23
+ currentLayerName,
23
24
  floorOrder: floorContext.getFloorOrder(),
24
25
  });
25
26
  for (const [index, point] of transitionPoints.entries()) {
@@ -66,15 +66,14 @@ export interface WayfindingRuntimeConfig {
66
66
  * that bridges to a concrete store (e.g., efp `LayerStore` + `RouteStore`).
67
67
  *
68
68
  * - {@link showAllFloors} — true when the map is rendering all floors simultaneously (no floor scoping/single-floor).
69
- * - {@link getActiveFloors} — names of the active route floors: one on a single-venue plan, one
70
- * level per venue when several venues show a level at once; empty when unresolvable.
71
- * Callers must check `!showAllFloors()` first.
69
+ * - {@link getActiveFloor} — name of the active route floor, or `""` when unresolvable;
70
+ * callers must check `!showAllFloors()` first.
72
71
  * - {@link isLayerVisible} — per-layer visibility for endpoint dim/hide and cross-floor trail gating.
73
72
  * - {@link getFloorOrder} — stable floor-name order used by transition placement.
74
73
  */
75
74
  export interface FloorContext {
76
75
  showAllFloors(): boolean;
77
- getActiveFloors(): readonly string[];
76
+ getActiveFloor(): string;
78
77
  isLayerVisible(layer: string): boolean;
79
78
  getFloorOrder(): string[];
80
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expofp/wayfinding",
3
- "version": "0.0.0-experimental.2632d13",
3
+ "version": "0.0.0-experimental.3b0db16",
4
4
  "type": "module",
5
5
  "description": "ExpoFP SDK internal: framework-neutral wayfinding (routing, snapping, scene rendering)",
6
6
  "homepage": "https://developer.expofp.com/",
@@ -34,12 +34,12 @@
34
34
  "dependencies": {
35
35
  "ngraph.graph": "^19.1.0",
36
36
  "tslib": "^2.3.0",
37
- "@expofp/geometry": "0.0.0-experimental.2632d13"
37
+ "@expofp/geometry": "0.0.0-experimental.3b0db16"
38
38
  },
39
39
  "peerDependencies": {
40
- "@expofp/renderer": "0.0.0-experimental.2632d13"
40
+ "@expofp/renderer": "0.0.0-experimental.3b0db16"
41
41
  },
42
42
  "devDependencies": {
43
- "@expofp/renderer": "0.0.0-experimental.2632d13"
43
+ "@expofp/renderer": "0.0.0-experimental.3b0db16"
44
44
  }
45
45
  }