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

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

1#include "../Viewscreen/CloudVolume.h"
2#include <iostream>
3#include <stdexcept>
4#include <limits>
5static unsigned checks=0;
6static void Check(bool value,const char* message){++checks;if(!value)throw std::runtime_error(message);}
7static bool Near(float a,float b,float tolerance=.0005f){return std::abs(a-b)<tolerance;}
8static CloudBaseWeather::Point At(int face,float u,float v,float altitude=0)
9{
10 auto p=CloudBaseWeather::Direction(face,u,v);
11 const float scale=(2939.6f+altitude)/std::sqrt(p.x*p.x+p.y*p.y+p.z*p.z);
12 return {p.x*scale,p.y*scale,p.z*scale};
13}
14int main()
15{
16 try
17 {
18 using namespace CloudBaseWeather;
19 for(int face=0;face<6;++face)
20 {
21 auto grid=std::make_shared<Grid>();grid->cube=face;grid->u=CenterU[face];grid->v=CenterV[face];
22 for(int y=0;y<64;++y)for(int x=0;x<64;++x)
23 grid->cells[y*64+x]={-.5f+.03f*x+.01f*y,.01f*x,1,0};
24 grid->Bounds();
25 for(int y=3;y<60;++y)for(int x=3;x<60;++x)
26 {
27 const auto p=At(face,float(grid->u+x-31)+.25f,float(grid->v+y-31)+.75f);
28 const auto value=grid->Sample(p);
29 Check(Near(value.coverage,1),"interior coverage");
30 Check(Near(value.base,-.5f+.03f*(x+.25f)+.01f*(y+.75f)),"ceiling orientation and bilinear interpolation");
31 Check(Near(value.turbulence,.01f*(x+.25f)),"turbulence orientation");
32 }
33 Frame frame{grid,1};
34 auto p=At(face,float(grid->u),float(grid->v));
35 const auto valid=Sample(frame,p,0,10,1.8f,.4f);
36 Check(Near(valid.base,.74f) && Near(valid.turbulence,.31f),"local base and scalar replace global controls");
37 for(float altitude:{9.5f,10.f,30.f,117.f,3000.f})
38 {
39 const auto high=Sample(frame,p,altitude,10,1.8f,.4f);
40 Check(high.base==1.8f && high.turbulence==.4f,"upper cloud controls changed");
41 }
42 grid->cells[31*64+31]={};
43 const auto missing=Sample(frame,p,0,10,1.8f,.4f);
44 Check(Near(missing.base,1.8f) && Near(missing.turbulence,.4f),"missing cell became false zero ceiling");
45 const auto half=Sample(frame,At(face,grid->u+.5f,float(grid->v)),0,10,1.8f,.4f);
46 Check(Near(half.base,(1.8f+.77f)*.5f),"invalid neighbor must blend to fallback");
47 const auto edge=Sample(frame,At(face,float(grid->u-31),float(grid->v)),0,10,1.8f,.4f);
48 Check(Near(edge.base,1.8f),"footprint edge not faded");
49
50 Store store;store.Target(grid);store.Advance(60);
51 auto before=store.Current()->Sample(At(face,float(grid->u+2),float(grid->v+2)));
52 for(const auto shift:std::array<std::array<int,2>,4>{{{{1,0}},{{-1,0}},{{0,1}},{{0,-1}}}})
53 {
54 auto shifted=std::make_shared<Grid>(*grid);shifted->u+=shift[0];shifted->v+=shift[1];
55 for(int y=0;y<64;++y)for(int x=0;x<64;++x)
56 shifted->cells[y*64+x]={-.5f+.03f*(x+shift[0])+.01f*(y+shift[1]),.01f*(x+shift[0]),1,0};
57 store.Target(shifted);
58 const auto after=store.Current()->Sample(At(face,float(grid->u+2),float(grid->v+2)));
59 Check(Near(after.base,before.base) && Near(after.turbulence,before.turbulence),"recenter moved retained weather");
60 }
61 auto revised=std::make_shared<Grid>(*grid);revised->cells.fill({4,.9f,1,0});
62 store.Target(revised);const auto old=store.Current()->Sample(At(face,float(grid->u+2),float(grid->v+2)));
63 store.Advance(1);const auto moved=store.Current()->Sample(At(face,float(grid->u+2),float(grid->v+2)));
64 Check(moved.base>old.base && moved.base<old.base+.1f,"weather refresh snapped base");
65 store.Target(nullptr);store.Advance(1);
66 Check(store.Current() && store.Current()->Sample(p).coverage<1,"coverage loss did not fade");
67 store.Advance(60);Check(!store.Current(),"expired coverage retained");
68 store.Target(revised);store.Advance(.1);store.Reset();Check(!store.Current(),"reset retained local field");
69 }
70 // Reprojection across a real face boundary preserves geographic values.
71 auto west=std::make_shared<Grid>();west->cube=0;west->u=2036;west->v=1019;west->cells.fill({2.5f,.7f,1,0});
72 auto east=std::make_shared<Grid>(*west);east->cube=1;east->u=2040;
73 Store seam;seam.Target(west);seam.Advance(60);seam.Target(east);
74 const auto retained=seam.Current()->Sample(At(1,2040,1019));
75 Check(Near(retained.base,2.5f) && Near(retained.turbulence,.7f),"cube-face handoff lost overlap");
76
77 auto grid=std::make_shared<Grid>();grid->cube=0;grid->u=grid->v=1019;grid->cells.fill({-.5f,1,1,0});grid->Bounds();
78 CloudVolume::Parameters local,global;local.localBase={grid,1};
79 const auto rayStart=At(0,1019,1019,0),rayEnd=At(0,1019,1019,1.2f);
80 Check(CloudVolume::Transmittance({rayStart.x,rayStart.y,rayStart.z},{rayEnd.x,rayEnd.y,rayEnd.z},local)<.01f
81 && CloudVolume::Transmittance({rayStart.x,rayStart.y,rayStart.z},{rayEnd.x,rayEnd.y,rayEnd.z},global)==1,
82 "light transmission clipped lower regional cloud to global shell");
83 for(float altitude:{-.3f,0.f,.3f,.7f,2.f,8.5f,9.f,9.5f,11.f,18.f})
84 {
85 const auto v=At(0,1019,1019,altitude);const CloudVolume::Point p{v.x,v.y,v.z};
87 Check(a.top==b.top,"local base shifted upper formation height");
88 if(altitude>=9.5f)
89 {
90 const auto da=CloudVolume::SampleMedium(p,local),db=CloudVolume::SampleMedium(p,global);
91 Check(a.base==b.base && da.density==db.density && da.extinction==db.extinction,"upper field not preserved exactly");
92 }
93 if(altitude==0)Check(CloudVolume::Density(p,local)>0 && CloudVolume::Density(p,global)==0,"lower local cloud clipped by global shell");
94 }
95 // Regional turbulence changes underside relief without changing its mean ceiling.
96 auto quiet=std::make_shared<Grid>(*grid);quiet->cells.fill({-.5f,0,1,0});quiet->Bounds();
97 CloudVolume::Parameters calm=local;calm.localBase={quiet,1};
98 float relief0=0,relief1=0;
99 for(int i=0;i<80;++i)
100 {
101 auto v=At(0,1000.f+i*.4f,1019,0);CloudVolume::Point p{v.x,v.y,v.z};
102 relief0+=std::abs(CloudVolume::LegacyBoundaries(p,calm).base+.5f);
103 relief1+=std::abs(CloudVolume::LegacyBoundaries(p,local).base+.5f);
104 }
105 Check(Near(relief1,relief0*3,.002f),"local turbulence does not control existing relief budget");
106 std::cout<<"PASS "<<checks<<" local cloud-base CPU checks\n";
107 return 0;
108 }
109 catch(const std::exception& error){std::cerr<<error.what()<<'\n';return 1;}
110}
void Target(GridPtr next)
void Advance(double elapsed)
Definition grid.h:14
char cube
Definition grid.h:45
Point Direction(int cube, float u, float v)
constexpr int CenterV[]
Controls Sample(const Frame &frame, Point p, float altitude, float top, float base, float turbulence)
constexpr int CenterU[]
Column LegacyBoundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Transmittance(Point from, Point to, const Parameters &params, uint32_t seed=DefaultSeed)
Medium SampleMedium(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Density(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141
CloudBaseWeather::Frame localBase
Definition CloudVolume.h:36