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

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

1#pragma once
2
3void OrbitGroundTrackTests()
4{
5 // Independently specified physical-axis landmarks from Server.NET's
6 // LatitudeLongitude/Globals and the portal's [-180,-90,180,90] extent.
7 struct Landmark { Vec physical; double eastDegrees,northDegrees; };
8 const Landmark landmarks[]={
9 {{0,-1,0},0,0},{{1,0,0},90,0},{{-1,0,0},-90,0},
10 {{-1e-12,1,0},-180,0},{{1e-12,1,0},180,0},
11 {{0,-1,-1},0,45},{{0,-1,1},0,-45},
12 {{-1,-1,-1.4142135623730951},-45,45}
13 };
14 constexpr double left=12,right=239,top=43,bottom=270;
15 for(const auto& site:landmarks) for(double height:{0.,.1,10.,50.,100.,1000.}) {
16 Snapshot s;s.radius=2939.6;s.spin=Tau/(14.43*3600);
17 s.ownState.r=Unit(site.physical)*(s.radius+height);
18 s.targetKind=TargetKind::Surface;s.targetState.r=s.ownState.r;
19 // A future point rotating with Vieneo must overlie the same location.
20 s.plan.path={{s.ownState.r,0},{Rotate(s.ownState.r,{0,0,1},s.spin*300),300}};
21 const auto picture=Plot(s,View::Track);
22 const Point expected{left+(site.eastDegrees+180)/360*(right-left),
23 top+(90-site.northDegrees)/180*(bottom-top)};
24 for(const auto color:{Green,Cyan,Amber}) {
25 Point center;int endpoints=0;
26 for(const auto& line:picture.lines) if(line.color==color) {
27 center.x+=line.a.x+line.b.x;center.y+=line.a.y+line.b.y;endpoints+=2;
28 }
29 Check(endpoints>0,"ground track draws own, target and future plan");
30 Check(std::abs(center.x/endpoints-expected.x)<1e-7&&std::abs(center.y/endpoints-expected.y)<1e-7,
31 "ground track matches portal longitude, north-up latitude and planet rotation at every flight height");
32 }
33 }
34 Snapshot seam;
35 seam.ownPath={{{.02,1,0},0},{{.01,1,0},1},{{-.01,1,0},2},{{-.02,1,0},3}};
36 auto picture=Plot(seam,View::Track);int segments=0;
37 for(const auto& line:picture.lines) if(line.color==Green) {
38 ++segments;
39 Check(std::abs(line.a.x-line.b.x)<1,"antimeridian crossing never draws across the map");
40 }
41 Check(segments==2,"track retains both sides of the antimeridian");
42 seam.ownPath={{{-.01,-1,0},0},{{.01,-1,0},1}};
43 picture=Plot(seam,View::Track);segments=0;
44 for(const auto& line:picture.lines) if(line.color==Green) {
45 ++segments;
46 Check(line.a.x<125.5&&line.b.x>125.5,"prime meridian crossing is continuous through map center");
47 }
48 Check(segments==1,"prime meridian is not a wrap seam");
49}
50
51void OrbitPresentationTests()
52{
53 OrbitGroundTrackTests();
54 auto in=Fixture(); in.targetKind=TargetKind::None;
55 Request request; FlightPresentation display; Snapshot s;
56 auto sample=[&](double altitude,double vertical,double dt=.5,double horizontal=.35) {
57 in.now+=dt; in.own={{in.radius+altitude,0,0},{vertical,horizontal,0}};
58 s=Solve(in,request,false);
59 const auto raw=s.ownState;
60 display.Update(s,in);
61 Check(Norm(s.ownState.r-raw.r)==0&&Norm(s.ownState.v-raw.v)==0,
62 "presentation retains unfiltered navigation state");
63 };
64 // Reproduce the level-flight report near Freedom. The original sign-only
65 // condition flips on every sample; both presentation labels now hold.
66 int oldFlips=0; bool oldRising=true;
67 for(int n=0;n<120;++n) {
68 const double vertical=n%2?.0004:-.0004;
69 sample(7.4,vertical);
70 const bool old=vertical>=0; oldFlips+=old!=oldRising; oldRising=old;
71 Check(s.ascentDetail&&s.flightPhase==L"ASCENT / INSERTION","level flight holds local detail and phase");
72 Check(RowText(Row::View,request,s,in.now)==L"VIEW ASCENT (AUTO)","level flight holds VIEW label");
73 }
74 Check(oldFlips>100,"trace reproduces original sign-only view flicker");
75 // Short excursions beyond the deadband do not constitute a phase change.
76 for(int n=0;n<40;++n) {
77 sample(7.4,n%4<2?-.03:.03);
78 Check(s.ascentDetail,"brief vertical excursions retain ascent detail");
79 }
80 for(int n=0;n<5;++n) { sample(7.4,-.03); Check(s.ascentDetail,"descent waits for confirmation"); }
81 sample(7.4,-.03);
82 Check(!s.ascentDetail&&s.flightPhase==L"SUBORBITAL / ENTRY","sustained descent selects overview");
83 // Plan/target/view edits and entry into a station-relative frame do not
84 // reset trend memory; manual/Autoflyte ownership is not an input to it.
85 for(int n=0;n<40;++n) {
86 request.view=View(n%4); ++request.revision; ++in.targetId;
87 sample(7.4,n%2?.0004:-.0004);
88 Check(!s.ascentDetail,"level-off after descent retains overview through plan edits");
89 }
90 for(int n=0;n<6;++n) sample(7.4,.03);
91 Check(s.ascentDetail,"sustained climb re-arms ascent detail");
92 request.view=View::Orbit;
93 sample(99.9,1,.5,4.5); Check(s.ascentDetail,"high-speed ascent retains local view below boundary");
94 sample(100.1,1,.5,4.5); Check(!s.ascentDetail,"high-speed ascent exits detail at 100 km");
95 for(int n=0;n<40;++n) {
96 sample(n%2?100.05:99.95,1,.5,4.5);
97 Check(!s.ascentDetail,"100 km altitude jitter cannot flip automatic zoom");
98 }
99 sample(98.9,.03); Check(s.ascentDetail,"automatic zoom re-arms below 99 km");
100 display={}; sample(75,-1,.5,5);
101 Check(!s.ascentDetail&&s.flightPhase==L"SUBORBITAL / ENTRY","established high-speed entry starts in overview");
102 in.onGround=true; in.freeFlight=false; sample(.2,-.0004);
103 Check(s.ascentDetail,"touchdown resets ascent presentation");
104 in.onGround=false; in.freeFlight=true;
105 for(int n=0;n<30;++n) { sample(.3,n%2?.004:-.004,.5,0); Check(s.ascentDetail,"VTOL hover stays stable"); }
106 in.powered=false; sample(.3,0);
107 Check(!s.ascentDetail&&s.flightPhase.empty(),"power loss clears presentation history");
108 in.powered=true; sample(75,-1);
109 Check(!s.ascentDetail,"power restored during descent initializes from current flight");
110 in.freeFlight=false; sample(937,0);
111 Check(!s.ascentDetail&&s.flightPhase==L"DOCKED","actual docking clears automatic zoom");
112 in.freeFlight=true; sample(7.4,-.0004);
113 Check(s.ascentDetail,"undocking initializes level-flight view");
114 // Frozen simulation time and one stalled frame cannot confirm a reversal.
115 for(int n=0;n<20;++n) { sample(7.4,-.03,0); Check(s.ascentDetail,"freeze does not advance display confirmation"); }
116 sample(7.4,-.03,30); Check(s.ascentDetail,"single long frame cannot confirm reversal");
117 for(int n=0;n<4;++n) sample(7.4,-.03);
118 Check(!s.ascentDetail,"normal updates resume reversal confirmation");
119 sample(7.4,-.0004,-100);
120 Check(s.ascentDetail,"time reset discards prior descent");
121 display={}; // same reset used for vehicle/simulator changes and teleport
122 sample(7.4,-.0004); Check(s.ascentDetail,"new flight does not inherit descent history");
123 display={};
124 const double speed=std::sqrt(in.gm/(in.radius+300));
125 for(int n=0;n<40;++n) {
126 sample(300,n%2?.0004:-.0004,.5,speed);
127 Check(!s.ascentDetail&&s.flightPhase==L"ORBIT","orbital coast remains overview");
128 }
129 in.own.v.x=std::numeric_limits<double>::quiet_NaN(); display.Update(s,in);
130 Check(!s.ascentDetail&&s.flightPhase.empty(),"invalid state clears presentation without stale phase");
131}
bool Unit(Vector3 &v)
Plan Solve(const Input &in, const Request &r, bool geometry)
Definition OrbitEntry.h:332
constexpr double Tau
Definition OrbitMath.h:10
std::wstring RowText(Row row, const Request &r, const Snapshot &s, double now)
Vec Rotate(Vec v, Vec axis, double angle)
Definition OrbitMath.h:22
constexpr std::uint32_t Cyan
Definition OrbitDisplay.h:9
constexpr std::uint32_t Green
Definition OrbitDisplay.h:9
constexpr std::uint32_t Amber
Definition OrbitDisplay.h:9
Picture Plot(const Snapshot &s, View view)
double Norm(Vec a)
Definition OrbitMath.h:18