Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/WeatherRadarGroundTests.h

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

1// Controlled terrain/weather replays exercise the same acquisition as flight.
2static bool IsReturn(Echo echo)
3{ return echo>=Echo::Green && echo<=Echo::Purple; }
4static void WriteWeatherRadarGroundReplay(std::ostream& output)
5{
6 output<<"scenario,bearing,gate,range_km,echo,attenuated,limited\n";
7 for(int scenario=0;scenario<4;++scenario)
8 {
9 Scanner scanner;Display display;auto in=Flight();in.rangeKm=40;
10 auto scene=[&](Point p) {
11 const double d=Length(p-in.position);
12 const double start=scenario==3 ? 20 : 8;
13 const bool ridge=p.x<0 && d>start && d<start+4;
14 const double surface=scenario==0 ? 0 : ridge ? (scenario==2 ? 1.1 : (std::min)(6.,(d-start)*3)) : 0;
15 const double weather=scenario==3 && d<18 ? 16. : d>24 && d<28 ? 12. : 2.;
16 return Sample{true,weather,surface,10};
17 };
18 Advance(scanner,in,display,4.1,scene);
19 for(int b=0;b<Bearings;++b)for(int g=0;g<Gates;++g)
20 output<<scenario<<','<<b-60<<','<<g<<','<<(g+.5)*in.rangeKm/Gates<<','
21 <<int(scanner.Beams()[b].echoes[g])<<','<<display.attenuated<<','<<display.limited<<'\n';
22 }
23}
24static void CheckWeatherRadarGround()
25{
26 Scanner scanner; Display display; auto in=Flight(); in.rangeKm=40;
27 auto distance=[&](Point p){return Length(p-in.position);};
28 auto flat=[](Point){return Sample{true,2,0,10};};
29 auto mountain=[&](Point p) {
30 const double d=distance(p);
31 const double height=d<8 ? 0 : d<10 ? (d-8)*3 : d<12 ? 6 : 0;
32 return Sample{true,2,height,10};
33 };
34 Advance(scanner,in,display,4.1,mountain);
35 const auto& ridge=scanner.Beams()[60].echoes;
36 bool painted=false;
37 for(int g=int(8/in.rangeKm*Gates);g<int(12/in.rangeKm*Gates);++g)
38 painted|=IsReturn(scanner.Beams()[60].groundEchoes[g]);
39 Check(painted && ridge[100]==Echo::TerrainShadow && !display.attenuated &&
40 std::none_of(ridge.begin(),ridge.end(),IsReturn),
41 "mountain clutter is rejected while its terrain shadow remains without WX ATTEN");
42
43 // A low ridge only intercepts the lower portion: higher rays can see a
44 // weather cell behind it, while a clear upper ray cannot erase masking.
45 auto lowRidge=[&](Point p) {
46 const double d=distance(p);
47 return Sample{true,d>24 && d<28 ? 12. : 2.,d>10 && d<12 ? 1.1 : 0.,10};
48 };
49 scanner.Reset(); Advance(scanner,in,display,4.1,lowRidge);
50 Check(scanner.Beams()[60].echoes[80]==Echo::Red && !display.attenuated,
51 "unobstructed upper beam detects red weather beyond a partial terrain blockage");
52 Check(scanner.Beams()[60].echoes[110]==Echo::TerrainShadow,
53 "empty upper beam does not declare the blocked central path clear");
54
55 // Beam widens with range, even with its center horizontally stabilized.
56 scanner.Reset(); Advance(scanner,in,display,4.1,flat);
57 const auto land=scanner.Beams()[60].groundEchoes;
58 int landReturns=0, first=Gates;
59 for(int g=0;g<Gates;++g) if(IsReturn(land[g])) {++landReturns;first=(std::min)(first,g);}
60 Check(first*in.rangeKm/Gates>10 && first*in.rangeKm/Gates<20 && landReturns>20,
61 "finite lower beam paints continuous flat ground beyond its geometric intercept");
62 Check(!display.attenuated && !display.limited,"clear terrain has no weather or data warning");
63 scanner.Reset(); Advance(scanner,in,display,4.1,[](Point){return Sample{true,2,0,10,false,1};});
64 int waterStrength=0, landStrength=0;
65 for(int g=0;g<Gates;++g)
66 {
67 if(IsReturn(land[g])) landStrength+=int(land[g]);
68 if(IsReturn(scanner.Beams()[60].groundEchoes[g])) waterStrength+=int(scanner.Beams()[60].groundEchoes[g]);
69 }
70 Check(waterStrength<landStrength,"supplied water landforms produce weaker diffuse clutter than land");
71
72 // Deep weather must hide surface returns as well as farther precipitation.
73 auto rainThenMountain=[&](Point p) {
74 const double d=distance(p);
75 return Sample{true,d<18 ? 16. : 2.,d>20 && d<23 ? 6. : 0.,10};
76 };
77 scanner.Reset(); Advance(scanner,in,display,4.1,rainThenMountain);
78 Check(scanner.Beams()[60].echoes[68]==Echo::Shadow && display.attenuated,
79 "terrain return beyond deep precipitation cannot shine through weather attenuation");
80 in.position.y=-in.radiusKm-.005;
81 scanner.Reset(); Advance(scanner,in,display,4.1,rainThenMountain);
82 Check(!IsReturn(scanner.Beams()[60].echoes[68]) && display.attenuated,
83 "lower rays stopped by nearby ground cannot reveal a mountain through intervening heavy rain");
84 in=Flight();in.rangeKm=40;
85
86 // Clear/terrain/weather rescan transitions retire old per-bearing flags.
87 Advance(scanner,in,display,8.1,mountain);
88 Check(!display.attenuated,"terrain rescan retires center-path weather attenuation");
89 auto missingLower=[&](Point p) {
90 const double d=distance(p);
91 if(d>5 && d<7 && Length(p)-in.radiusKm<.95) return Sample{};
92 return Sample{true,12,-20,10};
93 };
94 scanner.Reset(); Advance(scanner,in,display,4.1,missingLower);
95 Check(display.limited && IsReturn(scanner.Beams()[60].echoes[40]),
96 "missing lower-beam data stays annunciated despite a valid return at another elevation");
97 Advance(scanner,in,display,8.1,flat);
98 Check(!display.limited,"repaired beam coverage clears data warning after rescan");
99
100 // Land/water classification must not be inferred from the sea-level sign.
101 SPlotWeatherGrid packet{};packet.header.cube=0;packet.header.tcp={1019,1019};
102 packet.header.requestToken=3;packet.header.revision=1;
103 for(auto& col:packet.samples) for(auto& cell:col)
104 {cell.precipitation=20;cell.ceiling=1500;cell.visibility=42000;}
105 PlotWeather::Store source;
106 source.Accept(reinterpret_cast<const unsigned char*>(&packet),sizeof packet,3);
107 const auto coast=SampleGrid(source,in.position,10,[](unsigned,double,double,float& m,float& water) {
108 m=175;water=.75f;return true;
109 });
110 Check(coast.available && coast.surfaceKm>0 && coast.waterFraction==.75,
111 "positive-MSL water and mixed coast data survive the coordinate join");
112
113 for(double height:{.005,.1,7.2})
114 {
115 in=Flight();in.position.y=-in.radiusKm-height;in.rangeKm=40;
116 scanner.Reset();Advance(scanner,in,display,4.1,mountain);
117 Check(display.enabled && display.available && !display.attenuated,
118 "ground hover and cruise terrain scans remain active without speed or Autoflyte gating");
119 }
120 for(double height:{11.,63.,200.})
121 {
122 in.position.y=-in.radiusKm-height;in.dataAvailable=false;
123 scanner.Update(in,.1,mountain,display);
124 Check(display.echoes.empty() && !display.attenuated && !display.limited,
125 "ascent coast and orbital feed loss clears ground clutter and beam state");
126 }
127 in=Flight();in.position.y=-in.radiusKm-9.4;
128 scanner.Update(in,.1,flat,display);
129 for(int frame=0;frame<120;++frame){in.position.x+=8./60;scanner.Update(in,1./60,flat,display);}
130 Check(display.available && !display.attenuated,"8 km/s reentry re-acquires fresh finite-beam data");
131 in=Flight();Advance(scanner,in,display,4.1,flat);
132 in.simulator=true;scanner.Update(in,.1,flat,display);
133 Check(display.echoes.empty() && Count(scanner)==0,"simulator entry clears all terrain echoes");
134 in.simulator=false;scanner.Update(in,0,flat,display);
135 Check(Count(scanner)==1 && display.scanning,"simulator exit re-arms without replaying the old ground scan");
136}
SCRIPT_CONTROL SCRIPT_STATE const void int
Result Accept(const unsigned char *p, size_t length, uint16_t expectedToken)
Step Advance(float previous, float target, float baseline, float maximum, float dt, bool dead, float wakeFactor)
Sample SampleGrid(const PlotWeather::Store &source, Vector3 position, Elevation elevation)
SRenderWeather Sample(const unsigned char *p)
double Length(Point a)
SRenderWeather samples[64][64]
SPlotWeatherHeader header