diff --git a/spatial-coordinate-systems/src/all.rs b/spatial-coordinate-systems/src/all.rs index 0a52432..465481e 100644 --- a/spatial-coordinate-systems/src/all.rs +++ b/spatial-coordinate-systems/src/all.rs @@ -7,7 +7,7 @@ use crate::{ dmm, dms, plus, //xpin - sky_vector, + ddmmss, utm, Coordinate, Error, @@ -26,7 +26,7 @@ pub struct Coordinates { pub utm: utm::Coordinate, // pub xpin: xpin::Xpin, pub plus: plus::Coordinate, - pub sky_vector: sky_vector::Coordinate, + pub ddmmss: ddmmss::Coordinate, } impl TryFrom for Coordinates { @@ -40,7 +40,7 @@ impl TryFrom for Coordinates { dmm: dmm::Coordinate::from(latlon), utm: utm::Coordinate::try_from(latlon)?, plus: plus::Coordinate::try_from(latlon)?, - sky_vector: sky_vector::Coordinate::from(latlon), + ddmmss: ddmmss::Coordinate::from(latlon), }) } } diff --git a/spatial-coordinate-systems/src/sky_vector.rs b/spatial-coordinate-systems/src/ddmmss.rs similarity index 84% rename from spatial-coordinate-systems/src/sky_vector.rs rename to spatial-coordinate-systems/src/ddmmss.rs index 2cb055a..a0635fb 100644 --- a/spatial-coordinate-systems/src/sky_vector.rs +++ b/spatial-coordinate-systems/src/ddmmss.rs @@ -1,7 +1,7 @@ use crate::{ common::parse_direction, dms::{self, DMS}, - Direction, Error, LatLon, + Error, LatLon, }; use nom::{ bytes::complete::take, @@ -51,29 +51,11 @@ impl Coordinate { let dms = dms::Coordinate::from_components(lat, lon)?; let latlon = LatLon::from(&dms); - // let lat = Self::dms_to_f64_helper(lat_d, lat_m, lat_s, &lat_direction); - // let lon = Self::dms_to_f64_helper(lon_d, lon_m, lon_s, &lon_direction); - - // let latlon = DMS {}; - // LatLon::new(lat, lon)?; Ok(Coordinate(Self::latlon_to_string(&latlon), latlon)) }, )(i) } - /// Helper to convert u8, Option, Option into an f64 - // fn dms_to_f64_helper(d: u8, m: Option, s: Option, direction: &Direction) -> f64 { - - // (d as f64 - // + m.map(|m| m as f64 / 100.0_f64).unwrap_or(0.0_f64) - // + s.map(|s| s as f64 / 10_000.0_f64).unwrap_or(0.0_f64)) - // * if direction.is_positive() { - // 1.0_f64 - // } else { - // -1.0_f64 - // } - // } - /// Takes n digits from the input and parses it as a u8 fn parse_n_digits(i: &str) -> IResult<&str, u8> { map_parser(take(C), complete::u8)(i) @@ -87,16 +69,16 @@ impl Coordinate { "{:02.0}{:02.0}{:02.0}{}{:03.0}{:02.0}{:02.0}{}", lat.degrees, lat.minutes, - lat.seconds.trunc(), + lat.seconds.round(), lat.direction, lon.degrees, lon.minutes, - lon.seconds.trunc(), + lon.seconds.round(), lon.direction, ) } - pub fn get_sky_vector(&self) -> &str { + pub fn get_ddmmss(&self) -> &str { &self.0 } } diff --git a/spatial-coordinate-systems/src/lib.rs b/spatial-coordinate-systems/src/lib.rs index 9887a89..fe33c39 100644 --- a/spatial-coordinate-systems/src/lib.rs +++ b/spatial-coordinate-systems/src/lib.rs @@ -6,7 +6,7 @@ pub mod dmm; pub mod dms; pub mod latlon; pub mod plus; -pub mod sky_vector; +pub mod ddmmss; pub mod urls; pub mod utm; pub use error::Error; @@ -88,7 +88,7 @@ pub enum Coordinate { UTM(utm::Coordinate), // Xpin(xpin::Xpin), Plus(plus::Coordinate), - SkyVector(sky_vector::Coordinate), + DDMMSS(ddmmss::Coordinate), } impl Coordinate { @@ -108,7 +108,7 @@ impl Coordinate { map(dd::Coordinate::parse, Coordinate::DD), // map(xpin::Coordinate::parse, Cordinate::Xpin), map(plus::Coordinate::parse, Coordinate::Plus), - map(sky_vector::Coordinate::parse, Coordinate::SkyVector), + map(ddmmss::Coordinate::parse, Coordinate::DDMMSS), // Try to parse as a URL last map(urls::CoordinateUrls::parse, |coordinate_urls| { Coordinate::DD(dd::Coordinate::from(coordinate_urls.latlon)) @@ -130,7 +130,7 @@ impl Coordinate { CoordinateType::DMM => Self::DMM(dmm::Coordinate::from(lat_lon)), CoordinateType::UTM => Self::UTM(utm::Coordinate::try_from(lat_lon)?), CoordinateType::Plus => Self::Plus(plus::Coordinate::try_from(lat_lon)?), - CoordinateType::SkyVector => Self::SkyVector(sky_vector::Coordinate::from(lat_lon)), + CoordinateType::DDMMSS => Self::DDMMSS(ddmmss::Coordinate::from(lat_lon)), }) } @@ -142,7 +142,7 @@ impl Coordinate { Self::UTM(_) => CoordinateType::UTM, // Self::Xpin(_) => CoordinateType::Xpin, Self::Plus(_) => CoordinateType::Plus, - Self::SkyVector(_) => CoordinateType::SkyVector, + Self::DDMMSS(_) => CoordinateType::DDMMSS, } } } @@ -162,7 +162,7 @@ impl From<&Coordinate> for LatLon { Coordinate::UTM(utm) => utm.into(), // Coordinate::Xpin(xpin) => xpin.into(), Coordinate::Plus(plus) => plus.into(), - Coordinate::SkyVector(sky_vector) => sky_vector.into(), + Coordinate::DDMMSS(ddmmss) => ddmmss.into(), } } } @@ -206,9 +206,9 @@ impl From for Coordinate { Self::Plus(c) } } -impl From for Coordinate { - fn from(c: sky_vector::Coordinate) -> Self { - Self::SkyVector(c) +impl From for Coordinate { + fn from(c: ddmmss::Coordinate) -> Self { + Self::DDMMSS(c) } } @@ -245,7 +245,7 @@ impl fmt::Display for Coordinate { Coordinate::DMS(dms) => write!(f, "{}", dms), Coordinate::UTM(utm) => write!(f, "{}", utm), Coordinate::Plus(plus) => write!(f, "{}", plus), - Coordinate::SkyVector(sky_vector) => write!(f, "{}", sky_vector), + Coordinate::DDMMSS(ddmmss) => write!(f, "{}", ddmmss), } } } diff --git a/src/lib.rs b/src/lib.rs index 0ce58f7..bd12fad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,8 @@ #![allow(clippy::module_name_repetitions)] pub mod v0; -pub mod wide; +// TODO: Add wide support +// pub mod wide; use conversions::lat_lon_to_cellid; pub use s2::s1::angle::Angle; use std::{ diff --git a/xpin-wasm/src/lib.rs b/xpin-wasm/src/lib.rs index c23c68e..9a9216d 100644 --- a/xpin-wasm/src/lib.rs +++ b/xpin-wasm/src/lib.rs @@ -74,8 +74,8 @@ pub struct Coordinates { // pub xpin: String, #[wasm_bindgen(js_name = "Plus")] pub plus: String, - #[wasm_bindgen(js_name = "SkyVector")] - pub sky_vector: String, + #[wasm_bindgen(js_name = "DDMMSS")] + pub ddmmss: String, } impl From<&spatial_coordinate_systems::all::Coordinates> for Coordinates { @@ -86,7 +86,7 @@ impl From<&spatial_coordinate_systems::all::Coordinates> for Coordinates { dmm: value.dmm.to_string(), utm: value.utm.to_string(), plus: value.plus.to_string(), - sky_vector: value.sky_vector.to_string(), + ddmmss: value.ddmmss.to_string(), } } }