Skip to main content

Crate lightning_distance

Crate lightning_distance 

Source
Expand description

§lightning-distance

Estimate how far away a lightning strike is from the delay between the flash and the thunder, and apply the standard 30-second safety rule.

Sound takes roughly 5 seconds to travel one mile (3 seconds per kilometer).

use lightning_distance::{miles, is_dangerous};
assert!((miles(10.0) - 2.0).abs() < 1e-9);  // 10 s ~ 2 miles
assert_eq!(is_dangerous(10.0), true);        // <= 30 s is dangerous

Constants§

DANGER_THRESHOLD_SECS
The standard “go inside” threshold (seconds).
SECS_PER_KM
Seconds for sound to travel one kilometer (~3.0).
SECS_PER_MILE
Seconds for sound to travel one statute mile (~5.0).

Functions§

is_dangerous
The 30-second rule: if the gap is <= 30 s the storm is close enough to be dangerous.
kilometers
Distance in kilometers from the delay in seconds.
miles
Distance in miles from the flash-to-thunder delay in seconds.