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;}
9{
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}
15{
16 try
17 {
19 for(int face=0;face<6;++face)
20 {
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};
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 }
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
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};
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)));
64 Check(moved.base>old.base && moved.base<old.base+.1f,"weather refresh snapped base");
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");
69 }
70
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;
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
79 const auto rayStart=At(0,1019,1019,0),rayEnd=At(0,1019,1019,1.2f);
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 {
87 Check(a.top==b.top,"local base shifted upper formation height");
88 if(altitude>=9.5f)
89 {
91 Check(a.base==b.base && da.density==db.density && da.extinction==db.extinction,"upper field not preserved exactly");
92 }
94 }
95
96 auto quiet=std::make_shared<Grid>(*
grid);quiet->cells.fill({-.5f,0,1,0});quiet->Bounds();
98 float relief0=0,relief1=0;
99 for(int i=0;i<80;++i)
100 {
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)
Point Direction(int cube, float u, float v)
Controls Sample(const Frame &frame, Point p, float altitude, float top, float base, float turbulence)
Column LegacyBoundaries(Point p, const Parameters ¶ms, uint32_t seed=DefaultSeed)
float Transmittance(Point from, Point to, const Parameters ¶ms, uint32_t seed=DefaultSeed)
Medium SampleMedium(Point p, const Parameters ¶ms, uint32_t seed=DefaultSeed)
float Density(Point p, const Parameters ¶ms, uint32_t seed=DefaultSeed)
bool Near(const Body &b, const Triangle &t, double extra)
CloudBaseWeather::Frame localBase