API Reference¶
lightning-distance exposes two distance functions and one safety check,
plus three tunable constants. All take and return f64/bool. No structs,
no traits, no features to enable.
Constants¶
pub const SECS_PER_MILE: f64 = 5.0; // seconds for sound to travel 1 mile
pub const SECS_PER_KM: f64 = 3.0; // seconds for sound to travel 1 km
pub const DANGER_THRESHOLD_SECS: f64 = 30.0; // "go inside" cutoff
Approximate sound-travel rates used by the rule of thumb:
- 5 seconds per mile (sound ≈ 1,125 ft/s; a mile is 5,280 ft).
- 3 seconds per kilometer (sound ≈ 343 m/s).
- 30 seconds is the standard threshold below which a strike is close enough to be dangerous.
miles¶
Distance in miles from the flash-to-thunder delay:
seconds / SECS_PER_MILE.
use lightning_distance::miles;
assert!((miles(10.0) - 2.0).abs() < 1e-9); // 10 s → 2 mi
assert!((miles(5.0) - 1.0).abs() < 1e-9); // 5 s → 1 mi
kilometers¶
Distance in kilometers from the delay: seconds / SECS_PER_KM.
The km and mile results are internally consistent: km / miles ≈ 1.667
(the 5:3 ratio of the constants), close to the true 1.609 mi-to-km factor.
is_dangerous¶
The 30-second rule: returns true when seconds <= DANGER_THRESHOLD_SECS.
A strike within 30 seconds of the flash was within ~6 miles — close enough that the next strike could reach you. The standard advice is to shelter and wait 30 minutes after the last thunder.
use lightning_distance::is_dangerous;
assert!(is_dangerous(30.0)); // exactly at threshold → dangerous
assert!(is_dangerous(5.0)); // very close
assert!(!is_dangerous(45.0)); // far enough to be safer
The 30-minute clock
is_dangerous tells you whether this strike is close. It does not
tell you when it is safe to go back out — that is the separate "30 minutes
after the last thunder" rule, which you must reset on every clap. The
EarlyThunder storm tracker keeps that clock
for you.