1 changed files with 67 additions and 0 deletions
@ -0,0 +1,67 @@
|
||||
# Rename bodies.h/cpp to simulation.h and Refactor Velocities (2026-01-07) |
||||
|
||||
## Changes Made |
||||
|
||||
Refactored simulation module and velocity initialization: |
||||
|
||||
1. **Renamed files** |
||||
- src/bodies.h → src/simulation.h |
||||
- src/bodies.cpp → src/simulation.cpp |
||||
- Updated all include references in src/ and tests/ |
||||
- Updated Makefile to reference simulation.cpp |
||||
- Updated documentation references |
||||
|
||||
2. **Moved simulation logic from config_loader to simulation** |
||||
- Moved calculate_initial_velocities() to simulation.cpp |
||||
- Moved calculate_soi_radii() to simulation.cpp |
||||
- Removed OrbitParams struct - use sim->bodies[i].fields directly |
||||
- Config loader now only handles TOML parsing |
||||
|
||||
3. **Refactored calculate_initial_velocities()** |
||||
- Broke up 114-line function into 8 focused functions with descriptive names |
||||
- Added vec3_cross() utility to physics.cpp for reusable cross product calculation |
||||
- Made helper functions static in simulation.cpp (internal implementation detail) |
||||
- Removed unnecessary helper declarations from simulation.h (cleaner public API) |
||||
|
||||
New helper functions: |
||||
- compute_perpendicular_orbital_velocity() - root body orbits (26 lines) |
||||
- compute_orbital_velocity_from_vis_viva() - child body orbits (37 lines) |
||||
- compute_system_barycenter() - barycenter calculation (28 lines) |
||||
- compute_total_root_mass() - total mass calculation (8 lines) |
||||
- set_root_bodies_velocity() - sets all root velocities (15 lines) |
||||
- set_child_bodies_velocity() - sets all child velocities (13 lines) |
||||
- print_system_info_if_multiple_roots() - debug output (7 lines) |
||||
|
||||
Main compute_initial_velocities() reduced from 114 to 10 lines. |
||||
|
||||
4. **Cleaned up public API** |
||||
- Removed helper function declarations from simulation.h |
||||
- Only public API remains: compute_initial_velocities(), calculate_initial_velocities(), calculate_soi_radii() |
||||
- Removed deprecated comment |
||||
|
||||
## Commits |
||||
|
||||
1. `81e799c` Rename bodies.h/cpp to simulation.h/cpp |
||||
2. `9aafbd5` Refactor velocity initialization into smaller functions |
||||
3. `aa8a6b9` Merge branch 'loading-refactor' - refactor velocity initialization |
||||
|
||||
## Results |
||||
|
||||
16 files changed, +200/-212 lines (net -12 lines) |
||||
|
||||
**Net line changes:** |
||||
- config_loader.cpp: 330 → 143 lines (-187) |
||||
- config_loader.h: 22 → 16 lines (-6) |
||||
- physics.cpp: 123 → 131 lines (+8) |
||||
- physics.h: 38 → 39 lines (+1) |
||||
- simulation.cpp: 187 → 350 lines (+163) |
||||
- simulation.h: 56 → 62 lines (+6) |
||||
|
||||
All builds and tests pass (24 assertions, 5 test cases). |
||||
|
||||
**Benefits:** |
||||
- Code reuse: vec3_cross() used 2x (eliminates duplicate perpendicular velocity logic) |
||||
- Testability: smaller functions easier to test individually |
||||
- Readability: descriptive function names for each body type scenario |
||||
- Maintainability: main function reduced from 114 to 10 lines (91% reduction) |
||||
- Better separation of concerns: config_loader only parses TOML, simulation handles physics |
||||
Loading…
Reference in new issue