Rename sky vector to ddmmss

This commit is contained in:
Austen Adler 2023-04-26 22:55:57 -04:00
parent e32e8e00ee
commit c9c39828a2
5 changed files with 22 additions and 39 deletions

View File

@ -7,7 +7,7 @@ use crate::{
dmm, dmm,
dms, dms,
plus, //xpin plus, //xpin
sky_vector, ddmmss,
utm, utm,
Coordinate, Coordinate,
Error, Error,
@ -26,7 +26,7 @@ pub struct Coordinates {
pub utm: utm::Coordinate, pub utm: utm::Coordinate,
// pub xpin: xpin::Xpin, // pub xpin: xpin::Xpin,
pub plus: plus::Coordinate, pub plus: plus::Coordinate,
pub sky_vector: sky_vector::Coordinate, pub ddmmss: ddmmss::Coordinate,
} }
impl TryFrom<LatLon> for Coordinates { impl TryFrom<LatLon> for Coordinates {
@ -40,7 +40,7 @@ impl TryFrom<LatLon> for Coordinates {
dmm: dmm::Coordinate::from(latlon), dmm: dmm::Coordinate::from(latlon),
utm: utm::Coordinate::try_from(latlon)?, utm: utm::Coordinate::try_from(latlon)?,
plus: plus::Coordinate::try_from(latlon)?, plus: plus::Coordinate::try_from(latlon)?,
sky_vector: sky_vector::Coordinate::from(latlon), ddmmss: ddmmss::Coordinate::from(latlon),
}) })
} }
} }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
common::parse_direction, common::parse_direction,
dms::{self, DMS}, dms::{self, DMS},
Direction, Error, LatLon, Error, LatLon,
}; };
use nom::{ use nom::{
bytes::complete::take, bytes::complete::take,
@ -51,29 +51,11 @@ impl Coordinate {
let dms = dms::Coordinate::from_components(lat, lon)?; let dms = dms::Coordinate::from_components(lat, lon)?;
let latlon = LatLon::from(&dms); 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)) Ok(Coordinate(Self::latlon_to_string(&latlon), latlon))
}, },
)(i) )(i)
} }
/// Helper to convert u8, Option<u8>, Option<u8> into an f64
// fn dms_to_f64_helper(d: u8, m: Option<u8>, s: Option<u8>, 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 /// Takes n digits from the input and parses it as a u8
fn parse_n_digits<const C: u8>(i: &str) -> IResult<&str, u8> { fn parse_n_digits<const C: u8>(i: &str) -> IResult<&str, u8> {
map_parser(take(C), complete::u8)(i) 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}{}", "{:02.0}{:02.0}{:02.0}{}{:03.0}{:02.0}{:02.0}{}",
lat.degrees, lat.degrees,
lat.minutes, lat.minutes,
lat.seconds.trunc(), lat.seconds.round(),
lat.direction, lat.direction,
lon.degrees, lon.degrees,
lon.minutes, lon.minutes,
lon.seconds.trunc(), lon.seconds.round(),
lon.direction, lon.direction,
) )
} }
pub fn get_sky_vector(&self) -> &str { pub fn get_ddmmss(&self) -> &str {
&self.0 &self.0
} }
} }

View File

