Skip to content

Commit

Permalink
[terrain] handing of 0° edge conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Dec 5, 2023
1 parent 1f46009 commit 2ae700c
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions terrain/src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ fn sw_corner(Coord { x, y }: Coord<C>) -> Coord<i16> {
fn file_name(Coord { x, y }: Coord<i16>) -> String {
let (n_s, lat) = {
let lat = y.abs();
let n_s = if y.is_positive() { 'N' } else { 'S' };
let n_s = if y.is_negative() { 'S' } else { 'N' };
(n_s, lat)
};
let (e_w, lon) = {
let lon = x.abs();
let e_w = if x.is_positive() { 'E' } else { 'W' };
let e_w = if x.is_negative() { 'W' } else { 'E' };
(e_w, lon)
};
format!("{n_s}{lat:02}{e_w}{lon:03}.hgt")
Expand Down Expand Up @@ -160,8 +160,28 @@ mod tests {

#[test]
fn test_file_name() {
let sw_corner = sw_corner(MT_WASHINGTON);
let actual = file_name(sw_corner);
assert_eq!(actual, "N44W072.hgt");
let name = file_name(sw_corner(Coord {
y: 0.0 + f64::EPSILON,
x: 0.0 + f64::EPSILON,
}));
assert_eq!(name, "N00E000.hgt");

let name = file_name(sw_corner(Coord {
y: 0.0 + f64::EPSILON,
x: 0.0 - f64::EPSILON,
}));
assert_eq!(name, "N00W001.hgt");

let name = file_name(sw_corner(Coord {
y: 0.0 - f64::EPSILON,
x: 0.0 - f64::EPSILON,
}));
assert_eq!(name, "S01W001.hgt");

let name = file_name(sw_corner(Coord {
y: 0.0 - f64::EPSILON,
x: 0.0 + f64::EPSILON,
}));
assert_eq!(name, "S01E000.hgt");
}
}

0 comments on commit 2ae700c

Please sign in to comment.