Complete and test initial version of skyvector

This commit is contained in:
Austen Adler 2023-04-22 13:09:41 -04:00
parent 083089ea51
commit 80ca551fa9
2 changed files with 38 additions and 49 deletions

View File

@ -271,7 +271,7 @@ mod tests {
p!("1 2"); 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 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!( // assert_eq!(
// dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()), // dms::Coordinate::try_from(Coordinate::from_str("0.000000 100.500278").unwrap()),

View File

@ -1,14 +1,8 @@
use crate::{ use crate::{common::parse_direction, Direction, Error, LatLon};
common::{optional_separator, parse_direction, parse_f64},
dms::DMS,
Direction, Error, LatLon,
};
use nom::{ use nom::{
branch::alt,
bytes::complete::take, bytes::complete::take,
bytes::complete::take_while1, character::complete::{self, space0},
character::complete::{self, digit1, space0}, combinator::{map_parser, map_res, opt},
combinator::{map, map_parser, map_res, opt},
sequence::tuple, sequence::tuple,
IResult, IResult,
}; };
@ -47,11 +41,7 @@ impl Coordinate {
let lon = Self::dms_to_f64_helper(lon_d, lon_m, lon_s, &lon_direction); let lon = Self::dms_to_f64_helper(lon_d, lon_m, lon_s, &lon_direction);
let latlon = LatLon::new(lat, lon)?; let latlon = LatLon::new(lat, lon)?;
// Ok(Coordinate(..., latlon)) Ok(Coordinate(Self::latlon_to_string(&latlon), latlon))
// let latlon = LatLon::new(lat.to_decimal_degrees(), lon.to_decimal_degrees())?;
// Ok(Coordinate(lat, lon, latlon))
todo!();
} }
}, },
)(i) )(i)
@ -79,7 +69,7 @@ impl Coordinate {
let lat = dms.get_lat(); let lat = dms.get_lat();
let lon = dms.get_lon(); let lon = dms.get_lon();
format!( format!(
"{}{}{}{}{}{}{}{}", "{:02}{:02}{:02}{}{:03}{:02}{:02}{}",
lat.degrees, lat.degrees,
lat.minutes, lat.minutes,
lat.seconds, lat.seconds,
@ -90,6 +80,10 @@ impl Coordinate {
lon.direction, lon.direction,
) )
} }
pub fn get_skyvector(&self) -> &str {
&self.0
}
} }
impl FromStr for Coordinate { impl FromStr for Coordinate {
@ -115,8 +109,7 @@ impl From<&Coordinate> for LatLon {
impl From<LatLon> for Coordinate { impl From<LatLon> for Coordinate {
fn from(latlon: LatLon) -> Self { fn from(latlon: LatLon) -> Self {
// TODO: Encode the source and target // TODO: Encode the source and target
todo!() Coordinate(Self::latlon_to_string(&latlon), latlon)
// Self(ret, latlon)
} }
} }
@ -144,21 +137,17 @@ mod tests {
); );
} }
// fn test_general() { #[test]
// macro_rules! p { fn test_general() {
// ($tt:tt) => {{ assert_eq!(
// let cvt = Coordinate::from_str($tt); Coordinate::from(LatLon::new(12.0_f64, 24.0_f64).unwrap()).0,
// eprintln!("Testing: {} => {:?}", $tt, cvt); "120000N0240000E"
// assert!(cvt.is_ok()); );
// }};
// ($tt:tt, DMS) => {{ assert_eq!(
// let cvt = DMS::parse($tt); Coordinate::from(LatLon::new(12.0_f64, 100.0_f64).unwrap()).0,
// eprintln!("Testing: {} => {:?}", $tt, cvt); "120000N1000000E"
// assert!(cvt.is_ok()); );
// }};
// }
// // p!(r#"0° 0' 0" N 100° 30' 1" W"#);
// // p!(r#"0 0 0 N 100 30 1 W"#);
// p!("0° 0' N", DMS); // p!("0° 0' N", DMS);
// p!("0° 0'N", DMS); // p!("0° 0'N", DMS);
@ -171,13 +160,13 @@ mod tests {
// p!(r#"E 100° 30'"#, DMS); // p!(r#"E 100° 30'"#, DMS);
// p!(r#"N 0° 0' E 100° 30'"#); // p!(r#"N 0° 0' E 100° 30'"#);
// // parse_dmm_numeric(r#"38 53.2148425"#).unwrap(); // 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#"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#"-77° -1.7611312866219464'"#, DMS);
// // p!(r#"38° 53.2148425', -77° -1.7611312866219464'"#); // p!(r#"38° 53.2148425', -77° -1.7611312866219464'"#);
// } }
} }