From dd917558acf99ae93f7051b19e6168d0168607c0 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 22 Apr 2023 14:02:30 -0400 Subject: [PATCH] Fix negative minute bug --- spatial-coordinate-systems/src/dmm.rs | 2 +- spatial-coordinate-systems/src/dms.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spatial-coordinate-systems/src/dmm.rs b/spatial-coordinate-systems/src/dmm.rs index 5774c50..dfc990f 100644 --- a/spatial-coordinate-systems/src/dmm.rs +++ b/spatial-coordinate-systems/src/dmm.rs @@ -108,7 +108,7 @@ impl DMM { pub fn from_decimal_degrees(d: f64, is_latitude: bool) -> Self { let degrees = d as i16; - let minutes = d.fract() * 60_f64; + let minutes = d.abs().fract() * 60_f64; let (degrees, direction) = normalize_degrees_direction( degrees, diff --git a/spatial-coordinate-systems/src/dms.rs b/spatial-coordinate-systems/src/dms.rs index 6eb94fd..3714b8b 100644 --- a/spatial-coordinate-systems/src/dms.rs +++ b/spatial-coordinate-systems/src/dms.rs @@ -108,7 +108,7 @@ impl DMS { pub fn from_decimal_degrees(d: f64, is_latitude: bool) -> Self { let degrees = d as i16; - let minutes = d.fract() * 60_f64; + let minutes = d.abs().fract() * 60_f64; let seconds = minutes.fract() * 60_f64; let minutes = minutes as i16; @@ -187,7 +187,6 @@ mod tests { eprintln!("Testing: {} => {:?}", $tt, cvt); assert!(cvt.is_ok()); eprintln!("Now converting to latlon"); - // assert!(dbg!(TryInto::::try_into(cvt.unwrap())).is_ok()); }}; ($tt:tt, DMS) => {{ let cvt = DMS::parse($tt);