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/// Trait to extract the x and y values
19pub trait GetXY {
20    /// Returns the x value
21    fn x(&self) -> f64;
22    /// Returns the y value
23    fn y(&self) -> f64;
24}
25/// Trait to extract the z value
26pub trait GetZ {
27    /// Returns the z value
28    fn z(&self) -> Option<f64>;
29}
30/// Trait to extract the m value
31pub trait GetM<M> {
32    /// Returns the m value
33    fn m(&self) -> Option<&M>;
34}
35
36/// Composite Trait: XY + Z
37pub trait GetXYZ: GetXY + GetZ {}
38/// Composite Trait: XY + M
39pub trait GetXYM<M>: GetXY + GetM<M> {}
40/// Composite Trait: XY + Z + M
41pub trait GetXYZM<M>: GetXY + GetZ + GetM<M> {}
42
43/// Trait to set the x and y values
44pub trait SetXY {
45    /// Set the x value
46    fn set_x(&mut self, x: f64);
47    /// Set the y value
48    fn set_y(&mut self, y: f64);
49    /// Set both x and y
50    fn set_xy(&mut self, x: f64, y: f64) {
51        self.set_x(x);
52        self.set_y(y);
53    }
54}
55/// Trait to set the z value
56pub trait SetZ {
57    /// Set the z value
58    fn set_z(&mut self, z: f64);
59}
60/// Trait to set the m value
61pub trait SetM<M> {
62    /// Set the m value
63    fn set_m(&mut self, m: M);
64}
65
66/// Composite Trait: XY + Z
67pub trait SetXYZ: SetXY + SetZ {
68    /// Set x, y and z
69    fn set_xyz(&mut self, x: f64, y: f64, z: f64) {
70        self.set_xy(x, y);
71        self.set_z(z);
72    }
73}
74/// Composite Trait: XY + M
75pub trait SetXYM<M>: SetXY + SetM<M> {
76    /// Set x, y and m
77    fn set_xym(&mut self, x: f64, y: f64, m: M) {
78        self.set_xy(x, y);
79        self.set_m(m);
80    }
81}
82/// Composite Trait: XY + Z + M
83pub trait SetXYZM<M>: SetXY + SetZ + SetM<M> {
84    /// Set x, y, z and m
85    fn set_xyzm(&mut self, x: f64, y: f64, z: f64, m: M) {
86        self.set_xy(x, y);
87        self.set_z(z);
88        self.set_m(m);
89    }
90}
91
92/// Trait to create a new XY
93pub trait NewXY {
94    /// Create a new point with xy
95    fn new_xy(x: f64, y: f64) -> Self;
96}
97/// Trait to create a new XYZ
98pub trait NewXYZ {
99    /// Create a new point with xyz
100    fn new_xyz(x: f64, y: f64, z: f64) -> Self;
101}
102/// Trait to create a new XYZM
103pub trait NewXYZM<M> {
104    /// Create a new point with xyzm
105    fn new_xyzm(x: f64, y: f64, z: f64, m: M) -> Self;
106}
107
108/// The axis to apply an operation to
109#[derive(Debug, PartialEq, Eq, Clone, Copy)]
110pub enum Axis {
111    /// X axis
112    X = 0,
113    /// Y axis
114    Y = 1,
115}
116
117/// A Point in S2 Space with a Face
118#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
119pub struct STPoint<M> {
120    /// The face of the point
121    pub face: Face,
122    /// The s coordinate
123    pub s: f64,
124    /// The t coordinate
125    pub t: f64,
126    /// The z coordinate
127    pub z: Option<f64>,
128    /// The m coordinate
129    pub m: Option<M>,
130}