Skip to content

Commit

Permalink
Merge pull request #18 from JeromeSchmied/srtm-update
Browse files Browse the repository at this point in the history
refactor: update srtm_reader, use narrower int where applicable
  • Loading branch information
JeromeSchmied authored Jan 25, 2025
2 parents e9454fb + 20c1308 commit 2a58954
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fit2gpx"
version = "0.5.4"
version = "0.5.5"
edition = "2021"

authors = ["Jeromos Kovács <[email protected]>"]
Expand All @@ -20,7 +20,7 @@ geo-types = "0.7.15"
gpx = "0.10.0"
log = "0.4.25"
rayon = "1.10.0"
srtm_reader = { version = "0.4.2", optional = true }
srtm_reader = { version = "0.5.0", optional = true }
time = { version = "0.3.37", default-features = false }

[features]
Expand Down
15 changes: 9 additions & 6 deletions src/elevation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ pub use std::{
path::Path,
};

/// truncated coordinate
pub type Coord = (i8, i16);

// TODO: docs
pub fn needed_tile_coords(wps: &[Waypoint]) -> BTreeSet<(i32, i32)> {
// kinda Waypoint to (i32, i32)
let trunc = |wp: &Waypoint| -> (i32, i32) {
pub fn needed_tile_coords(wps: &[Waypoint]) -> BTreeSet<Coord> {
// kinda Waypoint to Coord
let trunc = |wp: &Waypoint| -> Coord {
let (x, y) = wp.point().x_y();
(y.trunc() as i32, x.trunc() as i32)
(y.trunc() as i8, x.trunc() as i16)
};
// tiles we need
wps.par_iter()
Expand All @@ -22,7 +25,7 @@ pub fn needed_tile_coords(wps: &[Waypoint]) -> BTreeSet<(i32, i32)> {

// TODO: docs
pub fn read_needed_tiles(
needs: &BTreeSet<(i32, i32)>,
needs: &BTreeSet<Coord>,
elev_data_dir: impl AsRef<Path>,
) -> Vec<srtm_reader::Tile> {
log::info!("reading needed tiles into memory");
Expand All @@ -31,7 +34,7 @@ pub fn read_needed_tiles(
let elev_data_dir = elev_data_dir.as_ref();
needs
.par_iter()
.map(|c| srtm_reader::get_filename(*c))
.map(|c| srtm_reader::Coord::from(*c).get_filename())
.map(|t| elev_data_dir.join(t))
.flat_map(|p| {
srtm_reader::Tile::from_file(&p)
Expand Down

0 comments on commit 2a58954

Please sign in to comment.