Skip to content

Add shared unit conversion helpers (#45) - #98

Merged
Kamal-uva merged 1 commit into
mainfrom
45/unit-conversion-helpers
Oct 22, 2026
Merged

Kamal-uva merged 1 commit into
mainfrom
45/unit-conversion-helpers

Conversation

@pranavvadd

Copy link
Copy Markdown
Contributor

Summary

Adds sim/units.py with shared unit-conversion helpers and replaces the duplicated
conversion literals (2.237, 1609.34, 1000.0) with them. No simulator behavior changes.

Changes

  • sim/units.py (new): mph_to_mps, mps_to_mph, meters_to_miles, meters_to_km,
    km_to_meters, minutes_to_hours, minutes_to_seconds. The constants are defined once here.
  • Use the helpers in sim/config.py, sim/reporting.py, sim/plotting.py,
    sim/simulator.py and sim/planning/sweep.py. The old MPH_TO_MPS constant in
    sweep.py is removed.
  • tests/test_units.py (new): 49 pytest tests.

Testing

python3 -m pytest tests passes (71 tests). The new tests cover:

  • known values for every helper, round trips, numpy arrays/scalars, nan/inf
  • the constants are pinned so display values can't drift
  • SimulationResults, TrackConfig and the sweep's mph-to-m/s conversion use the helpers correctly
  • a guard test that fails if 2.237 or 1609.34 reappear outside sim/units.py

To check that outputs are unchanged, I ran all 3 tracks x 4 strategies plus fixed-speed sweeps
on main and on this branch and diffed the output. Reports, lap counts and feasibility are
identical. The only differences are last-digit floating-point noise (~1e-16) in two sweep rows,
from mph / 2.237 replacing mph * (1 / 2.237).

Related Issue

Closes #45

Notes

New sim/units.py with mph/mps, meters/miles/km, and minutes/hours/seconds
helpers. Replace duplicated 2.237, 1609.34 and 1000.0 literals in config,
reporting, plotting, simulator and the planning sweep.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Kamal-uva

Copy link
Copy Markdown
Contributor

awesome

@Kamal-uva
Kamal-uva merged commit 46bb124 into main Oct 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Conversion Helpers

2 participants