1#include "../Viewscreen/GroundTireGrip.h"
2
3#include <cmath>
4#include <iostream>
5#include <stdexcept>
6
7namespace
8{
9 void Check(bool condition, const char* message)
10 {
11 if (!condition)
12 throw std::runtime_error(message);
13 }
14
15 void TestCorneringBudget(float framesPerSecond, float direction)
16 {
17 const float dt = 1.0f / framesPerSecond;
18 const float gravityKmss = 0.01127f;
19 const float staticBudget = gravityKmss * dt;
20 const float kineticBudget = 0.75f * staticBudget;
21 float lateralVelocity = 0.0f;
22 float oldSlidingOnlyVelocity = 0.0f;
23 for (int frame = 0; frame < static_cast<int>(framesPerSecond * 3.0f); ++frame)
24 {
25
26 const float demand = direction * 0.85f * staticBudget;
28 oldSlidingOnlyVelocity += demand - direction * kineticBudget;
29 Check(lateralVelocity == 0.0f, "a turn within dry pavement grip accumulated sideways slip");
30 }
31 Check(std::fabs(oldSlidingOnlyVelocity) > 0.003f, "regression scenario did not reproduce old sideways drift");
32
34 0.65f * staticBudget, 0.50f * staticBudget);
35 Check(std::fabs(wetResult) > 0.0f && wetResult * direction > 0.0f,
36 "wet pavement incorrectly held a turn beyond its available grip");
37
39 staticBudget, kineticBudget);
40 Check(std::fabs(overloaded - direction * 0.45f * staticBudget) < 1.0e-8f,
41 "overloaded dry tires did not use the sliding friction budget");
42 }
43}
44
46{
47 try
48 {
49 for (float fps : { 20.0f, 30.0f, 60.0f, 144.0f })
50 for (float direction : { -1.0f, 1.0f })
51 TestCorneringBudget(fps, direction);
52 for (float velocity : { -0.01f, -0.0001f, 0.0f, 0.0001f, 0.01f })
53 {
55 "unloaded tires applied lateral friction");
57 Check(std::fabs(result) <= std::fabs(velocity) && result * velocity >= 0.0f,
58 "friction added energy or reversed lateral velocity");
59 }
61 "static grip failed at the budget boundary");
62 std::cout << "Ground tire grip tests passed (dry/wet, overload, zero load, both directions, 20-144 FPS).\n";
63 return 0;
64 }
65 catch (const std::exception& error)
66 {
67 std::cerr << error.what() << '\n';
68 return 1;
69 }
70}
float ResolveLateralVelocity(float velocityKms, float staticDeltaVKms, float kineticDeltaVKms)