Skip to content

Commit

Permalink
docs(elev, fit): add, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeromos Kovács committed Jan 26, 2025
1 parent 83674cb commit a6432c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/elevation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub use std::{
/// truncated coordinate
pub type Coord = (i8, i16);

// TODO: docs
/// collect all the [`srtm_reader::Tile`]'s coordinates that shall be loaded into memory
/// in order to be able to get elevation data for all `wps`
pub fn needed_tile_coords(wps: &[Waypoint]) -> BTreeSet<Coord> {
// kinda Waypoint to Coord
let trunc = |wp: &Waypoint| -> Coord {
Expand All @@ -23,7 +24,8 @@ pub fn needed_tile_coords(wps: &[Waypoint]) -> BTreeSet<Coord> {
.collect()
}

// TODO: docs
/// read HGT [`srtm_reader::Tile`]s specified by `needs`, from `elev_data_dir`
/// **_NOTE_**: if a [`srtm_reader::Tile`] can't be loaded, it won't be
pub fn read_needed_tiles(
needs: &BTreeSet<Coord>,
elev_data_dir: impl AsRef<Path>,
Expand All @@ -42,8 +44,7 @@ pub fn read_needed_tiles(
})
.collect()
}
// TODO: docs
/// index the tiles with their coordinates
/// index the [`srtm_reader::Tile`]s with their coordinates
pub fn index_tiles(tiles: Vec<srtm_reader::Tile>) -> HashMap<(i8, i16), srtm_reader::Tile> {
log::info!("indexing all dem tiles");
log::trace!("tiles: {tiles:?}");
Expand All @@ -53,21 +54,18 @@ pub fn index_tiles(tiles: Vec<srtm_reader::Tile>) -> HashMap<(i8, i16), srtm_rea
.collect()
// log::debug!("loaded elevation data: {:?}", all_elev_data.keys());
}
impl crate::Fit {}

/// add elevation to all `wps` using `elev_data` if available, in parallel
///
/// # Safety
///
/// it's the caller's responsibility to have the necessary data loaded
///
/// # Usage
///
/// using the following order, it should be safe
///
/// ```no_run
/// use fit2gpx::elevation;
///
/// let mut fit = fit2gpx::Fit::from_file("evening walk.gpx").unwrap();
/// let mut fit = fit2gpx::Fit::from_file("evening_walk.fit").unwrap();
/// let elev_data_dir = "~/Downloads/srtm_data";
/// let needed_tile_coords = elevation::needed_tile_coords(&fit.track_segment.points);
/// let needed_tiles = elevation::read_needed_tiles(&needed_tile_coords, elev_data_dir);
Expand Down
3 changes: 2 additions & 1 deletion src/fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Fit {
pub track_segment: TrackSegment,
}

// high level functions impl
// public fns
impl Fit {
/// add a filename to `self`, create new instance
pub fn with_filename(self, fname: impl Into<PathBuf>) -> Self {
Expand Down Expand Up @@ -90,6 +90,7 @@ impl Fit {
add_elev_unchecked(&mut fit.track_segment.points, &all_elev_data, overwrite);
}
}
/// private fns
impl Fit {
/// [`fit_file::FitRecordMsg`] to [`gpx::Waypoint`]
// TODO: support heart-rate, distance, temperature and such extensions, if `gpx` crate does too
Expand Down

0 comments on commit a6432c4

Please sign in to comment.