From 357158683f27fbce2f9c54e19ef9519c3c04e2be Mon Sep 17 00:00:00 2001 From: p4ken Date: Wed, 3 Jul 2024 09:23:12 +0900 Subject: [PATCH] neo --- src/neo10.rs | 81 +++++++++++++++++++++++++++++++++++++++++++--------- src/neo4.rs | 2 ++ 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/neo10.rs b/src/neo10.rs index ce46fd3..862123a 100644 --- a/src/neo10.rs +++ b/src/neo10.rs @@ -1,26 +1,81 @@ #![allow(unused)] -struct Tokyo {} -impl Tokyo { - fn new(degrees: LatLon) -> Self { - todo!() +pub mod jgd { + use std::ops::{Div, Mul}; + + pub struct Tokyo {} + impl Tokyo { + pub fn new(degrees: LatLon) -> Self { + todo!() + } + pub fn to_jgd2000(&self) -> Self { + todo!() + } + pub fn to_jgd2011(&self) -> Self { + todo!() + } + pub fn degrees(&self) -> LatLon { + todo!() + } + } + + pub mod degree { + /// 1度あたりの秒。 + pub const SECOND: f64 = 3_600.; + + /// 1度あたりのミリ秒。 + pub const MILLI_SECOND: f64 = 3_600_000.; + } + + /// 緯度と経度のペア。 + pub struct LatLon(pub T, pub T); + impl LatLon { + pub fn new>(lat: T, lon: T) -> Self { + todo!() + } + // pub fn from_secs(lat: T, lon: T) -> Self { + // todo!() + // } + // pub fn to_secs(self) -> LatLon { + // todo!() + // } } - fn to_jgd2000(&self) -> Self { - todo!() + impl> LatLon { + // pub fn round(self) -> LatLon { + // todo!() + // } + pub fn map>(self, f: impl Fn(T) -> U) -> LatLon { + todo!() + } } - fn to_jgd2011(&self) -> Self { - todo!() + impl Mul for LatLon { + type Output = LatLon; + fn mul(self, rhs: f64) -> Self::Output { + todo!() + } } - fn into_inner(&self) -> LatLon { - todo!() + impl Div for LatLon { + type Output = LatLon; + fn div(self, rhs: f64) -> Self::Output { + todo!() + } } } -struct LatLon(f64, f64); - +#[cfg(test)] fn usage() { + use std::ops::Mul; + + use jgd::{degree::MILLI_SECOND, LatLon, Tokyo}; + let LatLon(lat, lon) = Tokyo::new(LatLon(0., 0.)) .to_jgd2000() .to_jgd2011() - .into_inner(); // 微妙〜 + .degrees(); + + let LatLon(lat, lon) = Tokyo::new(LatLon::new(0, 0) / MILLI_SECOND) + .to_jgd2000() + .to_jgd2011() + .degrees() + .map(|x| (x * MILLI_SECOND).round() as i32); } diff --git a/src/neo4.rs b/src/neo4.rs index ed8f7e4..89a052e 100644 --- a/src/neo4.rs +++ b/src/neo4.rs @@ -30,4 +30,6 @@ pub fn usage() { .to_jgd2000() .to_jgd2011() .degrees(); + + TOKYO.ToJgd2000().ToJgd2011().transform(LatLon(0., 0.)); }