diff options
| author | Adam Malczewski <[email protected]> | 2026-03-10 16:55:36 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-03-10 16:55:36 +0900 |
| commit | e7c69ea6f7358e78acad36eca99c96eeeed096ce (patch) | |
| tree | 9690c665b68679804a21ab05ae30997e7265cda0 /src/utils/calculate_circumference.ts | |
| parent | e542742c0525ec0971eb89daaf3e8fc1b30e48fb (diff) | |
| download | tirecalc-e7c69ea6f7358e78acad36eca99c96eeeed096ce.tar.gz tirecalc-e7c69ea6f7358e78acad36eca99c96eeeed096ce.zip | |
write app plus touchup
Diffstat (limited to 'src/utils/calculate_circumference.ts')
| -rw-r--r-- | src/utils/calculate_circumference.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/utils/calculate_circumference.ts b/src/utils/calculate_circumference.ts new file mode 100644 index 0000000..4ef6a2f --- /dev/null +++ b/src/utils/calculate_circumference.ts @@ -0,0 +1,36 @@ +/** + * calculate_circumference.ts + * + * Pure function that computes the bicycle wheel circumference from rim and + * tire diameters (both in mm). The formula uses 3.13772 instead of exact π + * to approximate the "roll-out" circumference (tire compressed under rider + * weight). + * + * Formula: circumference_mm = 3.13772 × (2 × tire_diameter + rim_diameter) + */ + +import type { CircumferenceResult } from "../types"; + +/** The modified Pi constant that accounts for tire compression. */ +const ROLLOUT_PI = 3.13772; + +/** + * Returns circumference in multiple units, or null when inputs are invalid + * (non-positive or missing). + */ +export function calculate_circumference( + rim_mm: number, + tire_mm: number, +): CircumferenceResult | null { + if (rim_mm <= 0 || tire_mm <= 0 || isNaN(rim_mm) || isNaN(tire_mm)) { + return null; + } + + const circ_mm = ROLLOUT_PI * (2 * tire_mm + rim_mm); + + return { + mm: Math.round(circ_mm), + cm: Math.round(circ_mm / 10), + inches: Math.round((10 * circ_mm) / 25.4) / 10, + }; +} |
