Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/RouteGuidanceTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Viewscreen/RouteGuidance.h"
2#include <cstdlib>
3#include <iostream>
4
5using G = RouteGuidance;
6static int checks = 0;
7static void Check(bool condition, const char* message)
8{
9 ++checks;
10 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
11}
12static bool HasReroute(const std::vector<G::Cue>& cues)
13{
14 return std::any_of(cues.begin(), cues.end(), [](const G::Cue& cue) { return cue.type == G::Recalculating; });
15}
16static void CheckRerouting()
17{
18 const std::vector<G::Node> straight = {{{0,0},1,"First"},{{1,0},1,"First"}};
19 G guidance;
20 guidance.Reset(straight);
21 for (int i = 0; i < 10; ++i)
22 Check(!HasReroute(guidance.Update({-0.3f,0.1f},0,1)), "waiting off-road for initial entry does not recalculate");
23 for (int i = 1; i <= 20; ++i)
24 Check(!HasReroute(guidance.Update({-0.3f + i * 0.01f,0.1f},30,1)), "approaching a distant entry is valid progress");
25
26 // Bill's 22:09:34 UI Building request after arriving at Techform.
27 // Origin and first road nodes are from the server log; the departure is simulated.
28 guidance.Reset({{{519.5770f,1102.196f},1,"8TH ST"},{{519.6122f,1102.231f},1,"8TH ST"},
29 {{519.6507f,1102.269f},1,"8TH ST"}});
30 guidance.Update({519.5502f,1102.214f},0,1);
31 Check(!HasReroute(guidance.Update({519.5200f,1102.245f},30,1)), "moving away from Bill's entry first starts confirmation");
32 Check(!HasReroute(guidance.Update({519.5150f,1102.250f},30,1)), "entry deviation waits for sustained evidence");
33 auto cues = guidance.Update({519.5100f,1102.255f},30,1);
34 Check(cues.size()==1 && HasReroute(cues) && cues[0].meters>50 && cues[0].WireDirection()==0,
35 "driving away from the new entry requests the existing server recalculation packet");
36 for (int i = 0; i < 14; ++i)
37 Check(guidance.Update({519.5100f,1102.255f},0,1).empty(), "pending recalculation suppresses stale cues and request floods");
38 Check(HasReroute(guidance.Update({519.5100f,1102.255f},0,1)), "a missing route response retries after fifteen seconds");
39
40 // A received replacement route resets all deviation and retry state.
41 guidance.Reset(straight);
42 guidance.Update({0.3f,0},50,1);
43 Check(!HasReroute(guidance.Update({0.27f,0},50,1)), "wrong-way travel on the road starts confirmation");
44 Check(!HasReroute(guidance.Update({0.26f,0},50,1)), "wrong-way travel is not an instantaneous trigger");
45 Check(HasReroute(guidance.Update({0.25f,0},50,1)), "wrong-way travel recalculates despite zero lateral distance");
46 guidance.Reset();
47 Check(guidance.Update({2,2},50,1).empty(), "clearing navigation cancels pending recalculation");
48
49 for (const int fps : {10,60,144})
50 {
51 guidance.Reset({{{0,0},1,"First"},{{0.5f,0},1,"First"},{{0.5f,-0.5f},2,"Second"}});
52 guidance.Update({0.4f,0},50,1.0f/fps);
53 int requests = 0;
54 for (int frame = 0; frame < fps * 4; ++frame)
55 {
56 // Continue straight through the required left turn, then remain off-route.
57 cues = guidance.Update({0.55f,0},50,1.0f/fps);
58 if (HasReroute(cues))
59 {
60 ++requests;
61 Check(frame >= fps * 2.9f && frame <= fps * 3.1f, "wrong-turn confirmation uses elapsed seconds at any frame rate");
62 Check(cues.size()==1, "a recalculation replaces other cues in that update");
63 }
64 }
65 Check(requests==1, "a sustained missed turn emits one request while awaiting a route");
66 }
67
68 guidance.Reset(straight);
69 guidance.Update({0.1f,0},50,1);
70 for (int i = 0; i < 4; ++i)
71 {
72 Check(!HasReroute(guidance.Update({0.2f,0.04f},30,1)), "a brief excursion beyond fifty meters does not reroute");
73 Check(!HasReroute(guidance.Update({0.21f,0},30,1)), "returning to the road clears deviation confirmation");
74 }
75 guidance.Reset(straight);
76 guidance.Update({0.1f,0},50,1);
77 Check(!HasReroute(guidance.Update({0.2f,0.04f},30,60)), "one stalled frame cannot immediately trigger recalculation");
78 guidance.Update({0.2f,0},30,1);
79 for (int i = 1; i <= 20; ++i)
80 Check(!HasReroute(guidance.Update({0.2f+i*0.01f,0.005f},50,1)), "normal forward travel with lane offset does not reroute");
81
82 guidance.Reset({{{0,0},1,"First"},{{0.5f,0},1,"First"},
83 {{0.5f,-0.0025f},2,"Second"},{{0.5f,-0.5f},2,"Second"}});
84 guidance.Update({0.48f,0},50,1);
85 for (int i = 1; i <= 5; ++i)
86 Check(!HasReroute(guidance.Update({0.5f,-i*0.02f},50,1)), "rounding tiny intersection links remains valid route progress");
87
88 guidance.Reset(straight);
89 guidance.Update({0.99f,0},0,1);
90 Check(guidance.IsComplete(), "arrival still completes guidance before deviation checks");
91 for (int i = 0; i < 4; ++i)
92 Check(guidance.Update({2,2},50,1).empty(), "driving after arrival does not resurrect the completed route");
93 guidance.Reset(straight);
94 guidance.Update({-0.1f,0},0,1);
95 guidance.Update({-0.15f,0},30,1);
96 guidance.Update({-0.16f,0},30,1);
97 Check(HasReroute(guidance.Update({-0.17f,0},30,1)), "a new destination after arrival can trigger recalculation");
98}
99static void CheckRecalculationCooldown()
100{
101 const std::vector<G::Node> straight = {{{0,0},1,"RESKIN WAY"},{{1,0},1,"RESKIN WAY"}};
102 for (const int fps : {10,60,144})
103 {
104 G guidance;
105 guidance.Reset(straight);
106 guidance.Update({0.3f,0},36,1);
107 guidance.Update({0.27f,0},36,1);
108 guidance.Update({0.26f,0},36,1);
109 Check(HasReroute(guidance.Update({0.25f,0},36,1)), "initial wrong-way departure still recalculates promptly");
110
111 // Bill's replies previously reset the three-second detector and repeated
112 // the same request every five or six seconds. Model both packet resets.
113 guidance.Reset({}, true);
114 guidance.Reset(straight, true);
115 int requests = 0;
116 for (int frame = 1; frame <= fps * 31; ++frame)
117 {
118 const float seconds = static_cast<float>(frame)/fps;
119 const auto cues = guidance.Update({0.25f-seconds*0.005f,0},36,1.0f/fps);
120 if (!HasReroute(cues)) continue;
121 ++requests;
122 Check(seconds>=29.9f && seconds<=30.1f, "received replacement preserves a thirty-second cooldown at any frame rate");
123 }
124 Check(requests==1, "continuing away from the replacement does not cause a rapid recalculation loop");
125
126 guidance.Reset(straight); // New waypoint, not a replacement.
127 guidance.Update({0.3f,0},36,1);
128 guidance.Update({0.27f,0},36,1);
129 guidance.Update({0.26f,0},36,1);
130 Check(HasReroute(guidance.Update({0.25f,0},36,1)), "a different destination starts without the previous cooldown");
131 guidance.Reset({{{0,0},1,"RESKIN WAY"},{{0.5f,0},1,"RESKIN WAY"},{{0.5f,0.5f},2,"Route O"}},true);
132 const auto warning = guidance.Update({0.45f,0},36,1);
133 Check(warning.size()==1 && warning[0].type==G::Approaching && warning[0].edgeId==2,
134 "the recalculation cooldown does not suppress ordinary turn guidance on the new route");
135 }
136}
137static std::vector<G::Node> AccessRoad()
138{
139 return {
140 {{520.5f, 1103.5f}, 10, "Access Road"},
141 {{519.5f, 1103.5f}, 10, "Access Road"},
142 {{519.5f, 1102.5f}, 20, "Access Road"},
143 {{519.25f, 1102.5f}, 30, "Alpha Street"}
144 };
145}
146static void CheckSlightBend(float angle, bool changesStreet)
147{
148 const float radians = angle * 3.14159265358979323846f / 180.0f;
149 const int direction = angle < 0.0f ? 1 : 3;
150 G guidance;
151 const std::vector<G::Node> nodes = {{{0,0},10,"Access Road"},{{0.5f,0},10,"Access Road"},
152 {{0.5f + 0.5f * std::cos(radians),0.5f * std::sin(radians)},20,
153 changesStreet ? "Second Street" : "Access Road"}};
154 guidance.Reset(nodes);
155 Check(guidance.Update({0.1f,0},50).empty(), "slight bend does not warn 800 m early");
156 const auto warning = guidance.Update({0.45f,0},50);
157 Check(warning.size()==1 && warning[0].type==G::Approaching &&
158 warning[0].direction==direction && warning[0].edgeId==20 &&
159 std::fabs(warning[0].meters-100.0f)<0.2f,
160 "slight bend gives a 100 m heads-up for the outgoing road, including on the same street");
161 Check(warning[0].continuesStreet == !changesStreet &&
162 warning[0].WireDirection() == direction + (changesStreet ? 0.0f : 0.5f),
163 "the warning preserves direction and tells the server whether the street stays the same");
164 Check(guidance.Update({0.46f,0},50).empty(), "slight bend heads-up is not repeated");
165 const auto execute = guidance.Update({0.495f,0},50);
166 if (changesStreet)
167 Check(execute.size()==1 && execute[0].type==G::Execute &&
168 execute[0].direction==direction && execute[0].edgeId==20 && !execute[0].continuesStreet,
169 "a slight turn onto a different street retains the immediate instruction");
170 else
171 Check(execute.empty(), "a same-street slight bend has one advance instruction without a repeat at the curve");
172 Check(guidance.Update({0.496f,0},50).empty(), "slight bend execution is not repeated");
173 const auto passed = guidance.Update({0.5f,0},30);
174 Check(std::none_of(passed.begin(), passed.end(), [](const G::Cue& cue) { return cue.type==G::Execute; }),
175 "reaching the bend node does not repeat the instruction either");
176
177 // A packet can arrive too late for the advance warning, or a slow frame
178 // can jump over the usual execute window. Neither should make a bend silent.
179 for (const float x : {0.495f,0.5f})
180 {
181 G late;
182 late.Reset(nodes);
183 const auto immediate = late.Update({x,0},30);
184 Check(immediate.size()==1 && immediate[0].type==G::Execute && immediate[0].direction==direction,
185 "a late route still announces a slight bend when no advance instruction was issued");
186 }
187 G jump;
188 jump.Reset(nodes);
189 jump.Update({0.45f,0},30);
190 const auto atNode = jump.Update({0.5f,0},30);
191 Check(std::any_of(atNode.begin(), atNode.end(), [](const G::Cue& cue) { return cue.type==G::Execute; })==changesStreet,
192 "jumping over the execute window repeats only a turn onto a different street");
193}
194static void CheckCurveCutoffs()
195{
196 for (const float angle : {-60.1f,-29.9f,-15.0f,0.0f,15.0f,29.9f,60.1f})
197 {
198 const float radians = angle * 3.14159265358979323846f / 180.0f;
199 G guidance;
200 guidance.Reset({{{0,0},10,"Same Street"},{{0.5f,0},10,"Same Street"},
201 {{0.5f + 0.5f * std::cos(radians),0.5f * std::sin(radians)},20,"Same Street"}});
202 const auto warning = guidance.Update({0.45f,0},30);
203 const auto execute = guidance.Update({0.495f,0},30);
204 if (std::fabs(angle)<30.0f)
205 {
206 Check(warning.empty(), "same-street curves below thirty degrees have no advance turn instruction");
207 Check(std::none_of(execute.begin(), execute.end(), [](const G::Cue& cue) {
208 return cue.type==G::Approaching || cue.type==G::Execute;
209 }), "same-street curves below thirty degrees have no instruction at the curve");
210 }
211 else
212 {
213 Check(warning.size()==1 && warning[0].type==G::Approaching,
214 "a sharper same-street turn retains its advance warning");
215 Check(execute.size()==1 && execute[0].type==G::Execute && execute[0].direction==G::Direction(angle),
216 "a same-street turn over sixty degrees retains its immediate instruction");
217 }
218 }
219}
220static void CheckInitialRoadEntry()
221{
222 // Beginning of Bill's 2026-09-10 14:55 route. The first edge is a 5 m
223 // intersection link, followed by almost 10 km westbound before the first turn.
224 const std::vector<G::Node> route = {
225 {{524.5012f,1103.4990f},10,"Access Road"},
226 {{524.4988f,1103.4990f},10,"Access Road"},
227 {{524.0000f,1103.4990f},20,"Access Road"},
228 {{523.5012f,1103.4990f},21,"Access Road"},
229 {{523.4988f,1103.4990f},22,"Access Road"},
230 {{523.0000f,1103.4990f},23,"Access Road"},
231 {{522.5012f,1103.4990f},24,"Access Road"},
232 {{522.4988f,1103.4990f},25,"Access Road"},
233 {{522.0000f,1103.4990f},26,"Access Road"},
234 {{521.5012f,1103.4990f},27,"Access Road"},
235 {{521.4988f,1103.4990f},28,"Access Road"},
236 {{521.0000f,1103.4990f},29,"Access Road"},
237 {{520.5012f,1103.4990f},30,"Access Road"},
238 {{520.4988f,1103.4990f},31,"Access Road"},
239 {{520.0000f,1103.4990f},32,"Access Road"},
240 {{519.5012f,1103.4990f},33,"Access Road"},
241 {{519.5006f,1103.0000f},34,"Access Road"}
242 };
243 G guidance;
244 guidance.Reset(route);
245 Check(guidance.Update({524.5471f,1103.2860f},0).empty(), "no continue while 435 m off the first road");
246 Check(guidance.Update({524.5012f,1103.4700f},20).empty(), "approaching the road is not following it yet");
247 Check(guidance.Update({524.5012f,1103.4990f},20).empty(), "crossing into the junction does not confirm the wrong heading");
248 auto cues = guidance.Update({524.4800f,1103.4990f},50);
249 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==20,
250 "joining the first Access Road announces continue on the current edge");
251 Check(cues[0].meters>9900 && cues[0].meters<10000,
252 "initial continue sums the whole road to the next turn, not the 5 m entry link");
253 Check(guidance.Update({524.4700f,1103.4990f},50).empty(), "initial continue is announced only once");
254 cues = guidance.Update({519.5512f,1103.4990f},50);
255 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].direction==4,
256 "initial continue does not suppress the later right-turn warning");
257
258 guidance.Reset(route);
259 Check(guidance.Update({524.4800f,1103.4990f},0).empty(), "a newly received route waits for travel direction");
260 Check(guidance.Update({524.4800f,1103.4990f},0).empty(), "stationary vehicle does not confirm a direction");
261 Check(guidance.Update({524.4900f,1103.4990f},30).empty(), "driving against the first edge does not say continue");
262 cues = guidance.Update({524.4800f,1103.4990f},30);
263 Check(cues.size()==1 && cues[0].type==G::Continue, "turning to follow the first edge gives the pending continue");
264
265 guidance.Reset(route);
266 guidance.Update({524.4800f,1103.4800f},30);
267 Check(guidance.Update({524.4700f,1103.4800f},30).empty(), "parallel motion 38 m off the road does not confirm entry");
268
269 guidance.Reset(route);
270 cues = guidance.Update({519.5512f,1103.4990f},50);
271 Check(cues.size()==1 && cues[0].type==G::Approaching, "an imminent turn takes priority over entry reassurance");
272 Check(guidance.Update({519.5412f,1103.4990f},50).empty(), "entry reassurance does not follow an imminent-turn warning");
273}
274static void CheckCarmelTo18th()
275{
276 // SQL nodes 1298 -> 2075 -> 2368 -> 2074 -> 1258. The first 18TH ST
277 // edge is still northbound for 4 m, then the junction turns sharply west.
278 const std::vector<G::Node> route = {
279 {{519.5203f,1102.9900f},1,"CARMEL ST"},
280 {{519.5203f,1102.9620f},2,"CARMEL ST"},
281 {{519.5203f,1102.9430f},3,"CARMEL ST"},
282 {{519.5203f,1102.9410f},4,"18TH ST"},
283 {{519.5184f,1102.9410f},5,"18TH ST"},
284 {{519.5001f,1102.9410f},6,"18TH ST"},
285 {{519.4800f,1102.9410f},7,"18TH ST"}
286 };
287 G guidance;
288 guidance.Reset(route);
289 auto cues = guidance.Update({519.5203f,1102.9855f},40);
290 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].direction==2 && cues[0].edgeId==4,
291 "Carmel to 18th gives a LEFT heads-up before the street-name change on the short lane link");
292 Check(std::fabs(cues[0].meters-85.0f)<0.3f, "left heads-up uses distance to the junction entrance");
293 Check(guidance.Update({519.5203f,1102.9800f},40).empty(), "junction heads-up is announced once");
294 cues = guidance.Update({519.5203f,1102.9490f},30);
295 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].direction==2,
296 "Carmel to 18th says turn LEFT at the junction, without a preliminary continue");
297 Check(guidance.Update({519.5203f,1102.9430f},20).empty(), "no duplicate turn on the first internal node");
298 Check(guidance.Update({519.5203f,1102.9410f},20).empty(), "no duplicate turn on the second internal node");
299 Check(guidance.Update({519.5184f,1102.9410f},20).empty(), "no reassurance until the car leaves the intersection");
300 cues = guidance.Update({519.5100f,1102.9410f},30);
301 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==6,
302 "after the single left maneuver, reassurance names 18th Street");
303
304 // Two real corners separated by a road segment stay separate.
305 guidance.Reset({{{0,0},1,"First"},{{0.5f,0},1,"First"},
306 {{0.5f,-0.1f},2,"Second"},{{1.0f,-0.1f},3,"Third"}});
307 cues = guidance.Update({0.45f,0},50);
308 Check(cues.size()==1 && cues[0].direction==2 && cues[0].edgeId==2,
309 "junction grouping does not swallow a second turn 200 m away");
310 cues = guidance.Update({0.5f,-0.02f},50);
311 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].direction==4 && cues[0].edgeId==3,
312 "the second real corner retains its own right-turn heads-up");
313 Check(guidance.Update({0.5f,-0.05f},50).empty(), "the earlier second-corner warning is not repeated");
314}
315static void CheckClaytonCurves()
316{
317 // Financial District SQL nodes 1993 -> 1101 -> 1102 -> 1103 -> 1104 ->
318 // 1105 -> 1139 -> 1140 -> 1141 -> 1165: two 45-degree left bends.
319 // Each curve is split into smaller changes, all below the 30-degree cutoff.
320 const std::vector<G::Node> route = {
321 {{519.324702f,1102.674015f},1,"CLAYTON ST"},
322 {{519.324702f,1102.709165f},2,"CLAYTON ST"},
323 {{519.325765f,1102.712692f},3,"CLAYTON ST"},
324 {{519.328341f,1102.716112f},4,"CLAYTON ST"},
325 {{519.342979f,1102.730749f},5,"CLAYTON ST"},
326 {{519.346243f,1102.734012f},6,"CLAYTON ST"},
327 {{519.360881f,1102.748649f},7,"CLAYTON ST"},
328 {{519.364301f,1102.751225f},8,"CLAYTON ST"},
329 {{519.367828f,1102.752288f},9,"CLAYTON ST"},
330 {{519.400908f,1102.752288f},10,"CLAYTON ST"}
331 };
332 for (const bool reverse : {false, true})
333 {
334 auto driven = route;
335 if (reverse) std::reverse(driven.begin(), driven.end());
336 G guidance;
337 guidance.Reset(driven);
338 int warnings = 0, executions = 0;
339 for (std::size_t i = 1; i < driven.size(); ++i)
340 {
341 const auto a = driven[i - 1].position, b = driven[i].position;
342 const int steps = static_cast<int>(std::ceil(G::DistanceMeters(a, b)));
343 for (int step = 0; step < steps; ++step)
344 {
345 const float t = static_cast<float>(step) / steps;
346 for (const auto& cue : guidance.Update({a.x + t * (b.x - a.x), a.y + t * (b.y - a.y)},30))
347 {
348 if (cue.type != G::Approaching && cue.type != G::Execute) continue;
349 Check(cue.direction == (reverse ? 3 : 1) && cue.continuesStreet,
350 "Clayton's rounded bends give slight turns to continue on the same street in both directions");
351 if (cue.type == G::Approaching) ++warnings;
352 else ++executions;
353 }
354 }
355 }
356 Check(warnings == 2 && executions == 0,
357 "each of Clayton's two bends gets one heads-up without a second instruction at the curve");
358 }
359 // A shallow drift spread over the same short links is not a spoken bend.
360 G guidance;
361 guidance.Reset({{{0,0},1,"CLAYTON ST"},{{0.1f,0},2,"CLAYTON ST"},
362 {{0.104f,-0.0003f},3,"CLAYTON ST"},{{0.108f,-0.001f},4,"CLAYTON ST"},
363 {{0.208f,-0.02f},5,"CLAYTON ST"}});
364 Check(guidance.Update({0.07f,0},30).empty(), "a shallow same-street drift below 30 degrees remains silent");
365}
366static void CheckVoiceLeadTime()
367{
368 struct Timing { float speed, warning, execute; };
369 for (const auto timing : {Timing{30,133.333f,25}, Timing{60,266.667f,50},
370 Timing{80,355.556f,66.667f}, Timing{100,444.444f,83.333f},
371 Timing{120,533.333f,100}, Timing{180,800,100}})
372 {
373 Check(std::fabs(G::WarningDistanceMeters(timing.speed) - timing.warning) < 0.01f,
374 "warning scales with speed to allow delivery, speech, and driver preparation");
375 Check(std::fabs(G::ExecuteDistanceMeters(timing.speed) - timing.execute) < 0.01f,
376 "final turn cue includes delivery time rather than waiting until a fixed 15 m");
377 G guidance;
378 guidance.Reset({{{0,0},1,"CLAYTON ST"},{{1,0},1,"CLAYTON ST"},{{1,1},2,"BEAUMONT AVE"}});
379 auto atDistance = [](float meters) { return G::Point{1.0f - meters / 2000.0f,0}; };
380 Check(guidance.Update(atDistance(timing.warning + 20),timing.speed).empty(),
381 "no premature warning outside the calculated window");
382 auto cues = guidance.Update(atDistance(timing.warning - 1),timing.speed);
383 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].direction==4 && cues[0].edgeId==2,
384 "Beaumont right turn is queued on entering the earlier warning window");
385 Check(cues[0].meters / (timing.speed / 3.6f) - 4.0f - 4.0f > 7.8f,
386 "after four seconds of delivery/queue and four seconds of speech there are about eight seconds to prepare");
387 Check(guidance.Update(atDistance(timing.warning - 2),timing.speed).empty(),
388 "the earlier warning is still sent only once");
389 cues = guidance.Update(atDistance(timing.execute - 1),timing.speed);
390 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].direction==4,
391 "execute cue is requested before delivery delay can carry the driver past the turn");
392 Check(guidance.Update(atDistance(timing.execute - 2),timing.speed).empty(),
393 "the earlier final cue is not repeated");
394 }
395 Check(G::WarningDistanceMeters(0)==120 && G::ExecuteDistanceMeters(0)==15,
396 "stationary vehicles retain bounded minimum cue distances");
397 Check(G::WarningDistanceMeters(500)==1000 && G::ExecuteDistanceMeters(500)==100,
398 "very high speeds retain bounded maximum cue distances");
399 Check(G::WarningDistanceMeters(-1)==120 && G::WarningDistanceMeters(std::numeric_limits<float>::quiet_NaN())==120,
400 "invalid speed does not corrupt the warning window");
401 G guidance;
402 guidance.Reset({{{0,0},1,"CLAYTON ST"},{{1,0},1,"CLAYTON ST"},{{1,1},2,"BEAUMONT AVE"}});
403 Check(guidance.Update({0.85f,0},30).empty(), "slow approach 300 m away is outside the warning window");
404 const auto cues = guidance.Update({0.851f,0},100);
405 Check(cues.size()==1 && cues[0].type==G::Approaching, "accelerating expands the warning distance immediately");
406}
407#include "RoutePositionTests.h"
408int main()
409{
410 RoutePositionTest::CheckPositionPublication();
411 RoutePositionTest::CheckJaegerSeams();
412 CheckRecalculationCooldown();
413 CheckCurveCutoffs();
414 CheckRerouting();
415 CheckVoiceLeadTime();
416 CheckClaytonCurves();
417 CheckCarmelTo18th();
418 CheckInitialRoadEntry();
419 for (const float angle : {-59.9f, -45.0f, -30.1f, 30.1f, 45.0f, 59.9f})
420 {
421 CheckSlightBend(angle, false);
422 CheckSlightBend(angle, true);
423 }
424 G guidance;
425 guidance.Reset(AccessRoad());
426 auto cues = guidance.Update({519.7f,1103.5f},50);
427 Check(cues.empty(), "already westbound on Access Road: no invented entry turn");
428 Check(guidance.NextNodeIndex()==1, "entry point behind vehicle is consumed");
429 cues = guidance.Update({519.55f,1103.5f},50);
430 Check(cues.size()==1 && cues[0].type==G::Approaching, "warn before west-to-north turn");
431 Check(cues[0].direction==4, "west-to-north is RIGHT even with unchanged street name");
432 Check(cues[0].edgeId==20, "turn names the outgoing edge, not the incoming edge");
433 Check(std::fabs(cues[0].meters-100)<0.2f, "fractional plot distance converts to meters once");
434 Check(guidance.Update({519.54f,1103.5f},50).empty(), "warning is not repeated each frame");
435 cues = guidance.Update({519.505f,1103.5f},50);
436 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].direction==4, "announce RIGHT at the turn");
437 Check(guidance.Update({519.504f,1103.5f},50).empty(), "execution instruction is not repeated");
438 cues = guidance.Update({519.5f,1103.38f},50);
439 Check(guidance.NextNodeIndex()==2, "sampling after the corner advances to the northbound endpoint");
440 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==20, "reassure on the actual current road");
441 Check(cues[0].meters>1700 && cues[0].meters<1800, "continue covers remaining road length");
442 cues = guidance.Update({519.5f,1102.55f},50);
443 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].direction==2 && cues[0].edgeId==30,
444 "following LEFT turn is still announced after advancing");
445 Check(G::HeadingChange(0,270)==90, "north wraparound from west is right");
446 Check(G::HeadingChange(270,0)==-90, "north to west is left");
447 Check(G::HeadingChange(1,359)==2, "359-to-1 is a small change");
448 Check(G::Direction(G::HeadingChange(359,1))==0, "1-to-359 is straight");
449 Check(G::Direction(180)==5 && G::Direction(-180)==5, "both 180-degree turns are U-turns");
450
451 guidance.Reset(AccessRoad());
452 cues = guidance.Update({519.53f,1103.5f},50);
453 Check(cues.size()==1 && cues[0].type==G::Approaching, "route received inside warning range still warns");
454 guidance.Reset(AccessRoad());
455 cues = guidance.Update({519.506f,1103.5f},50);
456 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].direction==4, "late route arrival still announces the immediate turn");
457
458 guidance.Reset({{{520,1103},1,"Access Road"},{{520.02f,1103},1,"Access Road"},
459 {{520.04f,1103},1,"Access Road"},{{520.06f,1103},1,"Access Road"},{{520.5f,1103},1,"Access Road"}});
460 guidance.Update({520.005f,1103},40);
461 cues=guidance.Update({520.1f,1103},40);
462 Check(guidance.NextNodeIndex()==4, "advance through multiple passed short edges in one update");
463 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].direction==0,
464 "collinear same-street nodes confirm initial travel without inventing a turn");
465
466 guidance.Reset({{{0,0},1,"First Street"},{{0.1f,0},1,"First Street"},{{0.2f,0},2,"Second Street"}});
467 cues=guidance.Update({0.06f,0},50);
468 Check(cues.size()==1 && cues[0].edgeId==2 && cues[0].direction==0, "straight street rename uses outgoing name");
469
470 guidance.Reset({{{0,0},1,"Access Road"},{{0.5f,0},1,"Access Road"},{{0.5f,-0.5f},2,"Access Road"}});
471 guidance.Update({0.1f,0},50);
472 guidance.Update({0.5f,-0.1f},50);
473 Check(guidance.NextNodeIndex()==2, "missed samples do not leave connector pointing behind a corner");
474 cues=guidance.Update({0.5f,-0.7f},50);
475 Check(!guidance.IsComplete(), "passing the destination far away is not arrival");
476 cues=guidance.Update({0.5f,-0.498f},50);
477 Check(guidance.IsComplete() && cues.size()==1 && cues[0].type==G::Completed, "arrival requires proximity to final node");
478 Check(guidance.Update({0.5f,-0.5f},50).empty(), "arrival is reported once");
479 guidance.Reset();
480 Check(!guidance.IsComplete() && guidance.NextNodeIndex()==0 && guidance.Update({0,0},50).empty(), "cleared route clears guidance state");
481 guidance.Reset(AccessRoad());
482 Check(guidance.Update({519.55f,1103.5f},50).size()==1, "new route resets warning suppression");
483
484 // Bill's 2026-09-09 outbound packet, nodes 16-35. He rounded the corner
485 // westbound -> northbound without driving over its two 5 m lane links.
486 guidance.Reset({
487 {{520.0000f,1103.4990f},2209,"Access Road"},
488 {{519.4988f,1103.5010f},5154,"Access Road"},
489 {{519.5012f,1103.5010f},5145,"Access Road"},
490 {{519.5012f,1103.4990f},5144,"Access Road"},
491 {{519.5006f,1103.0000f},5149,"Access Road"},
492 {{519.4994f,1102.9970f},1983,"CASTRO ST"},
493 {{519.5013f,1102.9950f},1935,"CASTRO ST"},
494 {{519.5022f,1102.9930f},1934,"CASTRO ST"},
495 {{519.5033f,1102.9910f},1933,"CASTRO ST"},
496 {{519.5078f,1102.9850f},1932,"CASTRO ST"},
497 {{519.5103f,1102.9830f},1931,"CASTRO ST"},
498 {{519.5137f,1102.9790f},1313,"CASTRO ST"},
499 {{519.5159f,1102.9760f},1930,"CASTRO ST"},
500 {{519.5171f,1102.9750f},1929,"CASTRO ST"},
501 {{519.5193f,1102.9690f},1928,"CASTRO ST"},
502 {{519.5201f,1102.9650f},1927,"CASTRO ST"},
503 {{519.5203f,1102.9620f},1926,"CASTRO ST"},
504 {{519.5203f,1102.9430f},561,"CASTRO ST"},
505 {{519.5203f,1102.9410f},1552,"CASTRO ST"},
506 {{519.5184f,1102.9410f},1908,"18TH ST"},
507 {{519.5001f,1102.9410f},1549,"18TH ST"}});
508 guidance.Update({519.5100f,1103.5000f},60);
509 cues = guidance.Update({519.5006f,1103.4500f},60);
510 Check(guidance.NextNodeIndex()==4, "Bill's missed access-road corner rejoins the northbound road");
511 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==5149,
512 "recovery resumes guidance without announcing the missed lane-link turns");
513 cues = guidance.Update({519.5006f,1103.0300f},40);
514 Check(!cues.empty(), "guidance still announces the Financial District entrance after recovery");
515 guidance.Update({519.5040f,1102.9900f},40);
516 guidance.Update({519.5190f,1102.9700f},40);
517 cues = guidance.Update({519.5203f,1102.9620f},30);
518 Check(guidance.NextNodeIndex()>=17, "sampling across the short Castro Street curve keeps advancing");
519 Check(std::any_of(cues.begin(),cues.end(),[](const G::Cue& cue) {
520 return cue.edgeId==1908 && cue.direction==2 && cue.type==G::Approaching;
521 }), "the later left onto 18th Street is announced after the missed corner");
522
523 guidance.Reset({{{0,0},1,"First"},{{0.5f,0},1,"First"},
524 {{0.5f,-0.005f},2,"Return"},{{0,-0.005f},2,"Return"}});
525 guidance.Update({0.1f,0},50);
526 guidance.Update({0.2f,-0.004f},50);
527 Check(guidance.NextNodeIndex()==1, "a nearby parallel return leg does not skip the hairpin");
528 guidance.Update({0.499f,-0.001f},30);
529 guidance.Update({0.511f,-0.004f},30);
530 Check(guidance.NextNodeIndex()<=2, "moving against the return leg does not reacquire it");
531
532 guidance.Reset({{{0,0},1,"First"},{{0.1f,0},1,"First"},
533 {{0.1f,-0.05f},2,"Second"},{{0.2f,-0.05f},2,"Second"}});
534 guidance.Update({0.08f,0},40);
535 cues=guidance.Update({0.13f,-0.025f},40);
536 Check(guidance.NextNodeIndex()==1 && !guidance.IsComplete(),
537 "being 60 m off the outgoing road does not count as passing the turn");
538
539 // Final road geometry for waypoint 2222 in the 2026-09-10 server log.
540 // At 12:07 Bill was 31 m from the last node, alongside the last approach,
541 // with a short intersection link still ahead of him.
542 guidance.Reset({{{519.5803f,1102.1920f},1,"8TH ST"},
543 {{519.5770f,1102.1890f},2,"8TH ST"},{{519.5737f,1102.1920f},3,"8TH ST"},
544 {{519.5386f,1102.2280f},4,"8TH ST"},{{519.5346f,1102.2240f},5,"8TH ST"}});
545 guidance.Update({519.5650f,1102.2010f},30);
546 Check(!guidance.IsComplete(), "Bill's final approach does not arrive while more road remains");
547 cues = guidance.Update({519.5441f,1102.2110f},0);
548 Check(guidance.IsComplete() && cues.size()==1 && cues[0].type==G::Completed,
549 "Bill's stop near the final road point announces arrival despite the tiny final link");
550 Check(guidance.Update({519.5441f,1102.2110f},0).empty(), "arrival at the road endpoint is announced once");
551
552 // Projected destination on the road, with a position about 89 m before
553 // the old final turn as in Bill's 12:01:28 reassurance cue.
554 guidance.Reset({{{519.5737f,1102.1920f},4,"8TH ST"},
555 {{519.5537f,1102.2126f},4,"8TH ST"}});
556 cues = guidance.Update({519.5699f,1102.1958f},0);
557 Check(guidance.IsComplete() && cues.size()==1 && cues[0].type==G::Completed,
558 "the corrected Techform endpoint announces arrival where the old route continued another 89 m");
559
560 guidance.Reset({{{0,0},1,"Approach"},{{0.5f,0},1,"Approach"}});
561 guidance.Update({0.4f,0},30);
562 cues = guidance.Update({0.48f,0},0);
563 Check(guidance.IsComplete() && cues.size()==1 && cues[0].type==G::Completed,
564 "stopping 40 m from the mapped road endpoint completes navigation");
565 guidance.Reset({{{0,0},1,"Approach"},{{0.5f,0},1,"Approach"}});
566 guidance.Update({0.4f,0},30);
567 cues = guidance.Update({0.49f,0.02f},0);
568 Check(!guidance.IsComplete(), "being close to the endpoint but 40 m off the approach does not arrive");
569 guidance.Reset({{{0,0},1,"Outbound"},{{0.5f,0},1,"Outbound"},
570 {{0.5f,-0.01f},2,"Return"},{{0,-0.01f},2,"Return"}});
571 cues = guidance.Update({0.005f,0},30);
572 Check(!guidance.IsComplete(), "a nearby endpoint across a long remaining loop does not arrive early");
573 std::cout << "PASS: " << checks << " route guidance checks\n";
574}
constexpr double G
Definition FlightLoads.h:13