From 0742b12f70fed454243c420464767a8e6d7743aa Mon Sep 17 00:00:00 2001 From: David Marteau Date: Wed, 8 Jan 2025 00:27:18 +0100 Subject: [PATCH] Allow 3d inputs in examples/proj4rs --- .gitignore | 2 ++ proj4rs-clib/Makefile.toml | 7 ++++++- proj4rs/CHANGELOG.md | 3 +++ proj4rs/examples/rsproj.rs | 11 ++++++++--- proj4rs/src/adaptors.rs | 8 ++++---- proj4rs/src/parameters.rs | 2 +- proj4rs/src/projections/eqc.rs | 13 +++++-------- proj4rs/src/projections/geos.rs | 2 +- proj4rs/src/transform.rs | 2 +- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 4ce03dd..d08fa27 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ Cargo.lock /target .idea/ + +__pycache__ diff --git a/proj4rs-clib/Makefile.toml b/proj4rs-clib/Makefile.toml index 536938b..a94d27d 100644 --- a/proj4rs-clib/Makefile.toml +++ b/proj4rs-clib/Makefile.toml @@ -47,6 +47,11 @@ args = [ ] +[tasks."python.build-dev"] +command = "maturin" +args = ["develop"] + + [tasks."python.lint-fix"] command = "ruff" args = [ @@ -65,4 +70,4 @@ args = ["python"] [tasks."python.test"] command = "pytest" args = [ "-v", "python/tests"] -dependencies = ["python.lint", "python.typing"] +dependencies = ["python.build-dev", "python.lint", "python.typing"] diff --git a/proj4rs/CHANGELOG.md b/proj4rs/CHANGELOG.md index 5b74421..60eef72 100644 --- a/proj4rs/CHANGELOG.md +++ b/proj4rs/CHANGELOG.md @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this ## Unreleased +### Changed +* Allow 3d inputs in examples/proj4rs + ### Added * Added 'eqc' projection diff --git a/proj4rs/examples/rsproj.rs b/proj4rs/examples/rsproj.rs index 3e41183..f0b93ad 100644 --- a/proj4rs/examples/rsproj.rs +++ b/proj4rs/examples/rsproj.rs @@ -58,15 +58,20 @@ fn main() -> Result<()> { for line in stdin.lines() { let line = line.unwrap(); let inputs = line.as_str().split_whitespace().collect::>(); - if inputs.len() != 2 { - eprintln!("Expecting: ' ,' found: {}", line.as_str()); + if inputs.len() < 2 || inputs.len() > 3 { + eprintln!("Expecting: ' , [,]' found: {}", line.as_str()); std::process::exit(1); } let x: f64 = inputs[0].parse().map_err(from_parse_err)?; let y: f64 = inputs[1].parse().map_err(from_parse_err)?; + let z: f64 = if inputs.len() > 2 { + inputs[2].parse().map_err(from_parse_err)? + } else { + 0. + }; - let mut point = (x, y, 0.); + let mut point = (x, y, z); if src.is_latlong() { point.0 = point.0.to_radians(); diff --git a/proj4rs/src/adaptors.rs b/proj4rs/src/adaptors.rs index 6586f3f..be76654 100644 --- a/proj4rs/src/adaptors.rs +++ b/proj4rs/src/adaptors.rs @@ -36,7 +36,7 @@ impl Transform for (f64, f64) { /// /// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap(); /// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap(); - +/// /// let (x, y, z) = transform_vertex_3d(&src, &dst, (2.0, 1.0, 0.0)).unwrap(); /// ``` pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Result<(f64, f64, f64)> { @@ -53,7 +53,7 @@ pub fn transform_vertex_3d(src: &Proj, dst: &Proj, pt: (f64, f64, f64)) -> Resul /// /// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap(); /// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap(); - +/// /// let (x, y) = transform_vertex_2d(&src, &dst, (2.0, 1.0)).unwrap(); /// ``` #[inline(always)] @@ -69,7 +69,7 @@ pub fn transform_vertex_2d(src: &Proj, dst: &Proj, pt: (f64, f64)) -> Result<(f6 /// /// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap(); /// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap(); - +/// /// let (x, y, z) = transform_xyz(&src, &dst, 2.0, 1.0, 0.0).unwrap(); /// ``` #[inline(always)] @@ -85,7 +85,7 @@ pub fn transform_xyz(src: &Proj, dst: &Proj, x: f64, y: f64, z: f64) -> Result<( /// /// let dst = Proj::from_proj_string("+proj=utm +ellps=GRS80 +zone=30").unwrap(); /// let src = Proj::from_proj_string("+proj=latlong +ellps=GRS80").unwrap(); - +/// /// let (x, y) = transform_xy(&src, &dst, 2.0, 1.0).unwrap(); /// ``` #[inline(always)] diff --git a/proj4rs/src/parameters.rs b/proj4rs/src/parameters.rs index 826a270..0d9c55b 100644 --- a/proj4rs/src/parameters.rs +++ b/proj4rs/src/parameters.rs @@ -37,7 +37,7 @@ impl<'a> TryFrom<&Parameter<'a>> for &'a str { } } -impl<'a> Parameter<'a> { +impl Parameter<'_> { fn try_value(&self) -> Result { match self.value.map(F::from_str) { None => Err(Error::NoValueParameter), diff --git a/proj4rs/src/projections/eqc.rs b/proj4rs/src/projections/eqc.rs index 4b66530..1e69264 100644 --- a/proj4rs/src/projections/eqc.rs +++ b/proj4rs/src/projections/eqc.rs @@ -51,7 +51,6 @@ impl Projection { } } - #[cfg(test)] mod tests { use crate::math::consts::EPS_10; @@ -64,9 +63,7 @@ mod tests { println!("{:#?}", p.projection()); - let inputs = [ - ((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.)), - ]; + let inputs = [((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.))]; test_proj_forward(&p, &inputs, EPS_10); test_proj_inverse(&p, &inputs, EPS_10); @@ -78,12 +75,12 @@ mod tests { println!("{:#?}", p.projection()); - let inputs = [ - ((-88., 30., 0.), (192811.01392664597, 3339584.72379820701, 0.)), - ]; + let inputs = [( + (-88., 30., 0.), + (192811.01392664597, 3339584.72379820701, 0.), + )]; test_proj_forward(&p, &inputs, EPS_10); test_proj_inverse(&p, &inputs, EPS_10); } - } diff --git a/proj4rs/src/projections/geos.rs b/proj4rs/src/projections/geos.rs index 3027ed0..6630293 100644 --- a/proj4rs/src/projections/geos.rs +++ b/proj4rs/src/projections/geos.rs @@ -49,7 +49,7 @@ impl Projection { pub fn geos(p: &mut ProjData, params: &ParamList) -> Result { let h: f64 = params .try_value("h")? - .ok_or_else(|| Error::InputStringError("Missing parameter 'h'"))?; + .ok_or(Error::InputStringError("Missing parameter 'h'"))?; let flip_axis: bool = params .try_value::<&str>("sweep") .and_then(|sweep| match sweep { diff --git a/proj4rs/src/transform.rs b/proj4rs/src/transform.rs index a70eeb6..6254edb 100644 --- a/proj4rs/src/transform.rs +++ b/proj4rs/src/transform.rs @@ -110,7 +110,7 @@ where let src_datum = src.datum(); let dst_datum = dst.datum(); - // Return true if the datums are identical is respect + // Return true if the datums are identical with respect // to datum transformation. // As of PROJ 4 behavior, we prevent datum transformation // if either the source or destination are of an unknown datum type.