Browse Source

remove wrap_count from OrbitTracker

Replace int wrap_count with bool initialized flag.
wrap_count was redundant with the accumulated_rotation threshold check.
Cleaner semantics: initialized tracks first-call baseline,
accumulated_rotation alone determines orbit completion.
test-refactor
cinnaboot 2 months ago
parent
commit
9e0a51999b
  1. 10
      src/test_utilities.cpp
  2. 2
      src/test_utilities.h

10
src/test_utilities.cpp

@ -51,7 +51,7 @@ OrbitTracker* create_orbit_tracker_with_min_time(int body_index, double min_time
tracker->initial_angle = 0.0;
tracker->previous_angle = 0.0;
tracker->accumulated_rotation = 0.0;
tracker->wrap_count = 0;
tracker->initialized = false;
tracker->orbit_completed = false;
tracker->time_at_completion = 0.0;
tracker->min_time_seconds = min_time_seconds;
@ -82,7 +82,7 @@ static void reset_tracker_fields(OrbitTracker* tracker) {
tracker->initial_angle = 0.0;
tracker->previous_angle = 0.0;
tracker->accumulated_rotation = 0.0;
tracker->wrap_count = 0;
tracker->initialized = false;
tracker->orbit_completed = false;
tracker->time_at_completion = 0.0;
}
@ -111,11 +111,11 @@ void update_orbit_tracker(OrbitTracker* tracker, CelestialBody* body, CelestialB
current_angle = atan2(relative_pos.y, relative_pos.x);
}
if (tracker->wrap_count == 0) {
if (!tracker->initialized) {
tracker->initial_angle = current_angle;
tracker->previous_angle = current_angle;
tracker->accumulated_rotation = 0.0;
tracker->wrap_count = 1;
tracker->initialized = true;
return;
}
@ -123,11 +123,9 @@ void update_orbit_tracker(OrbitTracker* tracker, CelestialBody* body, CelestialB
if (angle_diff > M_PI) {
angle_diff -= 2.0 * M_PI;
tracker->wrap_count++;
}
if (angle_diff < -M_PI) {
angle_diff += 2.0 * M_PI;
tracker->wrap_count++;
}
tracker->accumulated_rotation += angle_diff;

2
src/test_utilities.h

@ -16,7 +16,7 @@ struct OrbitTracker {
double initial_angle;
double previous_angle;
double accumulated_rotation;
int wrap_count;
bool initialized;
bool orbit_completed;
double time_at_completion;
int body_index;

Loading…
Cancel
Save