#ifndef TEST_UTILITIES_H #define TEST_UTILITIES_H #include "simulation.h" #include "physics.h" // Test tolerance constants // NOTE: Individual tests may use tighter or looser tolerances based on // observed errors. See per-test comments for adjustments. static const double A_TOL = 1e-6; // semi-major axis (meters), |a| < 1e10 static const double E_TOL = 1e-12; // eccentricity, round-trip conversion static const double ANG_TOL = 1e-12; // angles in radians (nu, inc, Ω, ω) static const double ANG_TOL_COARSE = 1e-4; // angles, degenerate cases (polar/retrograde) static const double R_TOL = 1e-6; // radius / distance magnitudes (meters) static const double V_TOL = 1e-6; // velocity magnitudes (m/s) static const double M_TOL = 1e-6; // time / period values (seconds) static const double REL_TOL = 1e-8; // relative / percentage errors (dimensionless) static const double DRIFT_TOL = 1e-12; // energy drift percent (parabolic orbit) struct OrbitalMetrics { double kinetic_energy; double potential_energy; double total_energy; double orbital_radius; double velocity_magnitude; }; struct OrbitTracker { double initial_angle; double previous_angle; double accumulated_rotation; bool initialized; bool orbit_completed; double time_at_completion; int body_index; double min_time_seconds; // Orbital elements for 3D angle calculation double inclination; double longitude_of_ascending_node; double argument_of_periapsis; bool has_orbital_elements; }; double calculate_kinetic_energy(CelestialBody* body); double calculate_potential_energy_pair(CelestialBody* body1, CelestialBody* body2); double calculate_system_total_energy(SimulationState* sim); OrbitalMetrics calculate_orbital_metrics(CelestialBody* body, CelestialBody* parent); OrbitTracker* create_orbit_tracker(int body_index); OrbitTracker* create_orbit_tracker_with_min_time(int body_index, double min_time_seconds); OrbitTracker* create_orbit_tracker_3d(int body_index, double min_time_days, double inclination, double lon_ascending_node, double argument_of_periapsis); void reset_orbit_tracker(OrbitTracker* tracker); void update_orbit_tracker(OrbitTracker* tracker, CelestialBody* body, CelestialBody* parent, double current_time); void destroy_orbit_tracker(OrbitTracker* tracker); // Write simulation state to a caller-allocated buffer. // Returns number of characters written (excluding null terminator). // Caller must ensure buffer is large enough (recommended 4096 bytes). int dump_simulation_state(SimulationState* sim, const char* label, char* buffer, int buffer_size); bool compare_vec3(Vec3 a, Vec3 b, double tolerance); #endif