jgdtrans/mesh.rs
1//! Provides utilities handling mesh.
2//!
3//! We note that [`MeshCoord`] supports non-negative latitude and longitude only.
4//! Therefore, [`MeshNode`] and [`MeshCell`] have the same restriction of [`MeshCoord`].
5//!
6//! The third digit of [`MeshCoord`] depends on mesh.
7//! If the mesh unit is [`MeshUnit::Five`], it takes 0 or 5 only.
8//! Hence, the methods/operations that relate with [`MeshCoord`] returns [`Err`],
9//! if [`MeshUnit::Five`] is given even though the third digit is neither 0 nor 5,
10//! in general.
11use std::error::Error;
12use std::fmt::{Display, Formatter};
13
14pub use cell::MeshCell;
15pub(crate) use code::MeshCode;
16pub use coord::MeshCoord;
17pub use node::MeshNode;
18pub use unit::MeshUnit;
19
20mod cell;
21mod code;
22mod coord;
23mod node;
24mod unit;
25
26/// Returns `ture` when `meshcode` is valid.
27///
28/// # Example
29///
30/// ```
31/// # use jgdtrans::mesh::*;
32/// #
33/// assert_eq!(is_meshcode(&54401027), true);
34/// assert_eq!(is_meshcode(&10900000), false);
35/// assert_eq!(is_meshcode(&100000000), false);
36/// ```
37#[inline]
38#[must_use]
39pub const fn is_meshcode(meshcode: &u32) -> bool {
40 MeshNode::try_from_meshcode(meshcode).is_some()
41}
42
43//
44// Error
45//
46
47/// An error on the [`TryFrom`] trait of [`mesh`](mod@self) module.
48#[derive(Debug, PartialEq, Eq)]
49pub struct MeshTryFromError;
50
51impl MeshTryFromError {
52 #[cold]
53 const fn new() -> Self {
54 Self {}
55 }
56}
57
58impl Error for MeshTryFromError {}
59
60impl Display for MeshTryFromError {
61 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
62 f.write_str("the value would be out-of-bounds of the output")
63 }
64}