1use crate::open::{LineStringMValues, MValue};
2
3use core::cmp::Ordering;
4
5use alloc::vec::Vec;
6
7#[derive(Default, Copy, Clone, Debug, PartialEq, PartialOrd, Eq)]
9pub struct BBox<T = f64> {
10 pub left: T,
12 pub bottom: T,
14 pub right: T,
16 pub top: T,
18}
19impl<T> BBox<T> {
20 pub fn new(left: T, bottom: T, right: T, top: T) -> Self {
22 Self { left, bottom, right, top }
23 }
24}
25
26#[derive(Default, Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
29pub struct BBox3D<T = f64> {
30 pub left: T,
32 pub bottom: T,
34 pub right: T,
36 pub top: T,
38 pub far: T,
41 pub near: T,
44}
45impl<T> BBox3D<T> {
46 pub fn new(left: T, bottom: T, right: T, top: T, near: T, far: T) -> Self {
48 Self { left, bottom, right, top, near, far }
49 }
50}
51
52#[derive(Copy, Clone, Debug, PartialEq)]
54pub enum BBOX {
55 BBox(BBox),
57 BBox3D(BBox3D),
59}
60impl Eq for BBOX {}
61impl PartialOrd for BBOX {
62 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
63 Some(self.cmp(other))
64 }
65}
66impl Ord for BBOX {
67 fn cmp(&self, other: &Self) -> Ordering {
68 match (self, other) {
69 (BBOX::BBox(a), BBOX::BBox(b)) => a.partial_cmp(b).unwrap_or(Ordering::Equal),
70 (BBOX::BBox3D(a), BBOX::BBox3D(b)) => a.partial_cmp(b).unwrap_or(Ordering::Equal),
71 (BBOX::BBox(_), BBOX::BBox3D(_)) => Ordering::Less,
73 (BBOX::BBox3D(_), BBOX::BBox(_)) => Ordering::Greater,
74 }
75 }
76}
77
78#[derive(Debug, Clone, PartialEq)]
81pub struct Point {
82 pub x: i32,
84 pub y: i32,
86 pub m: Option<MValue>,
88}
89impl Point {
90 pub fn new(x: i32, y: i32) -> Point {
92 Point { x, y, m: None }
93 }
94
95 pub fn new_with_m(x: i32, y: i32, m: MValue) -> Point {
97 Point { x, y, m: Some(m) }
98 }
99}
100impl PartialOrd for Point {
101 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
102 Some(core::cmp::Ord::cmp(self, other))
104 }
105}
106impl Eq for Point {}
107impl Ord for Point {
108 fn cmp(&self, other: &Self) -> Ordering {
109 self.x.cmp(&other.x).then(self.y.cmp(&other.y))
111 }
112}
113#[derive(Debug, Clone, PartialEq)]
116pub struct Point3D {
117 pub x: i32,
119 pub y: i32,
121 pub z: i32,
123 pub m: Option<MValue>,
125}
126impl Point3D {
127 pub fn new(x: i32, y: i32, z: i32) -> Point3D {
129 Point3D { x, y, z, m: None }
130 }
131
132 pub fn new_with_m(x: i32, y: i32, z: i32, m: MValue) -> Point3D {
134 Point3D { x, y, z, m: Some(m) }
135 }
136}
137impl PartialOrd for Point3D {
138 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
139 Some(core::cmp::Ord::cmp(self, other))
141 }
142}
143impl Eq for Point3D {}
144impl Ord for Point3D {
145 fn cmp(&self, other: &Self) -> Ordering {
146 self.x.cmp(&other.x).then(self.y.cmp(&other.y)).then(self.z.cmp(&other.z))
148 }
149}
150
151#[derive(Debug, Clone, PartialEq)]
153pub struct VectorLineWithOffset {
154 pub offset: f64,
156 pub geometry: VectorLine,
158}
159impl From<&[Point]> for VectorLineWithOffset {
160 fn from(p: &[Point]) -> Self {
161 Self { offset: 0.0, geometry: p.to_vec() }
162 }
163}
164impl VectorLineWithOffset {
165 pub fn new(offset: f64, geometry: VectorLine) -> Self {
167 Self { offset, geometry }
168 }
169
170 pub fn has_offset(&self) -> bool {
172 self.offset != 0.0
173 }
174
175 pub fn has_m_values(&self) -> bool {
177 self.geometry.iter().any(|p| p.m.is_some())
178 }
179
180 pub fn m_values(&self) -> Option<LineStringMValues> {
182 if !self.has_m_values() {
183 return None;
184 }
185 Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
186 }
187}
188pub type VectorLinesWithOffset = Vec<VectorLineWithOffset>;
190
191#[derive(Debug, Clone, PartialEq)]
193pub struct VectorLine3DWithOffset {
194 pub offset: f64,
196 pub geometry: VectorLine3D,
198}
199impl VectorLine3DWithOffset {
200 pub fn new(offset: f64, geometry: VectorLine3D) -> Self {
202 Self { offset, geometry }
203 }
204
205 pub fn has_offset(&self) -> bool {
207 self.offset != 0.0
208 }
209
210 pub fn has_m_values(&self) -> bool {
212 self.geometry.iter().any(|p| p.m.is_some())
213 }
214
215 pub fn m_values(&self) -> Option<LineStringMValues> {
217 if !self.has_m_values() {
218 return None;
219 }
220 Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
221 }
222}
223pub type VectorLines3DWithOffset = Vec<VectorLine3DWithOffset>;
225
226pub type VectorPoints = Vec<Point>;
228pub type VectorPoints3D = Vec<Point3D>;
230pub type VectorLine = Vec<Point>;
232pub type VectorLine3D = Vec<Point3D>;
234pub type VectorLines = Vec<VectorLine>;
236pub type VectorLines3D = Vec<VectorLine3D>;
238pub type VectorPoly = Vec<VectorLine>;
240pub type VectorPoly3D = Vec<VectorLine3D>;
242pub type VectorMultiPoly = Vec<VectorPoly>;
244pub type VectorMultiPoly3D = Vec<VectorPoly3D>;
246#[derive(Debug, Clone, PartialEq)]
248pub enum VectorGeometry {
249 VectorPoints(VectorPoints),
251 VectorLines(VectorLinesWithOffset),
253 VectorPolys(Vec<VectorLinesWithOffset>),
255 VectorPoints3D(VectorPoints3D),
257 VectorLines3D(VectorLines3DWithOffset),
259 VectorPolys3D(Vec<VectorLines3DWithOffset>),
261}