1
2
3#include "../Rendering/ClientMath.h"
4namespace RoutePositionTest
5{
6struct Cell { short u=0, v=0; };
7struct MapBus { Cell tcp; float assayProgressU=0, assayProgressV=0; };
8struct Game { MapBus* bus; bool timeLapse=false; };
9struct Grid { Cell tcp; };
10struct Vertex { RiseMath::Vector3 position; Cell tcp; };
13struct Logger {
15 void AddToCallStack(const char*) {}
16 void Log(
const char*, Level) {}
17};
18struct Viewscreen {
20 Grid* ptrGrid;
21 Logger* logger;
22 RiseMath::Vector3 leveler;
23 char area[3]{}, msg[999]{};
24 int zone=0;
25 float CalculateAGLd(RiseMath::Vector3, double, double, double,
26 double, double, double, RiseMath::Vector3, bool);
27 void BeginFrame() {
28#include "RoutePositionFrame.generated.h"
29 }
30};
31#include "RoutePosition.generated.h"
32
33struct Fixture {
34 MapBus bus;
36 Grid grid;
37 Logger logger;
38 Viewscreen view{&game,&grid,&logger};
39
40
41 bool Measure(Cell cell, float u, float v, bool terrainHit=true) {
42 grid.tcp=cell;
43 auto vertex=[&](float x,float y) {
44 return terrainHit ? RiseMath::Vector3((x-u)*2,(y-v)*2,-3000) : RiseMath::Vector3();
45 };
55
56 const bool hit=view.
CalculateAGLd({},0,0,0,0,0,3000,{0,0,-3000},
false)!=-1;
57 view.BeginFrame();
58 return hit;
59 }
61 return {float(bus.tcp.u)+bus.assayProgressU,float(bus.tcp.v)+bus.assayProgressV};
62 }
63};
64
65static std::vector<G::Node> JaegerRoute() {
66
67
68
69 return {
70 {{522.4988f,1102.501f},1,"Route 46"},
71 {{522.4988f,1103.f},2,"Route 46"},
72 {{522.4988f,1103.499f},3,"Route 46"},
73 {{522.f,1103.499f},4,"Route O"},
74 {{521.5012f,1103.499f},5,"Route O"},
75 {{521.4988f,1103.499f},6,"Route O"},
76 {{521.f,1103.499f},7,"Route O"},
77 {{520.5012f,1103.499f},8,"Route O"},
78 {{520.4988f,1103.499f},9,"Route O"},
79 {{520.f,1103.499f},10,"Route O"},
80 {{519.5012f,1103.499f},11,"Route O"},
81 {{519.5006f,1103.f},12,"CARMEL ST"}
82 };
83}
84
85static void CheckPositionPublication() {
86 for (const Cell step : {Cell{1,0},Cell{-1,0},Cell{0,1},Cell{0,-1}}) {
87 Fixture f;
88 const float u=step.u>0?.999f:step.u<0?.001f:.4993f;
89 const float v=step.v>0?.999f:step.v<0?.001f:.5f;
90 Check(f.Measure({522,1103},u,v),"initial terrain position is valid");
91 const auto before=f.Position();
92 const Cell next{short(522+step.u),short(1103+step.v)};
93 for(int frame=0;frame<4;++frame) {
94 Check(!f.Measure(next,0,0,false),"missing terrain intersection is reported");
95 Check(G::DistanceMeters(before,f.Position())<.01f,
96 "failed AGL at a cell boundary retains the entire previous map position");
97 }
98 Check(f.Measure(next,step.u?1-u:u,step.v?1-v:v),"position resumes after a valid terrain sample");
99 Check(G::DistanceMeters(before,f.Position())<5,
100 "resuming across a cell boundary moves meters instead of two kilometers");
101 }
102
103 Fixture f;
104 for(float u:{.1f,.4f,.6f,.9f}) for(float v:{.1f,.4f,.6f,.9f}) {
105 Check(f.Measure({522,1103},u,v),"terrain quadrant intersects");
106 Check(G::DistanceMeters(f.Position(),{522+u,1103+v})<.3f,
107 "map publication preserves terrain fractions in every quadrant");
108 }
109}
110
111static void CheckJaegerSeams() {
112 for (const int fps : {10,60,144}) {
113 Fixture f;
115 guidance.Reset(JaegerRoute());
116 auto update=[&](G::Point p) {
117 Cell cell{short(std::floor(p.x)),short(std::floor(p.y))};
118 Check(f.Measure(cell,p.x-cell.u,p.y-cell.v),"replay terrain sample intersects");
119 return guidance.Update(f.Position(),72,1.f/fps);
120 };
121 update({522.4993f,1102.999f});
122
123
124 f.Measure({522,1103},0,0,false);
125 auto cues=guidance.Update(f.Position(),72,1.f/fps);
126 Check(guidance.NextNodeIndex()==2 && cues.empty(),
127 "Route 46 seam cannot skip the Route O junction or announce Continue Route O");
128 for(int frame=1;frame<=fps*4;++frame) {
129 cues=update({522.4993f,1103.f+frame*.01f/fps});
130 Check(!HasReroute(cues) && guidance.NextNodeIndex()==2,
131 "southbound Route 46 stays current after the seam without false recalculation");
132 }
133
134 Check(!HasReroute(update({522.4993f,1103.03f})),"logged Route 46 origin remains on route");
135
136 cues=update({522.4993f,1103.35f});
137 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].edgeId==4 && cues[0].direction==4,
138 "the actual Route O junction retains its right-turn warning");
139 cues=update({522.4993f,1103.48f});
140 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].edgeId==4,
141 "the actual Route O turn retains its execution cue");
142 cues=update({522.48f,1103.5f});
143 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==4,
144 "Continue Route O occurs after the real turn");
145
146
147 guidance.Reset(JaegerRoute());
148 update({522.48f,1103.5f});
149 update({522.001f,1103.5f});
150
151
152 f.Measure({521,1103},0,0,false);
153 cues=guidance.Update(f.Position(),72,1.f/fps);
154 Check(!HasReroute(cues) && guidance.NextNodeIndex()==4,
155 "Route O seam cannot consume the next kilometer and lane link");
156 for(int frame=1;frame<=fps*4;++frame) {
157 cues=update({522.f-frame*.01f/fps,1103.5f});
158 Check(!HasReroute(cues) && guidance.NextNodeIndex()==4,
159 "normal Route O travel does not inherit a fictitious progress maximum");
160 }
161 Check(!HasReroute(update({521.9601f,1103.5f})),"logged Route O origin remains on route");
162
163 for(int frame=1;frame<=fps*245;++frame) {
164 const float x=521.9601f-frame*.01f/fps;
165 cues=update({x,1103.5f});
166 Check(!HasReroute(cues),"continuous Route O driving through all short links does not reroute");
167 Check(guidance.NextNodeIndex()<=10,"the later Carmel junction remains ahead");
168 }
169 }
170}
171}
float CalculateAGLd(RiseMath::Vector3 terpos, double terprecisionx, double terprecisiony, double terprecisionz, double proposedx, double proposedy, double proposedz, RiseMath::Vector3 proposed, bool makeleveler)
RiseMath::Vector3 insidearray[63][63][3]
LOCALGRID2 gridarray[64][64]
Vector Position(int cube, int u, int v, float radius)
float Level(float output, float limit)
std::function< void(const char *, bool warning)> Log
@ Game
Use the game audio system.
RiseMath::Vector3 position