Skip to main content

geodesy/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// The bread-and-butter, shrink-wrapped and ready to use
4pub mod prelude {
5    pub use crate::Error;
6    pub use crate::coord::*;
7    pub use crate::ctx::*;
8    pub use crate::ellps::*;
9}
10
11/// Extended prelude for authoring Contexts and InnerOp modules
12pub mod authoring {
13    pub use crate::grd::*;
14    pub use crate::math::*;
15    pub use crate::ops::*;
16    pub use crate::parse::*;
17    pub use crate::prelude::*;
18
19    // All new contexts are supposed to support these
20    pub use crate::context::BUILTIN_ADAPTORS;
21
22    // Map projection characteristics
23    pub use crate::math::jacobian::Factors;
24    pub use crate::math::jacobian::Jacobian;
25
26    // External material
27    pub use log::debug;
28    pub use log::error;
29    pub use log::info;
30    pub use log::trace;
31    pub use log::warn;
32    pub use std::collections::BTreeMap;
33}
34
35/// Context related elements
36pub mod ctx {
37    pub use crate::Direction;
38    pub use crate::Direction::Fwd;
39    pub use crate::Direction::Inv;
40    pub use crate::context::Context;
41    pub use crate::context::OpHandle;
42    pub use crate::context::minimal::Minimal;
43    #[cfg(feature = "with_plain")]
44    pub use crate::context::plain::Plain;
45}
46
47/// Ellipsoid related elements
48pub mod ellps {
49    pub use crate::ellipsoid::EllipsoidBase;
50    pub use crate::ellipsoid::biaxial::Ellipsoid;
51    pub use crate::ellipsoid::geocart::GeoCart;
52    pub use crate::ellipsoid::geodesics::Geodesics;
53    pub use crate::ellipsoid::gravity::Gravity;
54    pub use crate::ellipsoid::latitudes::Latitudes;
55    pub use crate::ellipsoid::meridians::Meridians;
56    pub use crate::ellipsoid::triaxial::TriaxialEllipsoid;
57}
58
59/// Coordinate related elements
60pub mod coord {
61    // Coordinate types
62    pub use crate::coordinate::coor2d::Coor2D;
63    pub use crate::coordinate::coor3d::Coor3D;
64    pub use crate::coordinate::coor4d::Coor4D;
65    pub use crate::coordinate::coor32::Coor32;
66    // Coordinate traits
67    pub use crate::coordinate::AngularUnits;
68    pub use crate::coordinate::CoordinateMetadata;
69    pub use crate::coordinate::set::CoordinateSet;
70    pub use crate::coordinate::tuple::CoordinateTuple;
71    pub use crate::math::angular;
72}
73
74/// Elements for building operators
75mod ops {
76    pub use crate::inner_op::InnerOp;
77    pub use crate::inner_op::OpConstructor;
78    pub use crate::op::Op;
79    pub use crate::op::OpDescriptor;
80    pub use crate::op::OpParameter;
81    pub use crate::op::ParsedParameters;
82    pub use crate::op::RawParameters;
83}
84
85/// Elements for handling grids
86pub mod grd {
87    pub use crate::grid::BaseGrid;
88    pub use crate::grid::Grid;
89    pub use crate::grid::GridHeader;
90    pub use crate::grid::GridSource;
91    pub use crate::grid::gravsoft;
92    pub use crate::grid::grids_at;
93    pub use crate::grid::read_grid;
94    pub use crate::grid::unigrid::read_unigrid_index;
95}
96
97/// Elements for parsing both Geodesy and PROJ syntax
98mod parse {
99    // Tokenizing Rust Geodesy operations
100    pub use crate::token::Tokenize;
101    // PROJ interoperability
102    pub use crate::token::parse_proj;
103}
104
105use thiserror::Error;
106/// The *Rust Geodesy* error messaging enumeration. Badly needs reconsideration
107#[derive(Error, Debug)]
108pub enum Error {
109    #[error("i/o error")]
110    Io(#[from] std::io::Error),
111
112    #[error("ParseInt error")]
113    ParseInt(#[from] std::num::ParseIntError),
114
115    #[error("General error: '{0}'")]
116    General(&'static str),
117
118    #[error("Syntax error: '{0}'")]
119    Syntax(String),
120
121    #[error("{0}: {1}")]
122    Operator(&'static str, &'static str),
123
124    #[error("Invalid header (expected {expected:?}, found {found:?})")]
125    InvalidHeader { expected: String, found: String },
126    #[error("{message:?} (expected {expected:?}, found {found:?})")]
127    Unexpected {
128        message: String,
129        expected: String,
130        found: String,
131    },
132
133    #[error("Operator '{0}' not found{1}")]
134    NotFound(String, String),
135
136    #[error("Recursion too deep for '{0}', at {1}")]
137    Recursion(String, String),
138
139    #[error("Attempt to invert a non-invertible item: '{0}'")]
140    NonInvertible(String),
141
142    #[error("Missing required parameter '{0}'")]
143    MissingParam(String),
144
145    #[error("Malformed value for parameter '{0}': '{1}'")]
146    BadParam(String, String),
147
148    #[error("Unsupported: {0}")]
149    Unsupported(String),
150
151    #[error("Invalid: {0}")]
152    Invalid(String),
153
154    #[error("UTF8 error")]
155    Utf8Error(#[from] std::str::Utf8Error),
156
157    #[error("Unknown")]
158    Unknown,
159}
160
161/// `Fwd`: Indicate that a two-way operator, function, or method,
162/// should run in the *forward* direction.
163/// `Inv`: Indicate that a two-way operator, function, or method,
164/// should run in the *inverse* direction.
165#[derive(Debug, PartialEq, Eq)]
166pub enum Direction {
167    Fwd,
168    Inv,
169}
170
171mod bibliography;
172mod context;
173mod coordinate;
174mod ellipsoid;
175mod grid;
176mod inner_op;
177mod math;
178mod op;
179mod token;
180
181/// Some generic coordinates for test composition
182#[cfg(test)]
183mod test_data {
184    pub fn coor4d() -> [crate::coord::Coor4D; 2] {
185        let copenhagen = crate::coord::Coor4D::raw(55., 12., 0., 0.);
186        let stockholm = crate::coord::Coor4D::raw(59., 18., 0., 0.);
187        [copenhagen, stockholm]
188    }
189
190    pub fn coor3d() -> [crate::coord::Coor3D; 2] {
191        let copenhagen = crate::coord::Coor3D::raw(55., 12., 0.);
192        let stockholm = crate::coord::Coor3D::raw(59., 18., 0.);
193        [copenhagen, stockholm]
194    }
195
196    pub fn coor2d() -> [crate::coord::Coor2D; 2] {
197        let copenhagen = crate::coord::Coor2D::raw(55., 12.);
198        let stockholm = crate::coord::Coor2D::raw(59., 18.);
199        [copenhagen, stockholm]
200    }
201
202    pub fn coor32() -> [crate::coord::Coor32; 2] {
203        let copenhagen = crate::coord::Coor32::raw(55., 12.);
204        let stockholm = crate::coord::Coor32::raw(59., 18.);
205        [copenhagen, stockholm]
206    }
207}
208
209// ---- Documentation: Bibliography ----
210#[cfg(doc)]
211pub use crate::bibliography::Bibliography;