@ -6,7 +6,7 @@ pub mod dmm;
pub mod dms; pub mod dms;
pub mod latlon; pub mod latlon;
pub mod plus; pub mod plus;
pub mod sky_vector; pub mod ddmmss;
pub mod urls; pub mod urls;
pub mod utm; pub mod utm;
pub use error::Error; pub use error::Error;
@ -88,7 +88,7 @@ pub enum Coordinate {
UTM(utm::Coordinate), UTM(utm::Coordinate),
// Xpin(xpin::Xpin), // Xpin(xpin::Xpin),
Plus(plus::Coordinate), Plus(plus::Coordinate),
SkyVector(sky_vector::Coordinate), DDMMSS(ddmmss::Coordinate),
} }
impl Coordinate { impl Coordinate {
@ -108,7 +108,7 @@ impl Coordinate {
map(dd::Coordinate::parse, Coordinate::DD), map(dd::Coordinate::parse, Coordinate::DD),
// map(xpin::Coordinate::parse, Cordinate::Xpin), // map(xpin::Coordinate::parse, Cordinate::Xpin),
map(plus::Coordinate::parse, Coordinate::Plus), 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 // Try to parse as a URL last
map(urls::CoordinateUrls::parse, |coordinate_urls| { map(urls::CoordinateUrls::parse, |coordinate_urls| {
Coordinate::DD(dd::Coordinate::from(coordinate_urls.latlon)) Coordinate::DD(dd::Coordinate::from(coordinate_urls.latlon))
@ -130,7 +130,7 @@ impl Coordinate {
CoordinateType::DMM => Self::DMM(dmm::Coordinate::from(lat_lon)), CoordinateType::DMM => Self::DMM(dmm::Coordinate::from(lat_lon)),
CoordinateType::UTM => Self::UTM(utm::Coordinate::try_from(lat_lon)?), CoordinateType::UTM => Self::UTM(utm::Coordinate::try_from(lat_lon)?),
CoordinateType::Plus => Self::Plus(plus::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::UTM(_) => CoordinateType::UTM,
// Self::Xpin(_) => CoordinateType::Xpin, // Self::Xpin(_) => CoordinateType::Xpin,
Self::Plus(_) => CoordinateType::Plus, 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::UTM(utm) => utm.into(),
// Coordinate::Xpin(xpin) => xpin.into(), // Coordinate::Xpin(xpin) => xpin.into(),
Coordinate::Plus(plus) => plus.into(), Coordinate::Plus(plus) => plus.into(),
Coordinate::SkyVector(sky_vector) => sky_vector.into(), Coordinate::DDMMSS(ddmmss) => ddmmss.into(),
} }
} }
} }
@ -206,9 +206,9 @@ impl From<plus::Coordinate> for Coordinate {
Self::Plus(c) Self::Plus(c)
} }
} }
impl From<sky_vector::Coordinate> for Coordinate { impl From<ddmmss::Coordinate> for Coordinate {
fn from(c: sky_vector::Coordinate) -> Self { fn from(c: ddmmss::Coordinate) -> Self {
Self::SkyVector(c) Self::DDMMSS(c)
} }
} }
@ -245,7 +245,7 @@ impl fmt::Display for Coordinate {
Coordinate::DMS(dms) => write!(f, "{}", dms), Coordinate::DMS(dms) => write!(f, "{}", dms),
Coordinate::UTM(utm) => write!(f, "{}", utm), Coordinate::UTM(utm) => write!(f, "{}", utm),
Coordinate::Plus(plus) => write!(f, "{}", plus), Coordinate::Plus(plus) => write!(f, "{}", plus),
Coordinate::SkyVector(sky_vector) => write!(f, "{}", sky_vector), Coordinate::DDMMSS(ddmmss) => write!(f, "{}", ddmmss),
} }
} }
} }

View File

@ -4,7 +4,8 @@
#![allow(clippy::module_name_repetitions)] #![allow(clippy::module_name_repetitions)]
pub mod v0; pub mod v0;
pub mod wide; // TODO: Add wide support
// pub mod wide;
use conversions::lat_lon_to_cellid; use conversions::lat_lon_to_cellid;
pub use s2::s1::angle::Angle; pub use s2::s1::angle::Angle;
use std::{ use std::{

View File

@ -74,8 +74,8 @@ pub struct Coordinates {
// pub xpin: String, // pub xpin: String,
#[wasm_bindgen(js_name = "Plus")] #[wasm_bindgen(js_name = "Plus")]
pub plus: String, pub plus: String,
#[wasm_bindgen(js_name = "SkyVector")] #[wasm_bindgen(js_name = "DDMMSS")]
pub sky_vector: String, pub ddmmss: String,
} }
impl From<&spatial_coordinate_systems::all::Coordinates> for Coordinates { 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(), dmm: value.dmm.to_string(),
utm: value.utm.to_string(), utm: value.utm.to_string(),
plus: value.plus.to_string(), plus: value.plus.to_string(),
sky_vector: value.sky_vector.to_string(), ddmmss: value.ddmmss.to_string(),
} }
} }
} }