s2json_core/geometry/
mod.rs1pub mod bbox;
3pub mod impls;
5pub mod interpolate;
7pub mod primitive;
9pub mod vector;
11pub mod vector_point;
13
14use crate::Face;
15pub use bbox::*;
16pub use interpolate::*;
17pub use primitive::*;
18use serde::{Deserialize, Serialize};
19pub use vector::*;
20pub use vector_point::*;
21
22pub trait GetXY {
24 fn x(&self) -> f64;
26 fn y(&self) -> f64;
28 fn xy(&self) -> (f64, f64) {
30 (self.x(), self.y())
31 }
32}
33pub trait GetZ {
35 fn z(&self) -> Option<f64>;
37}
38pub trait GetM<M> {
40 fn m(&self) -> Option<&M>;
42}
43
44pub trait GetXYZ: GetXY + GetZ {}
46impl<T> GetXYZ for T where T: GetXY + GetZ {}
47pub trait GetXYM<M>: GetXY + GetM<M> {}
49impl<T, M> GetXYM<M> for T where T: GetXY + GetM<M> {}
50pub trait GetXYZM<M>: GetXY + GetZ + GetM<M> {}
52impl<T, M> GetXYZM<M> for T where T: GetXY + GetZ + GetM<M> {}
53
54pub trait SetXY {
56 fn set_x(&mut self, x: f64);
58 fn set_y(&mut self, y: f64);
60 fn set_xy(&mut self, x: f64, y: f64) {
62 self.set_x(x);
63 self.set_y(y);
64 }
65}
66pub trait SetZ {
68 fn set_z(&mut self, z: f64);
70}
71pub trait SetM<M> {
73 fn set_m(&mut self, m: M);
75}
76
77pub trait SetXYZ: SetXY + SetZ {
79 fn set_xyz(&mut self, x: f64, y: f64, z: f64) {
81 self.set_xy(x, y);
82 self.set_z(z);
83 }
84}
85impl<T> SetXYZ for T where T: SetXY + SetZ {}
86pub trait SetXYM<M>: SetXY + SetM<M> {
88 fn set_xym(&mut self, x: f64, y: f64, m: M) {
90 self.set_xy(x, y);
91 self.set_m(m);
92 }
93}
94impl<T, M> SetXYM<M> for T where T: SetXY + SetM<M> {}
95pub trait SetXYZM<M>: SetXY + SetZ + SetM<M> {
97 fn set_xyzm(&mut self, x: f64, y: f64, z: f64, m: M) {
99 self.set_xy(x, y);
100 self.set_z(z);
101 self.set_m(m);
102 }
103}
104impl<T, M> SetXYZM<M> for T where T: SetXY + SetZ + SetM<M> {}
105
106pub trait NewXY {
108 fn new_xy(x: f64, y: f64) -> Self;
110}
111pub trait NewXYM<M> {
113 fn new_xym(x: f64, y: f64, m: M) -> Self;
115}
116pub trait NewXYZ {
118 fn new_xyz(x: f64, y: f64, z: f64) -> Self;
120}
121pub trait NewXYZM<M> {
123 fn new_xyzm(x: f64, y: f64, z: f64, m: M) -> Self;
125}
126
127pub trait FullXY: GetXYZ + SetXY + NewXY + Clone + PartialEq + Ord {}
131impl<T> FullXY for T where T: GetXYZ + SetXY + NewXY + Clone + PartialEq + Ord {}
132
133pub trait FullXYZ: GetXYZ + SetXYZ + NewXYZ + Clone + PartialEq + Ord {}
135impl<T> FullXYZ for T where T: GetXYZ + SetXYZ + NewXYZ + Clone + PartialEq + Ord {}
136
137pub trait FullXYZM<M>: GetXYZM<M> + SetXYZM<M> + NewXYZM<M> + Clone + PartialEq + Ord {}
139impl<T, M> FullXYZM<M> for T where T: GetXYZM<M> + SetXYZM<M> + NewXYZM<M> + Clone + PartialEq + Ord {}
140
141#[derive(Debug, PartialEq, Eq, Clone, Copy)]
143pub enum Axis {
144 X = 0,
146 Y = 1,
148}
149
150#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
152pub struct STPoint<M> {
153 pub face: Face,
155 pub s: f64,
157 pub t: f64,
159 pub z: Option<f64>,
161 pub m: Option<M>,
163}