@expofp/wayfinding 3.45.3 → 3.45.5

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.
@@ -39,8 +39,11 @@ export function animateLineSegments(segments, onChange, getPixelSize, startProgr
39
39
  const dy = end.p1.y - end.p0.y;
40
40
  return Math.sqrt(dx * dx + dy * dy);
41
41
  });
42
- /** The fraction each segment is currently drawn at; `-1` until it has been written even once. */
43
- const drawn = segments.map(() => -1);
42
+ /**
43
+ * The fraction each segment is currently drawn at; `-1` until it has been written even once. A
44
+ * segment handed over hidden already reads as empty, so the opening render skips it.
45
+ */
46
+ const drawn = segments.map((segment) => (segment.hidden ? NOTHING : -1));
44
47
  /** What the frame being rendered moved, refilled per frame so a frame allocates nothing. */
45
48
  const changed = [];
46
49
  const totalLength = segmentLengths.reduce((a, b) => a + b, 0);
@@ -105,8 +108,10 @@ export function animateLineSegments(segments, onChange, getPixelSize, startProgr
105
108
  const head = currentSegmentIndex;
106
109
  for (let i = 0; i < head; i++)
107
110
  draw(i, WHOLE);
108
- // A zero-length segment divides to `Infinity` and so is whole the moment the head reaches it.
109
- draw(head, Math.min(segmentProgress / segmentLengths[head], WHOLE));
111
+ // A zero-length segment is whole the moment the head reaches it: dividing by its length gives
112
+ // `Infinity` once the head has moved, but `NaN` on the opening render, where progress is zero.
113
+ const headLength = segmentLengths[head];
114
+ draw(head, headLength ? Math.min(segmentProgress / headLength, WHOLE) : WHOLE);
110
115
  for (let i = head + 1; i < segments.length; i++)
111
116
  draw(i, NOTHING);
112
117
  if (changed.length)
@@ -148,6 +153,9 @@ export function animateLineSegments(segments, onChange, getPixelSize, startProgr
148
153
  segmentProgress = 0;
149
154
  }
150
155
  lastTimestamp = null;
156
+ // Drawn now rather than on the first frame, so the segments go into the caller's commit already
157
+ // in their resumed state: a chase that waited for its first frame left the route blank for one.
158
+ render();
151
159
  animationFrameId = requestAnimationFrame(animate);
152
160
  }
153
161
  function stop() {
@@ -9,6 +9,19 @@ import { animateLineSegments } from './lineAnimation.js';
9
9
  function lineDef({ p0, p1 }, color) {
10
10
  return { points: { p0: { x: p0.x, y: p0.y }, p1: { x: p1.x, y: p1.y } }, color, width: 10 };
11
11
  }
12
+ /**
13
+ * Whether a line was built from this segment: the same endpoints, compared where
14
+ * {@link lineDef} copied them.
15
+ * @param def - The line.
16
+ * @param seg - The segment.
17
+ * @returns Whether they match.
18
+ */
19
+ function sameSegment(def, seg) {
20
+ return (def.points.p0.x === seg.p0.x &&
21
+ def.points.p0.y === seg.p0.y &&
22
+ def.points.p1.x === seg.p1.x &&
23
+ def.points.p1.y === seg.p1.y);
24
+ }
12
25
  /**
13
26
  * Create a {@link RouteLineManager} that renders `LineDef` segments
14
27
  * into layers managed by the given {@link LayerManager}.
@@ -63,14 +76,34 @@ export function createRouteLineManager(layerManager, colors, port, layers) {
63
76
  layerManager.touchDef(def);
64
77
  }
65
78
  }
79
+ /**
80
+ * Whether the layers already hold exactly these segments, split at the same place. The static
81
+ * defs are never moved, so their points still read as the segments they were built from; the
82
+ * animated layer holds one def per remaining segment, which is where the split shows.
83
+ * @param passed - The segments behind the position.
84
+ * @param remaining - The segments ahead of it.
85
+ * @returns Whether the layers hold them.
86
+ */
87
+ function holdsSameLines(passed, remaining) {
88
+ const current = linesLayer.children;
89
+ if (current.length !== passed.length + remaining.length)
90
+ return false;
91
+ if (animatedLayer.children.length !== remaining.length)
92
+ return false;
93
+ return (passed.every((seg, i) => sameSegment(current[i], seg)) &&
94
+ remaining.every((seg, i) => sameSegment(current[passed.length + i], seg)));
95
+ }
66
96
  return {
67
97
  setRouteLines(passed, remaining, options) {
98
+ const reset = options?.resetAnimation ?? true;
99
+ // The same lines again: let the chase run on instead of remounting every def under it.
100
+ if (!reset && holdsSameLines(passed, remaining))
101
+ return;
68
102
  layerManager.touchLayer(linesLayer);
69
103
  layerManager.touchLayer(animatedLayer);
70
104
  // Declared on every call rather than at construction: the `update(layer)` a flush performs is
71
105
  // what makes the renderer register the layer under this handler.
72
106
  animatedLayer.onScale = ({ pixelSize }) => readPixelSize(pixelSize);
73
- const reset = options?.resetAnimation ?? true;
74
107
  let resumeFrom = 0;
75
108
  if (animationHandle) {
76
109
  if (!reset)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expofp/wayfinding",
3
- "version": "3.45.3",
3
+ "version": "3.45.5",
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": "3.45.3"
37
+ "@expofp/geometry": "3.45.5"
38
38
  },
39
39
  "peerDependencies": {
40
- "@expofp/renderer": "3.45.3"
40
+ "@expofp/renderer": "3.45.5"
41
41
  },
42
42
  "devDependencies": {
43
- "@expofp/renderer": "3.45.3"
43
+ "@expofp/renderer": "3.45.5"
44
44
  }
45
45
  }