From 2ae700c7de1bab5336eab612ff6bd1d93df0c190 Mon Sep 17 00:00:00 2001 From: Jay Kickliter Date: Tue, 5 Dec 2023 10:57:11 -0700 Subject: [PATCH] =?UTF-8?q?[terrain]=20handing=20of=200=C2=B0=20edge=20con?= =?UTF-8?q?ditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terrain/src/tiles.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/terrain/src/tiles.rs b/terrain/src/tiles.rs index 4905dcc..7313844 100644 --- a/terrain/src/tiles.rs +++ b/terrain/src/tiles.rs @@ -121,12 +121,12 @@ fn sw_corner(Coord { x, y }: Coord) -> Coord { fn file_name(Coord { x, y }: Coord) -> 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") @@ -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"); } }