Skip to content

Commit

Permalink
Bugfix: mesh3 starts from 100°E
Browse files Browse the repository at this point in the history
  • Loading branch information
p4ken committed Jun 14, 2024
1 parent 2fe83bd commit 957567c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target/
/Cargo.lock
/par/*.log
/par/*.par
/par/*.zip
2 changes: 1 addition & 1 deletion par/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
all: TKY2JGD.in touhokutaiheiyouoki2011.in

%.in: %.par
cargo run --package conv < $*.par > $*.in
cargo run --package conv < $*.par > $*.in 2> $*.in.log

%.par: %.zip
unzip -p $*.zip > $@
Expand Down
Binary file modified par/TKY2JGD.in
Binary file not shown.
6 changes: 3 additions & 3 deletions par/conv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl FromStr for Record {
.context("grid overflowed")
}
let index_lat = to_grid_index(mesh1_lat, mesh2_lat, mesh3_lat).expect("lat");
let index_lon = to_grid_index(mesh1_lon, mesh2_lon, mesh3_lon).expect("lon");
let index_lon = to_grid_index(mesh1_lon + 100, mesh2_lon, mesh3_lon).expect("lon");

fn parse_diff(line: &mut &str) -> anyhow::Result<i32> {
let d_integer = parse_number(line, 4)?;
Expand All @@ -89,8 +89,8 @@ impl FromStr for Record {
}
impl Display for Record {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = format!("{:04},{:04},{:09},{:09}", self.0, self.1, self.2, self.3);
assert_eq!(s.len(), 29, "{}", s);
let s = format!("{:05},{:05},{:09},{:09}", self.0, self.1, self.2, self.3);
assert_eq!(s.len(), 31, "{}", s);
f.write_str(&s)
}
}
Expand Down
Binary file modified par/touhokutaiheiyouoki2011.in
Binary file not shown.
31 changes: 2 additions & 29 deletions src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ impl LatLon {
self
}
}
impl From<LonLat> for LatLon {
fn from(LonLat(lon, lat): LonLat) -> Self {
Self(lat, lon)
}
}
impl Add<LatLon> for LatLon {
type Output = Self;
fn add(self, rhs: LatLon) -> Self::Output {
Expand All @@ -86,32 +81,10 @@ impl Mul<f64> for LatLon {
}
}
impl From<LatLon> for (f64, f64) {
fn from(value: LatLon) -> Self {
todo!()
}
}

/// 度単位の経度と緯度のペア。
/// Longitude and latitude in degrees.
#[derive(Debug, Clone, Copy)]
pub struct LonLat(f64, f64);
impl LonLat {
pub fn new(lonlat: impl Into<(f64, f64)>) -> Self {
let (lon, lat) = lonlat.into();
Self(lon, lat)
fn from(LatLon(lat, lon): LatLon) -> Self {
(lat, lon)
}
}
// impl From<LatLon> for LonLat {
// fn from(LatLon(lat, lon): LatLon) -> Self {
// Self(lon, lat)
// }
// }
// impl<T: Into<(f64, f64)>> From<T> for LonLat {
// fn from(lonlat: T) -> Self {
// let (lon, lat) = lonlat.into();
// Self(lon, lat)
// }
// }

pub struct ECEF {}
impl ECEF {
Expand Down
3 changes: 2 additions & 1 deletion src/crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ impl Jgd2000 {
/// ただし、今後のバージョンアップで他のいくつかの地殻変動分を追加する可能性がある。
/// いずれにしても ...
pub fn to_jgd2011(&self) -> Jgd2011 {
todo!()
// todo
Jgd2011::new(self.lat_lon)
}

/// [`TKY2JGD`] を用いて [`Tokyo`] へ逆変換する。
Expand Down
9 changes: 5 additions & 4 deletions src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl Mesh3 {
fn floor(degree: LatLon) -> Self {
// "saturating cast" since Rust 1.45.0
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#fixing-unsoundness-in-casts
let lat = (degree.lat() / 120.) as i16;
let lon = (degree.lon() / 80.) as i16;
let lat = (degree.lat() * 120.) as i16;
let lon = (degree.lon() * 80.) as i16;
Self { lat, lon }
}
fn diagonal_weight(self, p: LatLon) -> LatLon {
Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {

let r = records.last().unwrap();
assert_eq!(r.mesh.lat, 5463);
assert_eq!(r.mesh.lon, 3356);
assert_eq!(r.mesh.lon, 11356);
assert_eq!(r.shift.lat, 7875320);
assert_eq!(r.shift.lon, -13995610);
}
Expand Down Expand Up @@ -180,8 +180,9 @@ mod tests {
#[test]
fn grid_interpolate_middle() {
let sut = Grid::new(&SMALLEST);
let exp = LatLon::from_micro_secs(-2, 2);
let ret = sut.interpolate(LatLon::from_secs(10., 15.)).unwrap();
let diff = (ret - LatLon::from_micro_secs(-2, 2)).abs();
let diff = (ret - exp).abs();
assert!(diff.lat() < MILLI_METER_IN_DEGREES);
assert!(diff.lon() < MILLI_METER_IN_DEGREES);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//!
//! 旧日本測地系 [`Tokyo`] の北緯35度・東経135度を、世界測地系 [`Jgd2011`] に変換する例。
//!
//! ```no_run
//! ```
//! # #[cfg(all(feature = "tky2jgd", feature = "patchjgd"))]
//! let (lat, lon) = jgd::from_tokyo(35.0, 135.0)
//! .to_jgd2000()
Expand All @@ -20,7 +20,7 @@
//!
//! [`geo`](https://docs.rs/geo/latest/geo/index.html#types) クレートの測地系を変換する例。
//!
//! ```no_run
//! ```
//! use geo::{Coord, LineString, MapCoords};
//!
//! let tokyo_datum = LineString::from(vec![(135.0, 35.0), (135.1, 35.1)]);
Expand Down Expand Up @@ -62,7 +62,7 @@ mod grid;
mod island;
mod par;

use coord::{LatLon, LonLat};
use coord::LatLon;
pub use crs::{
from_jgd2000, from_jgd2011, from_tokyo, from_tokyo97, Jgd2000, Jgd2011, Tokyo, Tokyo97,
};
Expand Down
8 changes: 8 additions & 0 deletions tests/transform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(all(feature = "tky2jgd", feature = "patchjgd"))]
#[test]
fn tokyo_to_jgd2011() {
let (lat, lon) = jgd::from_tokyo(35.0, 135.0)
.to_jgd2000()
.to_jgd2011()
.lat_lon();
}

0 comments on commit 957567c

Please sign in to comment.