Skip to content

Commit

Permalink
neo
Browse files Browse the repository at this point in the history
  • Loading branch information
p4ken committed Jun 29, 2024
1 parent 8ead580 commit 5c70d55
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/neo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl<T: From<LatLon> + Into<LatLon>> Degrees for T {
}

#[allow(unused_variables)]
#[cfg(feature = "default")]
mod tests {
use super::{jgd, Degrees, LatLon, Tokyo};

Expand Down
45 changes: 39 additions & 6 deletions src/neo5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub struct Tokyo;
impl Tokyo {
pub fn new(lat: f64, lon: f64) -> Self {
pub fn new(lat_lon: LatLon) -> Self {
Self
}
pub fn to_jgd2000(self) -> Jgd2000 {
Expand All @@ -25,11 +25,21 @@ impl Jgd2000 {
}
}
pub struct Jgd2011;
impl From<Jgd2011> for (f64, f64) {
fn from(crs: Jgd2011) -> Self {
crs.degrees()
impl Jgd2011 {
fn lat_lon(&self) -> LatLon {
LatLon(0., 0.)
}
}
// impl From<Jgd2011> for (f64, f64) {
// fn from(crs: Jgd2011) -> Self {
// crs.degrees()
// }
// }
// impl AsRef<LatLon> for Jgd2011 {
// fn as_ref(&self) -> &LatLon {
// &LatLon(0., 0.)
// }
// }
impl Degrees for Jgd2011 {
fn with_degrees(lat: f64, lon: f64) -> Self {
Self
Expand All @@ -50,13 +60,36 @@ pub trait Degrees: Sized {
self.degrees()
}
}
pub struct LatLon;
pub struct LatLon(f64, f64);
// impl Degrees for LatLon {
// fn with_degrees(lat: f64, lon: f64) -> Self {
// todo!()
// }
// fn degrees(self) -> (f64, f64) {
// todo!()
// }
// }

#[cfg(test)]
pub fn usage() {
let (lat, lon) = Tokyo::new(1., 2.).to_jgd2000().to_jgd2011().into();
use geo::Point;

// let (lat, lon) = Tokyo::new(LatLon(1., 2.))
// .to_jgd2000()
// .to_jgd2011()
// .lat_lon()
// .secs();
let (lat, lon) = Tokyo::with_degrees(1., 2.)
.to_jgd2000()
.to_jgd2011()
.degrees();

let (lat, lon) = Tokyo::with_secs(1., 2.).to_jgd2000().to_jgd2011().secs();

let mut p = Point::new(1., 2.);
let (lat, lon) = Tokyo::with_degrees(p.y(), p.x())
.to_jgd2000()
.to_jgd2011()
.degrees();
p = Point::new(lon, lat);
}
11 changes: 6 additions & 5 deletions src/neo6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Tokyo {
}
}
impl Degrees for Tokyo {
fn with_degrees(degrees: LatLon) -> Self {
fn with_degrees(degrees: impl Into<LatLon>) -> Self {
Self
}
fn degrees(&self) -> LatLon {
Expand All @@ -23,7 +23,7 @@ impl Jgd2000 {
}
pub struct Jgd2011;
impl Degrees for Jgd2011 {
fn with_degrees(degrees: LatLon) -> Self {
fn with_degrees(degrees: impl Into<LatLon>) -> Self {
Self
}
fn degrees(&self) -> LatLon {
Expand All @@ -33,7 +33,8 @@ impl Degrees for Jgd2011 {

// TODO sealed
pub trait Degrees: Sized {
fn with_degrees(degrees: LatLon) -> Self;
// TODO: Into要らないかも
fn with_degrees(degrees: impl Into<LatLon>) -> Self;
fn with_secs(secs: LatLon) -> Self {
Self::with_degrees(secs)
}
Expand All @@ -51,10 +52,10 @@ impl LatLon {
pub fn into_rev<T: From<[f64; 2]>>(&self) -> T {
[self.lon(), self.lat()].into()
}
pub fn lon(&self) -> f64 {
pub fn lat(&self) -> f64 {
self.0
}
pub fn lat(&self) -> f64 {
pub fn lon(&self) -> f64 {
self.1
}
}
Expand Down

0 comments on commit 5c70d55

Please sign in to comment.