s2json_core/geometry/
mod.rs

1/// BBox and BBox3D shapes and utilities
2pub mod bbox;
3/// Impls that we want to hide to make the code more readable
4pub mod impls;
5/// Primitive geometry types (used by GeoJSON spec)
6pub mod primitive;
7/// Vector geometry types (used by the s2json spec for both WGS84 and S2Geometry)
8pub mod vector;
9/// The VectorPoint struct is a powerful tool for 2D and 3D points
10pub mod vector_point;
11
12use crate::Face;
13pub use bbox::*;
14pub use primitive::*;
15use serde::{Deserialize, Serialize};
16pub use vector::*;
17pub use vector_point::*;
18
19/// Trait to extract the x and y values
20pub trait GetXY {
21    /// Returns the x value
22    fn x(&self) -> f64;
23    /// Returns the y value
24    fn y(&self) -> f64;
25}
26/// Trait to extract the z value
27pub trait GetZ {
28    /// Returns the z value
29    fn z(&self) -> Option<f64>;
30}
31/// Trait to extract the m value
32pub trait GetM<M> {
33    /// Returns the m value
34    fn m(&self) -> Option<&M>;
35}
36
37/// Composite Trait: XY + Z
38pub trait GetXYZ: GetXY + GetZ {}
39/// Composite Trait: XY + M
40pub trait GetXYM<M>: GetXY + GetM<M> {}
41/// Composite Trait: XY + Z + M
42pub trait GetXYZM<M>: GetXY + GetZ + GetM<M> {}
43
44/// Trait to set the x and y values
45pub trait SetXY {
46    /// Set the x value
47    fn set_x(&mut self, x: f64);
48    /// Set the y value
49    fn set_y(&mut self, y: f64);
50    /// Set both x and y
51    fn set_xy(&mut self, x: f64, y: f64) {
52        self.set_x(x);
53        self.set_y(y);
54    }
55}
56/// Trait to set the z value
57pub trait SetZ {
58    /// Set the z value
59    fn set_z(&mut self, z: f64);
60}
61/// Trait to set the m value
62pub trait SetM<M> {
63    /// Set the m value
64    fn set_m(&mut self, m: M);
65}
66
67/// Composite Trait: XY + Z
68pub trait SetXYZ: SetXY + SetZ {
69    /// Set x, y and z
70    fn set_xyz(&mut self, x: f64, y: f64, z: f64) {
71        self.set_xy(x, y);
72        self.set_z(z);
73    }
74}
75/// Composite Trait: XY + M
76pub trait SetXYM<M>: SetXY + SetM<M> {
77    /// Set x, y and m
78    fn set_xym(&mut self, x: f64, y: f64, m: M) {
79        self.set_xy(x, y);
80        self.set_m(m);
81    }
82}
83/// Composite Trait: XY + Z + M
84pub trait SetXYZM<M>: SetXY + SetZ + SetM<M> {
85    /// Set x, y, z and m
86    fn set_xyzm(&mut self, x: f64, y: f64, z: f64, m: M) {
87        self.set_xy(x, y);
88        self.set_z(z);
89        self.set_m(m);
90    }
91}
92
93/// Trait to create a new XY
94pub trait NewXY {
95    /// Create a new point with xy
96    fn new_xy(x: f64, y: f64) -> Self;
97}
98/// Trait to create a new XYZ
99pub trait NewXYZ {
100    /// Create a new point with xyz
101    fn new_xyz(x: f64, y: f64, z: f64) -> Self;
102}
103/// Trait to create a new XYZM
104pub trait NewXYZM<M> {
105    /// Create a new point with xyzm
106    fn new_xyzm(x: f64, y: f64, z: f64, m: M) -> Self;
107}
108
109/// The axis to apply an operation to
110#[derive(Debug, PartialEq, Eq, Clone, Copy)]
111pub enum Axis {
112    /// X axis
113    X = 0,
114    /// Y axis
115    Y = 1,
116}
117
118/// A Point in S2 Space with a Face
119#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
120pub struct STPoint<M> {
121    /// The face of the point
122    pub face: Face,
123    /// The s coordinate
124    pub s: f64,
125    /// The t coordinate
126    pub t: f64,
127    /// The z coordinate
128    pub z: Option<f64>,
129    /// The m coordinate
130    pub m: Option<M>,
131}