1#include "../Viewscreen/SunPositionOverride.h"
2#include "../Viewscreen/WeatherOverrides.h"
3#include <cstdlib>
4#include <iostream>
5#include <limits>
6
8static void Check(bool condition, const char* message)
9{
10 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
11}
12
13int main()
14{
15 float value = .75f;
16 for (const auto* text : {L"0.5", L".5", L"+0.5", L" 0.5 "})
18 for (const auto* text : {L"0", L"1", L"-1", L"0.125", L"0.9999"})
20 for (const auto* text : {L"", L" ", L"0.5junk", L"0,5", L"0.5 1", L"nan", L"inf",
21 L"1e999", L"1.001", L"-0.1", L"-2", L"+-1"})
22 {
23 value = .75f;
25 "invalid input leaves previous position alone");
26 }
27
28 M::Matrix orbit, rotation;
29 M::MatrixScaling(&orbit, 40, 40, 40);
30 orbit._42 = -100000.f;
31 for (float angle : {0.f, .73f, M::Pi})
32 {
33 M::MatrixRotationZ(&rotation, angle);
34 const M::Matrix natural = orbit * rotation;
35 for (M::Vector3 up : {M::Vector3(0, 1, 0), M::Vector3(0, -1, 0),
36 M::Vector3(0, 0, 1), M::Vector3(0, 0, -1), M::Vector3(3, 4, 5)})
37 {
38 M::Vec3Normalize(&up, &up);
39 M::Vector3 source(natural._41, natural._42, natural._43);
40 M::Vec3Normalize(&source, &source);
41 const M::Vector3 naturalTangent = source - up * M::Vec3Dot(&source, &up);
42 for (int step = 0; step <= 100; ++step)
43 {
44 const float mode = step / 100.f;
45 M::Matrix world = natural;
46 M::Vector3 light(.2f, .3f, .4f);
48 const M::Vector3 center(world._41, world._42, world._43);
49 const M::Vector3 right(world._11, world._12, world._13);
50 M::Vector3 normal(world._21, world._22, world._23);
51 const M::Vector3 top(world._31, world._32, world._33);
52 Check(std::fabs(M::Vec3Length(¢er) - 100000.f) < .04f, "solar distance retained");
53 Check(std::fabs(M::Vec3Length(&right) - 40.f) < .001f &&
54 std::fabs(M::Vec3Length(&top) - 40.f) < .001f, "solar disc size retained");
55 M::Vec3Normalize(&normal, &normal);
56 Check(M::Vec3Dot(&normal, &light) > .99999f, "disc faces observer");
57 Check(std::fabs(M::Vec3Dot(&light, &up) + std::sin((mode - .5f) * M::Pi)) < .00001f,
58 "linear elevation from nadir through horizon to zenith at every latitude");
59 Check(M::Vec3Dot(¢er, &light) < -99999.f, "disc and illumination agree");
60 if (step > 0 && step < 100 && M::Vec3LengthSq(&naturalTangent) > 1.e-10f)
61 Check(M::Vec3Dot(&naturalTangent, &light) < 0, "natural sun bearing retained");
62 M::Matrix repeated = natural;
63 M::Vector3 repeatedLight;
65 Check(std::memcmp(&repeated, &world, sizeof world) == 0, "no accumulation or fallback drift");
66 }
67 for (float mode : {-1.f, -.1f, 1.1f, std::numeric_limits<float>::infinity(),
68 std::numeric_limits<float>::quiet_NaN()})
69 {
70 M::Matrix world = natural;
71 const M::Vector3 original(.2f, .3f, .4f);
72 M::Vector3 light = original;
74 Check(std::memcmp(&world, &natural, sizeof world) == 0 && light == original,
75 "reset and invalid override preserve current orbit and light exactly");
76 }
77 }
78 }
79 std::cout << "PASS: sun parsing, 1515 positions, bearing, disc geometry, endpoints and reset\n";
80}
void Apply(float mode, const RiseMath::Vector3 &outwardNormal, RiseMath::Matrix &sunWorld, RiseMath::Vector3 &incomingLight)
bool ParseValue(const wchar_t *text, float minimum, float maximum, float &value)