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

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

1#include "../Viewscreen/WindshieldRain.h"
2#include "../Viewscreen/CloudVolume.h"
3#include <cstdlib>
4#include <iostream>
5#include <numeric>
6#include <memory>
7using namespace WindshieldRain;
8static void Check(bool ok, const char* message)
9{
10 if (!ok) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
11}
12static float Total(const Surface& s) { return std::accumulate(s.Water().begin(),s.Water().end(),0.f); }
13static Drop Largest(const Surface& s)
14{
15 Check(!s.Drops().empty(),"fixture retains water");
16 return *std::max_element(s.Drops().begin(),s.Drops().end(),[](const Drop& a,const Drop& b) { return a.radius<b.radius; });
17}
18static double Volume(const Surface& s)
19{
20 double total=0;
21 for(const auto& d:s.Drops()) total+=double(d.radius)*d.radius*d.radius;
22 return total;
23}
24static void CheckRainAirTaper()
25{
26 const AirJet jet{{0,1},75,0,1};
27 float prior=100;
28 for (float height:{.05f,.25f,.5f,.75f,.95f})
29 {
30 Surface pane;
31 pane.Impact({.5f,height},.002f,false);
32 pane.Update(1.f/30,0,{},{},2.6f,0,jet);
33 Check(pane.Drops().size()==1,"rain air moves rather than instantly removes the test bead");
34 const auto d=pane.Drops()[0];
35 Check(d.velocity.y>0 && d.velocity.y<prior,"jet motion weakens continuously from nozzle to top");
36 prior=d.velocity.y;
37 // Rotate the same glass 90 degrees in chart space. Aircraft-up is now
38 // -X, and the physical bottom projects to -1 rather than zero.
39 Surface rotated;
40 rotated.Impact({1-height,.5f},.002f,false);
41 rotated.Update(1.f/30,0,{},{},2.6f,0,{{-1,0},75,-1,0});
42 Check(std::abs(rotated.Drops()[0].velocity.x+d.velocity.y)<.000001f
43 && rotated.Drops()[0].velocity.y==0,"jet taper follows physical height across rotated charts");
44 }
45 Surface lower,upper;
46 lower.Impact({.5f,.05f},.002f,false);upper.Impact({.5f,.95f},.002f,false);
47 lower.Update(1.f/30,0,{0,-11},{},2.6f,0,jet);
48 upper.Update(1.f/30,0,{0,-11},{},2.6f,0,jet);
49 Check(lower.Drops()[0].velocity.y>0 && upper.Drops()[0].radius>.0019f,
50 "strong lower jet blows water up while upper impacts retain their size");
51 Surface wet;
52 wet.Update(1.f/30,1,{0,-11},{},2.6f,0,jet);
53 unsigned upperImpacts=0;
54 for (const auto& d:wet.Drops()) upperImpacts+=d.position.y>.5f;
55 Check(upperImpacts>=10,"rain still lands on the upper half with protection selected");
56 // Seed equal residue without bead movement to isolate local drying.
57 Surface residue;
58 auto& trail=const_cast<Surface::Field&>(residue.Residue());
59 std::fill(trail.begin(),trail.end(),1.f);
60 residue.Update(1.f/30,0,{},{},2.6f,0,jet);
61 const int n=Surface::Resolution;
62 Check(residue.Residue()[n*n-n/2]>residue.Residue()[n/2]*1.5f,
63 "upper residue persists longer than residue beside the nozzle");
64 Surface off,zero;
65 for (int tick=0;tick<30;++tick)
66 {
67 off.Update(1.f/30,1,{0,-11},{},2.6f);
68 zero.Update(1.f/30,1,{0,-11},{},2.6f,0,{{-1,0},0,-1,0});
69 }
70 Check(off.Water()==zero.Water(),"zero supply preserves ordinary rain exactly");
71 std::cout<<"PASS: tapered rain-air motion, rotated charts, upper impacts, local residue drying and zero-supply parity.\n";
72}
73static void CheckAirDensity()
74{
75 // Below breakup speed, one fixed step isolates linear density scaling.
76 const auto step = [](float density, Point wind, Point force = Point{0,9.8f}) {
77 auto pane = std::make_unique<Surface>();
78 pane->Impact({.5f,.5f},.0025f);
79 pane->Update(1.f/30,0,force,wind,density);
80 Check(pane->Drops().size()==1,"density test retains its bead");
81 return pane->Drops()[0];
82 };
83 constexpr float seaLevel = 2630.397f / 1013.25f;
84 const auto vacuum = step(0,{7,-12});
85 const auto still = step(seaLevel,{});
86 const auto earth = step(1,{7,-12});
87 const auto surface = step(seaLevel,{7,-12});
88 const auto half = step(seaLevel*.5f,{7,-12});
89 const auto thin = step(seaLevel*.1f,{7,-12});
90 Check(vacuum.velocity.x==still.velocity.x && vacuum.velocity.y==still.velocity.y && vacuum.velocity.y>0,
91 "vacuum removes wind force but retains gravity");
92 Check(std::fabs((surface.velocity.x-still.velocity.x)/(earth.velocity.x-still.velocity.x)-seaLevel)<.00001f,
93 "2630.397 mB surface strengthens wind drag by the one-atmosphere ratio");
94 Check(std::fabs((half.velocity.x-still.velocity.x)/(surface.velocity.x-still.velocity.x)-.5f)<.00001f &&
95 std::fabs((thin.velocity.x-still.velocity.x)/(surface.velocity.x-still.velocity.x)-.1f)<.00001f,
96 "wind force falls linearly with static density, not its square");
97 Check(std::fabs((half.velocity.y-still.velocity.y)/(surface.velocity.y-still.velocity.y)-.5f)<.00001f,
98 "upward wind scales without scaling gravity");
99 Check(step(0,{-10000,10000},{-20,0}).velocity.x<0,
100 "vehicle inertia still moves droplets in vacuum");
101 const auto fastSurface = step(seaLevel,{10000,0});
102 const auto fastThin = step(seaLevel*.1f,{10000,0});
103 Check(std::isfinite(fastSurface.velocity.x) &&
104 std::fabs(fastThin.velocity.x/fastSurface.velocity.x-.1f)<.00001f,
105 "airspeed cap preserves density scaling at high speeds");
106 Check(step(-1,{7,-12}).velocity.x==still.velocity.x,"negative density cannot reverse the wind force");
107 const auto localGravity=step(1188.f/1013.25f,{}, {0,11.27f});
108 Check(std::fabs(localGravity.velocity.y/still.velocity.y-11.27f/9.8f)<.00001f,
109 "local gravity above one Earth G produces proportionally stronger runoff");
110 const auto along=step(1,{30,40},{}), diagonal=step(1,{0,50},{});
111 Check(std::fabs(std::hypot(along.velocity.x,along.velocity.y)-diagonal.velocity.y)<.00001f,
112 "wind drag magnitude is independent of arbitrary glass UV rotation");
113 std::cout << "PASS: density scaling at surface, one atmosphere, half/thin air and vacuum; gravity/inertia preserved; high-speed cap.\n";
114}
115static void CheckStationaryRain()
116{
117 Check(LiquidRainIntensity(3,0,true)==0 && LiquidRainIntensity(9.5f,0,true)==.5f &&
118 LiquidRainIntensity(6,0,true)<.25f && LiquidRainIntensity(16,0,true)==1,
119 "windshield deposition follows exterior precipitation density");
120 Check(LiquidRainIntensity(16,1,true)==0 && LiquidRainIntensity(16,.5f,true)==.5f &&
121 LiquidRainIntensity(16,0,false)==0,"snow and shelter suppress liquid deposition");
122 auto light=std::make_unique<Surface>(), heavy=std::make_unique<Surface>();
123 for(int i=0;i<300;++i)
124 {
125 light->Update(1.f/30,LiquidRainIntensity(3.3f,0,true),{},{},1.f);
126 heavy->Update(1.f/30,LiquidRainIntensity(16,0,true),{},{},1.f);
127 }
128 Check(heavy->Drops().size()<=heavy->DropLimit() && Volume(*heavy)>Volume(*light)*3 &&
129 Total(*heavy)>Total(*light)*2,"precipitation 16 builds substantially more wetness than light rain");
130 std::cout << "PASS: heavy rain beads="
131 << heavy->Drops().size() << ", light=" << light->Drops().size() << "\n";
132 auto front=std::make_unique<Surface>(1.813f,1.875f);
133 // E-11 front-glass extent and the tangent component of local gravity.
134 for(int i=0;i<300;++i) front->Update(1.f/30,1,{0,5.06f},{},1188.f/1013.25f);
135 size_t left=0,right=0;
136 for(const auto& bead:front->Drops()) (bead.position.x<front->Width()*.5f ? left : right)++;
137 Check(left>300 && right>300 && front->Drops().size()<=front->DropLimit(),
138 "large front field retains hundreds of beads on both halves in heavy rain");
139 std::cout << "PASS: E-11-size front field has " << left << "/" << right
140 << " left/right beads after 10 s of heavy rain; budget " << front->DropLimit() << "\n";
141 auto pane = std::make_unique<Surface>(1.f,2.f);
142 pane->Impact({.5f,.2f},.0025f);
143 for(int i=0;i<300;++i) pane->Update(1.f/30,0,{0,9.80665f},{},2630.397f/1013.25f);
144 const auto drop=Largest(*pane);
145 Check(drop.position.y>1.2f && drop.position.y<1.7f && drop.radius>.0008f,
146 "stationary bead runs at a visible pace without disappearing prematurely");
147 // Isolate old film from the parent and deposited daughter beads.
148 const_cast<std::vector<Drop>&>(pane->Drops()).clear();
149 pane->Rebuild();
150 Check(pane->Drops().empty(),"residue test removes its bead");
151 const float residue=Total(*pane);
152 Check(residue>1,"rolling leaves a visible film after the bead is removed");
153 for(int i=0;i<360;++i) pane->Update(1.f/30,0,{},{},1.f);
154 Check(Total(*pane)>residue*.45f && Total(*pane)<residue*.55f,
155 "old residue retains half its strength after twelve seconds");
156 for(int i=0;i<3600;++i) pane->Update(1.f/30,0,{},{},1.f);
157 Check(!pane->Wet(),"residue eventually dries instead of accumulating forever");
158 std::cout << "PASS: stationary bead travels " << (drop.position.y-.2f)*100 << " cm in 10 s; radius "
159 << drop.radius*1000 << " mm; residue half-life 12 s; precipitation matches outside rain.\n";
160}
161static void CheckCoalescence()
162{
163 auto pane=std::make_unique<Surface>();
164 pane->Impact({.5f,.5f},.0022f);
165 pane->Update(1.f/30,0,{0,11.27f},{},1.f);
166 const auto before=pane->Drops()[0];
167 const double oldVolume=Volume(*pane), addedVolume=.0014*.0014*.0014;
168 pane->Impact(before.position,.0014f);
169 Check(pane->Drops().size()==1,"incoming rain merges with a touching bead");
170 const auto merged=pane->Drops()[0];
171 Check(std::fabs(Volume(*pane)/(oldVolume+addedVolume)-1)<.000001,
172 "coalescence conserves volume rather than summing radii");
173 Check(std::fabs(merged.velocity.y-before.velocity.y*float(oldVolume/(oldVolume+addedVolume)))<.000001f,
174 "coalescence conserves momentum when new rain has no tangential velocity");
175 pane->Impact({.8f,.8f},.0014f);
176 Check(pane->Drops().size()==2,"separated beads remain independent");
177
178 auto small=std::make_unique<Surface>(), large=std::make_unique<Surface>();
179 small->Impact({.5f,.2f},.0014f);
180 large->Impact({.5f,.2f},.0014f); large->Impact({.5f,.2f},.0014f);
181 for(int i=0;i<30;++i)
182 {
183 small->Update(1.f/30,0,{0,11.27f},{},1.f);
184 large->Update(1.f/30,0,{0,11.27f},{},1.f);
185 }
186 Check(large->Drops()[0].position.y-.2f>(small->Drops()[0].position.y-.2f)*1.6f,
187 "coalesced heavier bead runs faster than an unmerged bead");
188 auto pickup=std::make_unique<Surface>(), alone=std::make_unique<Surface>();
189 alone->Impact({.5f,.2f},.0028f);
190 pickup->Impact({.5f,.2f},.0028f); pickup->Impact({.5f,.235f},.0014f);
191 Check(pickup->Drops().size()==2,"runoff pickup starts with separated beads");
192 for(int i=0;i<30;++i)
193 {
194 pickup->Update(1.f/30,0,{0,11.27f},{},1.f);
195 alone->Update(1.f/30,0,{0,11.27f},{},1.f);
196 }
197 Check(Largest(*pickup).position.y>.235f &&
198 Volume(*pickup)>Volume(*alone)*1.05,"moving bead collects water encountered down the pane");
199 size_t moving=0;
200 for(const auto& d:pickup->Drops()) moving+=d.radius>.0007f;
201 Check(moving==1,"runoff pickup leaves one parent plus only pinned daughter beads");
202
203 auto wide=std::make_unique<Surface>(2.f,2.f);
204 for(int y=0;y<100;++y) for(int x=0;x<100;++x)
205 wide->Impact({.05f+x*.019f,.05f+y*.019f},.0014f);
206 Check(wide->Drops().size()==Surface::MaxDrops && wide->DropLimit()==Surface::MaxDrops,
207 "large-pane storage stops at the fixed 8192 bead ceiling");
208 const auto full=wide->Drops()[0]; const double fullVolume=Volume(*wide);
209 wide->Impact(full.position,.0014f);
210 Check(wide->Drops().size()==Surface::MaxDrops && Volume(*wide)>fullVolume,
211 "rain hitting existing water still accumulates at the bead limit");
212 Check(pane->DropLimit()==3072 && Surface(.25f,.25f).DropLimit()==512,
213 "budgets scale by area with a bounded minimum for tiny panes");
214 Check(Surface(1.813f,1.875f).DropLimit()>6900,
215 "E-11 front glass is no longer capped at a small side window's 512 beads");
216 std::cout << "PASS: impact/rolling coalescence, conserved volume/momentum, faster heavy beads, pane-area budgets and hard cap.\n";
217}
218static void CheckBeadShape()
219{
220 auto small=std::make_unique<Surface>(1.6f,.8f), large=std::make_unique<Surface>(1.6f,.8f);
221 small->Impact({.8f,.4f},.0025f); large->Impact({.8f,.4f},.007f);
222 small->Rebuild(); large->Rebuild();
223 Check(Total(*large)>Total(*small)*2,"small and large beads retain distinct rasterized sizes");
224 double xx=0,yy=0;
225 for(int y=0;y<Surface::Resolution;++y) for(int x=0;x<Surface::Resolution;++x)
226 {
227 const float dx=(x+.5f)*large->Width()/Surface::Resolution-.8f;
228 const float dy=(y+.5f)*large->Height()/Surface::Resolution-.4f;
229 const float height=large->Water()[y*Surface::Resolution+x];
230 xx+=dx*dx*height; yy+=dy*dy*height;
231 Check(large->Residue()[y*Surface::Resolution+x]==0,"stationary bead is distinct from old runoff");
232 }
233 Check(xx/yy>.8 && xx/yy<1.2,"bead footprint stays round in metres on a rectangular pane");
234 auto fresh=std::make_unique<Surface>(10.f,10.f);
235 fresh->Update(1.f/30,1,{},{},1.f);
236 Check(fresh->Drops().size()>100,"fresh rain size fixture has a representative sample");
237 for(const auto& drop:fresh->Drops()) Check(drop.radius>=.0005f && drop.radius<=.0025f,
238 "parked rain starts with millimetre-scale beads rather than 5-14 mm diameters");
239 auto tiny=std::make_unique<Surface>(3.2f,1.6f);
240 tiny->Impact({1.6013f,.8007f},.0007f);
241 std::vector<Surface::BeadSample> map; tiny->BeadMap(map);
242 size_t occupied=0;
243 for(const auto& sample:map) if(sample.radius>0)
244 {
245 ++occupied;
246 Check(sample.x==1.6013f && sample.y==.8007f && sample.radius==.0007f*Surface::BeadRadiusScale,
247 "sub-texel bead map keeps the exact center with bounded optical size emphasis");
248 }
249 Check(occupied>=4 && occupied<=25,"optically emphasized sub-texel bead stays in a small lookup neighborhood");
250 Check(tiny->Drops()[0].radius==.0007f,"optical size emphasis never changes simulated bead volume");
251 std::cout << "PASS: small/large cap areas " << Total(*small) << "/" << Total(*large)
252 << "; metric X/Y second-moment ratio " << xx/yy << "; separate residue.\n";
253}
254static void CheckHighSpeedShedding()
255{
256 constexpr float density=1188.f/1013.25f;
257 auto slow=std::make_unique<Surface>(1.6f,.8f), fast=std::make_unique<Surface>(1.6f,.8f);
258 auto normal=std::make_unique<Surface>(1.6f,.8f);
259 for(int i=0;i<300;++i)
260 {
261 slow->Update(1.f/30,1,{0,11.27f},{},density);
262 fast->Update(1.f/30,1,{0,11.27f},{0,-90},density,103);
263 normal->Update(1.f/30,1,{0,11.27f},{},density,103);
264 }
265 const auto averageRadius=[](const Surface& s) {
266 float sum=0; for(const auto& d:s.Drops()) sum+=d.radius;
267 return sum/(std::max)(size_t(1),s.Drops().size());
268 };
269 Check(!fast->Drops().empty() && fast->Drops().size()<slow->Drops().size()/3,
270 "200-knot flow sheds beads quickly while fresh impacts remain visible");
271 // Persistent pinned splash satellites lower the parked count-average;
272 // compare the water-bearing body size rather than counting spray equally.
273 const auto waterRadius=[](const Surface& s) {
274 double sum=0;for(const auto& d:s.Drops()) sum+=double(d.radius)*d.radius*d.radius*d.radius;
275 return sum/Volume(s);
276 };
277 Check(waterRadius(*fast)<waterRadius(*slow)*.6 &&
278 waterRadius(*normal)<waterRadius(*slow)*.6,
279 "high-speed impacts break into smaller beads, including near-normal impacts");
280 for(const auto& d:fast->Drops())
281 Check(d.radius<=.0013f && d.velocity.y<0,"small fragments travel with high-speed airflow");
282 Check(std::accumulate(fast->Residue().begin(),fast->Residue().end(),0.f)>0,
283 "full shedding traces fragment motion with a brief wake");
284 auto overlapping=std::make_unique<Surface>();
285 overlapping->Impact({.5f,.5f},.0025f,false); overlapping->Impact({.5f,.5f},.0025f,false);
286 overlapping->Update(1.f/30,0,{},{0,-90},density,103);
287 Check(overlapping->Drops().size()==2,"full shedding skips pairwise coalescing of overlapping beads");
288
289 auto residue=std::make_unique<Surface>();
290 residue->Impact({.5f,.5f},.0025f);
291 residue->Update(.25f,0,{0,11.27f},{},density);
292 Check(std::accumulate(residue->Residue().begin(),residue->Residue().end(),0.f)>0,
293 "runoff fixture starts with a wet trail");
294 for(int i=0;i<30;++i) residue->Update(1.f/30,0,{0,11.27f},{0,-90},density,103);
295 Check(!residue->Wet(),"accelerating into high-speed flow clears old beads and residue within one second");
296
297 auto vacuum=std::make_unique<Surface>(), still=std::make_unique<Surface>();
298 auto fps30=std::make_unique<Surface>(), fps144=std::make_unique<Surface>();
299 for(int i=0;i<120;++i)
300 {
301 vacuum->Update(1.f/30,1,{0,11.27f},{0,-90},0,103);
302 still->Update(1.f/30,1,{0,11.27f},{},0,0);
303 fps30->Update(1.f/30,1,{0,11.27f},{0,-90},density,103);
304 }
305 for(int i=0;i<576;++i) fps144->Update(1.f/144,1,{0,11.27f},{0,-90},density,103);
306 Check(vacuum->Water()==still->Water(),"speed without air density does not break up water");
307 Check(fps30->Drops().size()==fps144->Drops().size() && fps30->Water()==fps144->Water(),
308 "high-speed shedding is identical at 30 and 144 FPS");
309 std::cout << "PASS: 200 knots: beads " << slow->Drops().size() << " -> " << fast->Drops().size()
310 << "; mean radius " << averageRadius(*slow)*1000 << " -> " << averageRadius(*fast)*1000
311 << " mm; brief wakes, no coalescing; normal impacts; one-second clearing; vacuum and FPS invariance.\n";
312}
313static void CheckCloudRain()
314{
315 Check(CloudRainFactor(0,-1,true)==0 && CloudRainFactor(1,-1,true)==1,
316 "cloud gaps stop new impacts and dense clusters restore them");
317 Check(CloudRainFactor(.2f,-1,true)<CloudRainFactor(.8f,-1,true),
318 "in-cloud impacts increase with local density");
319 Check(CloudRainFactor(0,.1f,true)==1 && CloudRainFactor(0,0,true)==1,
320 "falling rain continues at and below cloud base");
321 Check(CloudRainFactor(0,-.25f,true)==.5f && CloudRainFactor(0,-.5f,true)==0,
322 "cloud-base transition is continuous");
323 Check(CloudRainFactor(0,-1,false)==1,"legacy clouds retain ordinary rain");
324 Surface gap; gap.Impact({.5f,.5f},.0025f);
325 gap.Update(1.f/30,CloudRainFactor(0,-1,true),{0,11.27f},{},1);
326 Check(gap.Drops().size()==1 && gap.Drops()[0].position.y>.5f,
327 "entering a cloud gap preserves existing runoff instead of clearing the pane");
328 // Traverse the real planet-fixed cloud field at a constant 7.5 km.
329 // Modulation must follow spatial clusters, not altitude.
331 float lowest=1,highest=0; std::vector<float> rates;
332 for(int i=0;i<160;++i)
333 {
334 const float angle=i*.00002f;
335 const CloudVolume::Point p{(params.radius+7.5f)*std::sin(angle),
336 (params.radius+7.5f)*std::cos(angle),0};
337 const float density=CloudVolume::Density(p,params);
338 const auto column=CloudVolume::Boundaries(p,params);
339 const float rate=CloudRainFactor(density,column.base-7.5f,true)*LiquidRainIntensity(16,0,true,7.5f);
340 Check(std::abs(rate-density*.5f)<.000001f,"rain uses the actual cloud density sample");
341 lowest=(std::min)(lowest,rate); highest=(std::max)(highest,rate); rates.push_back(rate);
342 }
343 Check(highest-lowest>.01f,"rain changes across real cloud clusters at one altitude");
344 Surface thin,dense;
345 for(int i=0;i<90;++i)
346 {
347 thin.Update(1.f/30,lowest,{},{},1);
348 dense.Update(1.f/30,highest,{},{},1);
349 }
350 Check(dense.Drops().size()>thin.Drops().size(),"dense cluster produces more impacts than thin cluster");
351 for(size_t i=1;i<rates.size();++i) Check(std::abs(rates[i]-rates[i-1])<.02f,
352 "moving between adjacent density samples has no binary precipitation switch");
353 std::cout << "PASS: real cloud-cluster rain modulation at 7.5 km: " << lowest << ".." << highest << "\n";
354}
355static void CheckHeavyCoverage()
356{
357 Surface moderate(1.813f,1.875f), heavy(1.813f,1.875f);
358 for(int i=0;i<900;++i)
359 {
360 moderate.Update(1.f/30,LiquidRainIntensity(6,0,true),{0,5.06f},{},1188.f/1013.25f);
361 heavy.Update(1.f/30,LiquidRainIntensity(16,0,true),{0,5.06f},{},1188.f/1013.25f);
362 }
363 // The former small-bead settings covered only 0.204% of this field at both
364 // PR 6 and PR 16. Assert physical bead area, not the prefiltered wetness map.
365 std::cout << "Coverage moderate/heavy: " << moderate.Wetness() << "/" << heavy.Wetness() << "; counts " << moderate.Drops().size() << "/" << heavy.Drops().size() << std::endl;
366 Check(heavy.Wetness()>.01f && heavy.Wetness()>moderate.Wetness()*1.7f,
367 "heavy rain materially increases small-bead coverage beyond moderate rain");
368 Check(heavy.Drops().size()>6000 && heavy.Drops().size()<=heavy.DropLimit(),
369 "large front glass keeps thousands of small beads within its area budget");
370 // Impacts must remain distinct droplets. With gravity and airflow absent,
371 // no moving runoff exists to justify a pane-wide residue texture.
372 Surface still(1.813f,1.875f);
373 for(int i=0;i<120;++i) still.Update(1.f/30,1,{},{},1);
374 Check(!still.Drops().empty() && std::accumulate(still.Residue().begin(),still.Residue().end(),0.f)==0,
375 "heavy stationary impacts cannot build a mottled background film");
376 heavy.WipeTriangle({0,0},{2,0},{2,2}); heavy.WipeTriangle({0,0},{2,2},{0,2}); heavy.Rebuild();
377 Check(!heavy.Wet(),"wiping removes dense beads and accumulated runoff");
378 std::cout << "PASS: moderate/heavy accumulation and complete clearing of dense wet glass.\n";
379}
380static float ExteriorStrength(float intensity)
381{
382 constexpr int maximum=8192;
383 const int count=ExteriorDropCount(intensity,maximum);
384 Check(count>=0 && count<=maximum && count%2==0,"exterior count stays within its even vertex budget");
385 float total=0;
386 for(int i=0;i<maximum;++i)
387 {
388 const float opacity=ExteriorDropOpacity(i,intensity,maximum);
389 Check(opacity>=0 && opacity<=1,"exterior alpha is bounded");
390 if(i>=count) Check(opacity==0,"removed streaks have already faded to zero");
391 total+=opacity;
392 }
393 return total/maximum;
394}
395static void CheckExteriorRain()
396{
397 Check(ExteriorStrength(0)==0 && ExteriorStrength(1)==1,"exterior has exact dry/full endpoints");
398 Check(PrecipitationIntensity(3)==0 && PrecipitationIntensity(16)==1 &&
399 PrecipitationIntensity(6)<PrecipitationIntensity(10),"exterior rain uses the full precipitation range");
400 float previous=1;
401 for(int i=0;i<=500;++i)
402 {
403 const float strength=ExteriorStrength(PrecipitationIntensity(16,5+i*.01f));
404 Check(strength<=previous+.000001f && previous-strength<.0032f,
405 "exterior rain fades smoothly from 5 to 10 km without a cutoff");
406 previous=strength;
407 }
408 Check(previous==0 && ExteriorStrength(PrecipitationIntensity(16,9.99f))<.000001f,
409 "exterior is already invisible before the legacy 10 km weather switch");
410 Check(ExteriorStrength(PrecipitationIntensity(16,7.5f))>.49f &&
411 ExteriorStrength(PrecipitationIntensity(16,7.5f))<.51f,"half exterior strength at 7.5 km");
412 const float thin=PrecipitationIntensity(16,7.5f)*CloudRainFactor(.2f,-1,true);
413 const float dense=PrecipitationIntensity(16,7.5f)*CloudRainFactor(.8f,-1,true);
414 Check(ExteriorStrength(dense)>ExteriorStrength(thin)*3.5f,"exterior responds to local cloud clusters");
415 for(int i=0;i<8192;++i)
416 Check(std::abs(ExteriorDropOpacity(i,.50001f,8192)-ExteriorDropOpacity(i,.5f,8192))<.001f,
417 "individual streaks fade continuously instead of popping with integer count changes");
418 Check(ExteriorStrength(PrecipitationIntensity(16)*CloudRainFactor(0,.1f,true))==1,
419 "falling precipitation continues beneath the cloud base");
420 std::cout << "PASS: exterior 5..10 km fade, density clusters, gradual particle entry/exit, even bounded count and below-cloud rain.\n";
421}
422static void CheckAltitudeRain()
423{
424 Check(AltitudeRainFactor(10)==0 && AltitudeRainFactor(12)==0,"no altitude rain above 10 km");
425 Check(AltitudeRainFactor(5)==1 && AltitudeRainFactor(-1)==1,"full altitude rain below 5 km");
426 Check(AltitudeRainFactor(7.5f)==.5f,"half rain at 7.5 km");
427 float previous=0;
428 for(int i=0;i<=500;++i)
429 {
430 const float factor=AltitudeRainFactor(10-i*.01f);
431 Check(factor>=previous && factor-previous<.0031f,"10..5 km fade is smooth and monotonic");
432 previous=factor;
433 }
434 Check(AltitudeRainFactor(9.99f)<.00002f && AltitudeRainFactor(5.01f)>.99998f,
435 "altitude fade eases in/out at both boundaries");
436 Check(LiquidRainIntensity(16,0,true,10)==0 && LiquidRainIntensity(16,0,true,7.5f)==.5f,
437 "high precipitation and weather overrides still respect altitude");
438 Check(std::abs(LiquidRainIntensity(4.5f,.5f,true,7.5f)-1.5f/52.f)<.000001f && LiquidRainIntensity(16,0,false,5)==0,
439 "altitude composes with precipitation, snow and shelter");
440 Surface high,half,full;
441 for(int i=0;i<30;++i)
442 {
443 high.Update(1.f/30,LiquidRainIntensity(16,0,true,10),{},{},1);
444 half.Update(1.f/30,LiquidRainIntensity(16,0,true,7.5f),{},{},1);
445 full.Update(1.f/30,LiquidRainIntensity(16,0,true,5),{},{},1);
446 }
447 Check(!high.Wet() && half.Drops().size()>50 && Volume(half)<Volume(full)*.6,
448 "altitude fades actual new impacts, not only their rendering");
449 std::cout << "PASS: altitude-dependent rain deposition and smooth 10..5 km fade.\n";
450}
451static void CheckBladeSweeps()
452{
453 const auto blade=[](float oldX,float newX) {
454 return std::vector<Surface::BladeSweep>{
455 {{{oldX,.1f},{oldX+.01f,.1f},{oldX,.9f}},{{newX,.1f},{newX+.01f,.1f},{newX,.9f}}},
456 {{{oldX+.01f,.1f},{oldX+.01f,.9f},{oldX,.9f}},{{newX+.01f,.1f},{newX+.01f,.9f},{newX,.9f}}}};
457 };
458 const auto volume=[](const Surface& s) { double v=0; for(const auto& d:s.Drops())v+=d.radius*d.radius*d.radius; return v; };
459 Surface swept;
460 swept.Impact({.3f,.5f},.002f); swept.Impact({.8f,.5f},.001f); swept.Rebuild();
461 const double before=volume(swept);
462 const auto revision=swept.Revision();
463 swept.SweepBlades(blade(.2f,.4f),.1f);
464 Check(swept.Drops().size()==2 && std::abs(volume(swept)-before)<1.e-13,
465 "blade carries water ahead of the rubber without deleting its volume");
466 auto moving=Largest(swept);
467 Check(moving.position.x>.41f && moving.position.x<.42f && moving.velocity.x>1.9f,
468 "collected water receives the blade's position and fling velocity");
469 Check(swept.Drops()[1].position.x==.8f && swept.Drops()[1].velocity.x==0,
470 "wiping leaves unswept drops untouched");
471 Check(swept.Revision()>revision,"displaced beads invalidate renderer uploads");
472 swept.Update(1.f/30,0,{},{},1.f);
473 Check(Largest(swept).position.x>moving.position.x+.04f,"water keeps moving after blade releases it");
474 swept.SweepBlades(blade(.6f,.2f),.2f);
475 Check(Largest(swept).position.x<.2f && Largest(swept).velocity.x<-1.9f,
476 "return stroke reverses the displacement and momentum");
477 swept.SweepBlades(blade(.2f,-.1f),.15f);
478 Check(swept.Drops().size()==1 && swept.Drops()[0].position.x==.8f,
479 "water is removed only after it is swept off the pane");
480 Surface duplicated, single;
481 for(auto* s:{&duplicated,&single})s->Impact({.3f,.5f},.002f);
482 auto mesh=blade(.2f,.4f);auto dense=mesh;
483 for(int i=0;i<50;++i)dense.insert(dense.end(),mesh.begin(),mesh.end());
484 duplicated.SweepBlades(dense,.1f);single.SweepBlades(mesh,.1f);
485 Check(Largest(duplicated).position.x==Largest(single).position.x
486 && volume(duplicated)==volume(single),"overlapping blade triangles cannot push a bead repeatedly");
487 const auto stationary=Largest(single);
488 single.SweepBlades(blade(.4f,.4f),.1f);
489 Check(Largest(single).position.x==stationary.position.x,"stationary blade cannot permanently erase its sweep");
490 Surface wake;
491 wake.Impact({.5f,.5f},.002f);
492 const_cast<std::vector<Drop>&>(wake.Drops())[0].wake={.2f,.5f};
493 wake.SweepBlades(blade(.3f,.31f),.1f);
494 Check(Largest(wake).position.x==.5f && Largest(wake).wake.x==.5f,
495 "sweeping a wake cuts the trail without moving its unswept parent");
496 std::cout<<"PASS: batched blade sweep conserves/pushes water, transfers momentum, returns, ejects at edge, and cuts wakes.\n";
497}
498static void CheckGravityDominatedRunoff()
499{
500 Surface merged;
501 merged.Impact({.5f,.5f},.002f);
502 merged.Impact({.503f,.5f},.002f);
503 const auto stationary=Largest(merged);
504 Check(stationary.wake.x==stationary.position.x && stationary.wake.y==stationary.position.y,
505 "stationary coalescence cannot invent a sideways runoff tail");
506 auto& runner=const_cast<std::vector<Drop>&>(merged.Drops())[0];
507 runner.velocity={0,.2f}; runner.wake={runner.position.x,runner.position.y-.02f};
508 merged.Impact({runner.position.x+.003f,runner.position.y},.002f);
509 const auto collected=Largest(merged);
510 Check(std::abs(collected.wake.x-collected.position.x)<.0000001f && collected.wake.y<collected.position.y,
511 "off-centre pickup preserves a real downward wake instead of rotating it sideways");
512
513 Surface small(1,2),heavy(1,2);
514 small.Impact({.5f,.2f},.00085f); heavy.Impact({.5f,.2f},.003f);
515 for(int i=0;i<60;++i) for(auto* pane:{&small,&heavy})
516 pane->Update(1.f/30,0,{0,11.27f},{},2630.397f/1013.25f);
517 Check(Largest(small).position.y==.2f,"small beads stay pinned until enough water accumulates");
518 Check(Largest(heavy).position.y>.6f,"heavy beads release into fast gravity runoff");
519 small.Impact({.5f,.2f},.0014f);
520 for(int i=0;i<60;++i) small.Update(1.f/30,0,{0,11.27f},{},2630.397f/1013.25f);
521 Check(Largest(small).position.y>.23f,"collecting water releases a previously pinned bead");
522
523 // Test down in two chart orientations, both calm and a light ground wind.
524 // The metric is relative to gravity, not a particular texture Y axis.
525 float worst=0;size_t samples=0;
526 for(Point down:{Point{0,1},Point{.6f,.8f}}) for(float breeze:{0.f,4.f})
527 {
528 Surface rain(1,1);
529 for(int i=0;i<180;++i)
530 {
531 rain.Update(1.f/30,1,{down.x*5.06f,down.y*5.06f},
532 {down.y*breeze,-down.x*breeze},2630.397f/1013.25f);
533 for(const auto& d:rain.Drops()) if(d.radius>.0016f)
534 {
535 const float along=d.velocity.x*down.x+d.velocity.y*down.y;
536 const float across=d.velocity.x*down.y-d.velocity.y*down.x;
537 Check(along>=0,"a light ground breeze cannot turn heavy runoff uphill");
538 if(along<=.005f) continue;
539 worst=(std::max)(worst,std::abs(across)/along);++samples;
540 }
541 }
542 }
543 std::cout << "Downpour lateral/downward velocity ratio: " << worst << "; samples=" << samples << '\n';
544 Check(samples>10000 && worst<.22f,"parked heavy-rain runners stay within 13 degrees of downhill");
545}
546static void CheckWetTrailFollowing()
547{
548 // Form an actual trail with a leading drop, then let a second bead enter
549 // it. Clearing the first drop isolates the retained path from coalescence.
550 Surface wet(1,3);
551 wet.Impact({.5f,.2f},.003f);
552 for(int i=0;i<120;++i) wet.Update(1.f/30,0,{0,9.80665f},{},1);
553 const_cast<std::vector<Drop>&>(wet.Drops()).clear();
554 auto dry=wet, wiped=wet;
555 std::fill(const_cast<Surface::Field&>(dry.Residue()).begin(),
556 const_cast<Surface::Field&>(dry.Residue()).end(),0.f);
557 wiped.WipeTriangle({0,0},{1,0},{1,3}); wiped.WipeTriangle({0,0},{1,3},{0,3});
558 for(auto* pane:{&wet,&dry,&wiped}) pane->Impact({.5f,.2f},.0025f);
559 for(int i=0;i<30;++i) for(auto* pane:{&wet,&dry,&wiped})
560 pane->Update(1.f/30,0,{0,9.80665f},{},1);
561 const float dryTravel=Largest(dry).position.y-.2f, wetTravel=Largest(wet).position.y-.2f;
562 Check(dryTravel>.15f && dryTravel<.3f,"2.5 mm dry-glass bead rolls visibly within one second");
563 Check(wetTravel>dryTravel*1.25f,"old runoff lowers resistance for the following bead");
564 Check(wiped.Water()==dry.Water(),"wiping removes both visible water and the old trail's motion advantage");
565 // A narrow existing rivulet guides the bead laterally, but cannot create
566 // flow without gravity/wind or dislodge a pinned sub-millimetre satellite.
567 const auto band=[](Surface& pane,float centre) {
568 auto& field=const_cast<Surface::Field&>(pane.Residue());
569 for(int y=0;y<Surface::Resolution;++y) for(int x=0;x<Surface::Resolution;++x) {
570 const float dx=((x+.5f)*pane.Width()/Surface::Resolution-centre)/.008f;
571 field[y*Surface::Resolution+x]=.15f*(std::max)(0.f,1-dx*dx);
572 }
573 };
574 Surface left(1,3),right(1,3),forceFree(1,3),pinned(1,3);
575 band(left,.492f); band(right,.508f); band(forceFree,.508f); band(pinned,.5f);
576 for(auto* pane:{&left,&right,&forceFree}) pane->Impact({.5f,.2f},.0025f);
577 pinned.Impact({.5f,.2f},.0006f);
578 for(int i=0;i<30;++i) {
579 left.Update(1.f/30,0,{0,9.80665f},{},1); right.Update(1.f/30,0,{0,9.80665f},{},1);
580 forceFree.Update(1.f/30,0,{},{},1); pinned.Update(1.f/30,0,{0,9.80665f},{},1);
581 }
582 std::cout << "Wet-path guidance left/right=" << Largest(left).position.x << "/" << Largest(right).position.x << std::endl;
583 Check(Largest(left).position.x<.496f && Largest(right).position.x>.504f,
584 "runoff bends toward a nearby wet rivulet on either side");
585 Check(Largest(forceFree).position.x==.5f && Largest(forceFree).position.y==.2f,
586 "wet trails do not invent a force");
587 Check(Largest(pinned).position.y==.2f,"tiny satellite remains pinned on a wet trail");
588 std::cout << "PASS: dry/wet first-second travel " << dryTravel << "/" << wetTravel << " m; trail following and wiping.\n";
589}
590static void CheckRunoffContinuity()
591{
592 Surface runoff(1,2);
593 runoff.Impact({.5f,.2f},.0025f);
594 const double initial=Volume(runoff);
595 for(int i=0;i<60;++i)
596 {
597 const double before=Volume(runoff);
598 runoff.Update(1.f/30,0,{0,11.27f},{},1.f);
599 Check(Volume(runoff)<=before,"each daughter deposition debits its parent's water volume");
600 }
601 const auto parent=Largest(runoff);
602 Check(parent.wake.y<parent.position.y && parent.position.y-parent.wake.y<.061f,
603 "runoff wake follows the recent path and remains bounded in metres");
604 std::vector<Surface::BeadSample> beadMap;
605 std::vector<Surface::WakeSample> wakeMap;
606 runoff.BeadMap(beadMap,&wakeMap);
607 bool foundWake=false;
608 for(size_t i=0;i<beadMap.size();++i) if(beadMap[i].radius>0)
609 {
610 Check(wakeMap[i].radius<=beadMap[i].radius,
611 "wake width is bounded by its bead, never by the field texel");
612 foundWake |= wakeMap[i].y<beadMap[i].y-.005f;
613 }
614 Check(foundWake,"lookup retains a visible physical wake behind the parent");
615 Surface sweptWake;
616 sweptWake.Impact({.5f,.2f},.0025f);
617 for(int i=0;i<30;++i) sweptWake.Update(1.f/30,0,{0,11.27f},{},1.f);
618 const auto moving=Largest(sweptWake);
619 const float middle=(moving.position.y+moving.wake.y)*.5f;
620 sweptWake.WipeTriangle({.49f,middle-.001f},{.51f,middle-.001f},{.5f,middle+.001f});
621 const auto wiped=Largest(sweptWake);
622 Check(wiped.position.y==moving.position.y && wiped.wake.y==wiped.position.y,
623 "blade crossing only a wake clears it while retaining its unwiped parent");
624 Check(runoff.Drops().size()>=4 && parent.position.y>.35f && parent.radius<.0025f,
625 "rolling parent travels, shrinks, and leaves several smaller beads");
626 for(const auto& d:runoff.Drops()) if(d.radius<parent.radius)
627 Check(d.radius<.0007f && d.position.y<parent.position.y-.003f,
628 "daughter beads remain pinned behind the moving parent");
629 Check(Volume(runoff)<initial,"deposited beads take water from their parent instead of creating volume");
630 Surface oneG, twoG;
631 for(auto* s:{&oneG,&twoG}) s->Impact({.5f,.2f},.0025f);
632 oneG.Update(.25f,0,{0,9.80665f},{},1.f);
633 twoG.Update(.25f,0,{0,19.6133f},{},1.f);
634 Check(Largest(twoG).position.y-.2f>(Largest(oneG).position.y-.2f)*1.8f,
635 "positive two-G liftoff load accelerates downward runoff");
636 for(float speed:{100.f,120.f})
637 {
638 Surface fast(1,3);
639 fast.Impact({.5f,2.f},.0008f);
640 for(int i=0;i<9;++i) fast.Update(1.f/30,0,{0,11.27f},{0,-speed*.8f},1188.f/1013.25f,speed);
641 Check(fast.Drops().size()==1 && fast.Drops()[0].position.y<1.6f,
642 "small high-speed fragment travels over 40 cm before shedding");
643 const float residue=std::accumulate(fast.Residue().begin(),fast.Residue().end(),0.f);
644 Check(residue>0,"high-speed transit leaves a visible trajectory");
645 const_cast<std::vector<Drop>&>(fast.Drops()).clear();
646 for(int i=0;i<9;++i) fast.Update(1.f/30,0,{0,11.27f},{0,-speed*.8f},1188.f/1013.25f,speed);
647 Check(std::accumulate(fast.Residue().begin(),fast.Residue().end(),0.f)<residue*.02f,
648 "fast wakes clear within 0.3 seconds instead of becoming long-lived streaks");
649 }
650 std::cout << "PASS: shrinking runoff deposits " << runoff.Drops().size()-1
651 << " small beads; conserved water, two-G runoff, 100/120 m/s travel and short wakes.\n";
652}
653static void CheckSplashesAndRoughness()
654{
655 Surface splash;
656 constexpr float r=.0025f;
657 splash.Splash({.5f,.5f},r);
658 Check(splash.Drops().size()==4,"one impact produces a parent and three separated small satellites");
659 Check(std::abs(Volume(splash)/(r*r*r)-1)<.000002,"splash partitions incoming water without creating volume");
660 const auto original=splash.Drops();
661 for(int i=0;i<90;++i) splash.Update(1.f/30,0,{0,11.27f},{},1.f);
662 int pinned=0;
663 for(const auto& d:original) if(d.radius<.0007f)
664 {
665 bool retained=false;
666 for(const auto& now:splash.Drops()) if(now.position.x==d.position.x && now.position.y==d.position.y) retained=true;
667 pinned+=retained;
668 }
669 Check(pinned>=2,"separated splash satellites remain pinned; runoff can collect those in its path");
670 splash.WipeTriangle({0,0},{1,0},{1,1}); splash.WipeTriangle({0,0},{1,1},{0,1}); splash.Rebuild();
671 Check(!splash.Wet(),"wipers remove splash satellites along with running water");
672 Surface run(1,2),repeat(1,2);
673 for(auto* w:{&run,&repeat}) w->Impact({.5f,.2f},r);
674 float lo=.5f,hi=.5f,priorX=0;int turns=0;
675 for(int i=0;i<240;++i)
676 {
677 for(auto* w:{&run,&repeat}) w->Update(1.f/30,0,{0,11.27f},{},1.f);
678 const auto d=Largest(run);
679 lo=(std::min)(lo,d.position.x);hi=(std::max)(hi,d.position.x);
680 turns+=priorX*d.velocity.x<0; priorX=d.velocity.x;
681 }
682 Check(hi-lo>.001f && hi-lo<.06f && turns>=3,"gravity runoff meanders and changes lateral direction without broad sideways fanning");
683 Check(run.Water()==repeat.Water(),"imperfections stay fixed to the glass, with deterministic motion");
684 float priorSpeed=0;
685 for(int speed=0;speed<=120;++speed)
686 {
687 Surface air;air.Impact({.5f,.5f},.0008f);
688 air.Update(1.f/30,0,{},{0,-float(speed)},2630.397f/1013.25f,float(speed));
689 const float motion=-air.Drops()[0].velocity.y;
690 Check(motion+.00001f>=priorSpeed,"acceleration from road speed into flight never reduces aerodynamic drive");
691 priorSpeed=motion;
692 }
693 std::cout << "PASS: volume-conserving splash, persistent satellites, wipe; meander " << (hi-lo)*1000 << " mm, " << turns << " lateral turns.\n";
694}
695int main()
696{
697 CheckRainAirTaper();
698 CheckBladeSweeps();
699 CheckGravityDominatedRunoff();
700 CheckSplashesAndRoughness();
701 CheckWetTrailFollowing();
702 CheckRunoffContinuity();
703 CheckExteriorRain();
704 CheckHeavyCoverage();
705 CheckCloudRain();
706 CheckAltitudeRain();
707 CheckHighSpeedShedding();
708 CheckBeadShape();
709 CheckAirDensity();
710 CheckStationaryRain();
711 CheckCoalescence();
712 auto dryStorage=std::make_unique<Surface>(); auto& dry=*dryStorage;
713 for (int i=0;i<300;++i) dry.Update(1.f/30,0,{0,9.8f},{},1.f);
714 Check(!dry.Wet(),"dry weather never creates water");
715 auto gravityStorage=std::make_unique<Surface>(); auto& gravity=*gravityStorage;
716 gravity.Impact({.5f,.5f},.0025f);
717 for(int i=0;i<30;++i) gravity.Update(1.f/30,0,{0,9.8f},{},1.f);
718 Check(Largest(gravity).position.y>.5f,"gravity moves a stopped vehicle's drop down");
719 Check(Largest(gravity).radius<.0025f,"moving drops shrink");
720 const auto position=Largest(gravity).position;
721 gravity.WipeTriangle({position.x-.01f,position.y-.01f},{position.x+.02f,position.y-.01f},{position.x,position.y+.02f});
722 for(const auto& d:gravity.Drops()) Check(d.radius<.0007f,"blade removes parent but preserves smaller beads behind it");
723 gravity.Rebuild();
724 Check(Total(gravity)>0,"moving drop leaves a persistent trail behind the blade");
725 auto airStorage=std::make_unique<Surface>(); auto& air=*airStorage;
726 air.Impact({.5f,.5f},.0025f);
727 air.Update(.25f,0,{0,9.8f},{40,-70},1.f);
728 Check(air.Drops()[0].position.x>.5f && air.Drops()[0].position.y<.5f,"relative wind blows droplets sideways and upward at speed");
729 auto accelerationStorage=std::make_unique<Surface>(); auto& acceleration=*accelerationStorage;
730 acceleration.Impact({.5f,.5f},.0025f);
731 acceleration.Update(.25f,0,{-20,0},{},1.f);
732 Check(acceleration.Drops()[0].position.x<.5f,"vehicle acceleration changes drop motion");
733 auto wipeStorage=std::make_unique<Surface>(); auto& wipe=*wipeStorage;
734 wipe.Impact({.2f,.2f},.0025f); wipe.Impact({.8f,.8f},.0025f); wipe.Rebuild();
735 wipe.WipeTriangle({0,0},{.6f,0},{0,.6f}); wipe.Rebuild();
736 Check(wipe.Drops().size()==1 && wipe.Drops()[0].position.x==.8f,"wiping preserves drops outside the sweep");
737 wipe.Impact({.2f,.2f},.0025f); wipe.Rebuild();
738 Check(wipe.Drops().size()==2,"new impacts wet previously wiped glass");
739 wipe.WipeTriangle({0,0},{1,0},{1,1}); wipe.WipeTriangle({0,0},{1,1},{0,1}); wipe.Rebuild();
740 Check(!wipe.Wet(),"complete sweep removes drops and old streaks");
741 auto fps30Storage=std::make_unique<Surface>(), fps144Storage=std::make_unique<Surface>();
742 auto& fps30=*fps30Storage; auto& fps144=*fps144Storage;
743 for(int i=0;i<300;++i) fps30.Update(1.f/30,.6f,{0,9.8f},{5,0},1.f);
744 for(int i=0;i<1440;++i) fps144.Update(1.f/144,.6f,{0,9.8f},{5,0},1.f);
745 Check(fps30.Drops().size()==fps144.Drops().size(),"spawn count independent of render FPS");
746 Check(fps30.Water()==fps144.Water(),"water and trails identical at 30 and 144 FPS");
747 const auto paused=fps30.Water(); fps30.Update(0,1,{0,9.8f},{5,0},1.f);
748 Check(fps30.Water()==paused,"zero timestep preserves water");
749 auto stallStorage=std::make_unique<Surface>(); auto& stall=*stallStorage; stall.Update(30,1,{},{},1.f);
750 Check(stall.LastStepCount()==2,"a stalled frame uses only two collision/field steps");
751 Surface catchup(10,10), regular(10,10);
752 // Sparse impacts in a large field isolate elapsed spawning from collisions.
753 for(int i=0;i<4;++i) catchup.Update(.25f,.1f,{},{},0.f);
754 for(int i=0;i<30;++i) regular.Update(1.f/30,.1f,{},{},0.f);
755 Check(std::abs(int(catchup.Drops().size())-int(regular.Drops().size()))<=1
756 && catchup.Drops().size()>400,"bounded catch-up retains the elapsed precipitation rate");
757 Surface dryingSlow, dryingRegular;
758 dryingSlow.Impact({.5f,.5f},.0012f); dryingRegular.Impact({.5f,.5f},.0012f);
759 for(int i=0;i<4;++i) dryingSlow.Update(.25f,0,{},{},1.f,100.f);
760 for(int i=0;i<30;++i) dryingRegular.Update(1.f/30,0,{},{},1.f,100.f);
761 Check(std::abs(Largest(dryingSlow).radius-Largest(dryingRegular).radius)<.000001f,
762 "bounded catch-up retains elapsed evaporation without incoming rain");
763 auto quarterSecond=std::make_unique<Surface>(); quarterSecond->Update(.25f,1,{},{},1.f);
764 Check(stall.Water()==quarterSecond->Water() && stall.Drops().size()==quarterSecond->Drops().size(),
765 "long frame produces exactly the bounded quarter-second update");
766 for(int i=0;i<6000;++i) fps30.Update(1.f/30,0,{0,9.8f},{},1.f);
767 Check(!fps30.Wet(),"water dries after leaving rain");
768 stall.Clear(); Check(!stall.Wet(),"vehicle change clears all water");
769 float phase=0;
770 Check(AdvanceWiper(phase,.1f,false,true)==0,"unpowered wipers stay parked");
771 phase=AdvanceWiper(phase,.1f,true,true);
772 Check(phase>0,"rain starts powered wipers");
773 Check(AdvanceWiper(phase,.1f,false,false)==phase,"power loss freezes wiper");
774 for(int i=0;i<60;++i) phase=AdvanceWiper(phase,1.f/30,true,false);
775 Check(phase==0,"wipers finish their return and park when rain stops");
776 std::cout << "PASS: gravity, inertia, wind, shrinking streaks, selective wipe/re-wet, drying, bounded state, pause, 30/144 FPS equivalence, powered wiping and parking\n";
777}
const std::vector< Drop > & Drops() const
std::vector< float > Field
void Splash(Point position, float radius, Point velocity={}, bool coalesce=true)
static constexpr int Resolution
const Field & Residue() const
void SweepBlades(const std::vector< BladeSweep > &sweeps, float elapsed)
static constexpr float BeadRadiusScale
uint64_t Revision() const
void Impact(Point position, float radius, bool coalesce=true)
void WipeTriangle(Point a, Point b, Point c)
const Field & Water() const
static constexpr size_t MaxDrops
void Update(float elapsed, float rain, Point acceleration, Point wind, float airDensity, float airSpeed=-1.f, AirJet airJet={})
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Density(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float DropLimit(float intensity, float snow)
float ExteriorDropOpacity(int index, float intensity, int maximum)
float PrecipitationIntensity(float precipitation, float altitudeKm=0.f)
float LiquidRainIntensity(float precipitation, float snowBlend, bool exposed, float altitudeKm=0.f)
float AdvanceWiper(float phase, float elapsed, bool powered, bool raining, bool *moving=nullptr)
float AltitudeRainFactor(float altitudeKm)
float CloudRainFactor(float density, float belowBaseKm, bool volumeEnabled)
int ExteriorDropCount(float intensity, int maximum)