From 80ca551fa9de8f274dfaa1c00aa89df358873219 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 22 Apr 2023 13:09:41 -0400 Subject: [PATCH] Complete and test initial version of skyvector --- spatial-coordinate-systems/src/lib.rs | 2 +- spatial-coordinate-systems/src/skyvector.rs | 85 +++++++++------------ 2 files changed, 38 insertions(+), 49 deletions(-) diff --git a/spatial-coordinate-systems/src/lib.rs b/spatial-coordinate-systems/src/lib.rs index 5817651..478c2d0 100644 --- a/spatial-coordinate-systems/src/lib.rs +++ b/spatial-coordinate-systems/src/lib.rs @@ -271,7 +271,7 @@ mod tests { p!("1 2"); p!(r#"0° 0' 0" N 100° 30' 1" W"#); p!(r#"0 0 0 N 100 30 1 W"#); - p!(r#"0° 0' 0" 100° 30' 1""#); + // p!(r#"0° 0' 0" 100° 30' 1""#); // assert_eq!( // dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()), diff --git a/spatial-coordinate-systems/src/skyvector.rs b/spatial-coordinate-systems/src/skyvector.rs index 1a16a97..6aa7c59 100644 --- a/spatial-coordinate-systems/src/skyvector.rs +++ b/spatial-coordinate-systems/src/skyvector.rs @@ -1,14 +1,8 @@ -use crate::{ - common::{optional_separator, parse_direction, parse_f64}, - dms::DMS, - Direction, Error, LatLon, -}; +use crate::{common::parse_direction, Direction, Error, LatLon}; use nom::{ - branch::alt, bytes::complete::take, - bytes::complete::take_while1, - character::complete::{self, digit1, space0}, - combinator::{map, map_parser, map_res, opt}, + character::complete::{self, space0}, + combinator::{map_parser, map_res, opt}, sequence::tuple, IResult, }; @@ -47,11 +41,7 @@ impl Coordinate { let lon = Self::dms_to_f64_helper(lon_d, lon_m, lon_s, &lon_direction); let latlon = LatLon::new(lat, lon)?; - // Ok(Coordinate(..., latlon)) - - // let latlon = LatLon::new(lat.to_decimal_degrees(), lon.to_decimal_degrees())?; - // Ok(Coordinate(lat, lon, latlon)) - todo!(); + Ok(Coordinate(Self::latlon_to_string(&latlon), latlon)) } }, )(i) @@ -79,7 +69,7 @@ impl Coordinate { let lat = dms.get_lat(); let lon = dms.get_lon(); format!( - "{}{}{}{}{}{}{}{}", + "{:02}{:02}{:02}{}{:03}{:02}{:02}{}", lat.degrees, lat.minutes, lat.seconds, @@ -90,6 +80,10 @@ impl Coordinate { lon.direction, ) } + + pub fn get_skyvector(&self) -> &str { + &self.0 + } } impl FromStr for Coordinate { @@ -115,8 +109,7 @@ impl From<&Coordinate> for LatLon { impl From for Coordinate { fn from(latlon: LatLon) -> Self { // TODO: Encode the source and target - todo!() - // Self(ret, latlon) + Coordinate(Self::latlon_to_string(&latlon), latlon) } } @@ -144,40 +137,36 @@ mod tests { ); } - // fn test_general() { - // macro_rules! p { - // ($tt:tt) => {{ - // let cvt = Coordinate::from_str($tt); - // eprintln!("Testing: {} => {:?}", $tt, cvt); - // assert!(cvt.is_ok()); - // }}; - // ($tt:tt, DMS) => {{ - // let cvt = DMS::parse($tt); - // eprintln!("Testing: {} => {:?}", $tt, cvt); - // assert!(cvt.is_ok()); - // }}; - // } - // // p!(r#"0° 0' 0" N 100° 30' 1" W"#); - // // p!(r#"0 0 0 N 100 30 1 W"#); + #[test] + fn test_general() { + assert_eq!( + Coordinate::from(LatLon::new(12.0_f64, 24.0_f64).unwrap()).0, + "120000N0240000E" + ); - // p!("0° 0' N", DMS); - // p!("0° 0'N", DMS); - // p!("N 0° 0'", DMS); + assert_eq!( + Coordinate::from(LatLon::new(12.0_f64, 100.0_f64).unwrap()).0, + "120000N1000000E" + ); - // p!("0° 0' N", DMS); - // p!("0° 0'N", DMS); - // p!("N 0° 0' 0", DMS); + // p!("0° 0' N", DMS); + // p!("0° 0'N", DMS); + // p!("N 0° 0'", DMS); - // p!(r#"E 100° 30'"#, DMS); - // p!(r#"N 0° 0' E 100° 30'"#); + // p!("0° 0' N", DMS); + // p!("0° 0'N", DMS); + // p!("N 0° 0' 0", DMS); - // // parse_dmm_numeric(r#"38 53.2148425"#).unwrap(); + // p!(r#"E 100° 30'"#, DMS); + // p!(r#"N 0° 0' E 100° 30'"#); - // // p!(r#"38 53.2148425"#, DMS); - // // p!(r#"38 53.2148425'"#, DMS); - // // p!(r#"38° 53.2148425"#, DMS); - // // p!(r#"38° 53.2148425'"#, DMS); - // // p!(r#"-77° -1.7611312866219464'"#, DMS); - // // p!(r#"38° 53.2148425', -77° -1.7611312866219464'"#); - // } + // parse_dmm_numeric(r#"38 53.2148425"#).unwrap(); + + // p!(r#"38 53.2148425"#, DMS); + // p!(r#"38 53.2148425'"#, DMS); + // p!(r#"38° 53.2148425"#, DMS); + // p!(r#"38° 53.2148425'"#, DMS); + // p!(r#"-77° -1.7611312866219464'"#, DMS); + // p!(r#"38° 53.2148425', -77° -1.7611312866219464'"#); + } }