open_vector_tile/
geometry.rs1use alloc::vec::Vec;
2use core::cmp::Ordering;
3use s2json::{LineStringMValues, MValue};
4
5#[derive(Debug, Clone, PartialEq)]
8pub struct Point {
9 pub x: i32,
11 pub y: i32,
13 pub m: Option<MValue>,
15}
16impl Point {
17 pub fn new(x: i32, y: i32) -> Point {
19 Point { x, y, m: None }
20 }
21
22 pub fn new_with_m(x: i32, y: i32, m: MValue) -> Point {
24 Point { x, y, m: Some(m) }
25 }
26}
27impl PartialOrd for Point {
28 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
29 Some(core::cmp::Ord::cmp(self, other))
31 }
32}
33impl Eq for Point {}
34impl Ord for Point {
35 fn cmp(&self, other: &Self) -> Ordering {
36 self.x.cmp(&other.x).then(self.y.cmp(&other.y))
38 }
39}
40#[derive(Debug, Clone, PartialEq)]
43pub struct Point3D {
44 pub x: i32,
46 pub y: i32,
48 pub z: i32,
50 pub m: Option<MValue>,
52}
53impl Point3D {
54 pub fn new(x: i32, y: i32, z: i32) -> Point3D {
56 Point3D { x, y, z, m: None }
57 }
58
59 pub fn new_with_m(x: i32, y: i32, z: i32, m: MValue) -> Point3D {
61 Point3D { x, y, z, m: Some(m) }
62 }
63}
64impl PartialOrd for Point3D {
65 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
66 Some(core::cmp::Ord::cmp(self, other))
68 }
69}
70impl Eq for Point3D {}
71impl Ord for Point3D {
72 fn cmp(&self, other: &Self) -> Ordering {
73 self.x.cmp(&other.x).then(self.y.cmp(&other.y)).then(self.z.cmp(&other.z))
75 }
76}
77
78#[derive(Debug, Clone, PartialEq)]
80pub struct VectorLineWithOffset {
81 pub offset: f64,
83 pub geometry: VectorLine,
85}
86impl From<&[Point]> for VectorLineWithOffset {
87 fn from(p: &[Point]) -> Self {
88 Self { offset: 0.0, geometry: p.to_vec() }
89 }
90}
91impl VectorLineWithOffset {
92 pub fn new(offset: f64, geometry: VectorLine) -> Self {
94 Self { offset, geometry }
95 }
96
97 pub fn has_offset(&self) -> bool {
99 self.offset != 0.0
100 }
101
102 pub fn has_m_values(&self) -> bool {
104 self.geometry.iter().any(|p| p.m.is_some())
105 }
106
107 pub fn m_values(&self) -> Option<LineStringMValues> {
109 if !self.has_m_values() {
110 return None;
111 }
112 Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
113 }
114}
115pub type VectorLinesWithOffset = Vec<VectorLineWithOffset>;
117
118#[derive(Debug, Clone, PartialEq)]
120pub struct VectorLine3DWithOffset {
121 pub offset: f64,
123 pub geometry: VectorLine3D,
125}
126impl VectorLine3DWithOffset {
127 pub fn new(offset: f64, geometry: VectorLine3D) -> Self {
129 Self { offset, geometry }
130 }
131
132 pub fn has_offset(&self) -> bool {
134 self.offset != 0.0
135 }
136
137 pub fn has_m_values(&self) -> bool {
139 self.geometry.iter().any(|p| p.m.is_some())
140 }
141
142 pub fn m_values(&self) -> Option<LineStringMValues> {
144 if !self.has_m_values() {
145 return None;
146 }
147 Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
148 }
149}
150pub type VectorLines3DWithOffset = Vec<VectorLine3DWithOffset>;
152
153pub type VectorPoints = Vec<Point>;
155pub type VectorPoints3D = Vec<Point3D>;
157pub type VectorLine = Vec<Point>;
159pub type VectorLine3D = Vec<Point3D>;
161pub type VectorLines = Vec<VectorLine>;
163pub type VectorLines3D = Vec<VectorLine3D>;
165pub type VectorPoly = Vec<VectorLine>;
167pub type VectorPoly3D = Vec<VectorLine3D>;
169pub type VectorMultiPoly = Vec<VectorPoly>;
171pub type VectorMultiPoly3D = Vec<VectorPoly3D>;
173#[derive(Debug, Clone, PartialEq)]
175pub enum VectorGeometry {
176 VectorPoints(VectorPoints),
178 VectorLines(VectorLinesWithOffset),
180 VectorPolys(Vec<VectorLinesWithOffset>),
182 VectorPoints3D(VectorPoints3D),
184 VectorLines3D(VectorLines3DWithOffset),
186 VectorPolys3D(Vec<VectorLines3DWithOffset>),
188}