1#[cfg(feature = "vec-x")]
2use vec_x::VecX;
3
4use crate::{jpr2ll, JprOrigin, ll2jpr, ll2pixel, llz2xyz, pixel2ll, xyz2llz, ZoomLv};
13
14#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
18pub struct LL {
19 long: f64,
20 lat: f64,
21}
22
23impl LL {
24 pub fn new(long: f64, lat: f64) -> Self {
28 Self { long, lat }
29 }
30
31 pub fn to_tuple(&self) -> (f64, f64) {
35 (self.long, self.lat)
36 }
37
38 #[cfg(feature = "vec-x")]
42 pub fn to_vec2(&self) -> VecX<f64, 2> {
43 VecX::new([self.long, self.lat])
44 }
45
46 pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
50 let (y, x) = ll2jpr(self.to_tuple(), origin);
51 JPR::new(y, x, origin)
52 }
53
54 pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
58 let (x, y) = ll2pixel(self.to_tuple(), zoom_lv);
59 Pixel::new(x, y, zoom_lv)
60 }
61
62 pub fn to_xyz(&self, altitude: f64) -> XYZ {
66 let (x, y, z) = llz2xyz(self.to_tuple(), altitude);
67 XYZ::new(x, y, z)
68 }
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
75pub struct JPR {
76 y: f64,
77 x: f64,
78 origin: JprOrigin,
79}
80
81impl JPR {
82 pub fn new(x: f64, y: f64, origin: JprOrigin) -> Self {
86 Self { y, x, origin }
87 }
88
89 pub fn to_tuple(&self) -> (f64, f64) {
93 (self.y, self.x)
94 }
95
96 #[cfg(feature = "vec-x")]
100 pub fn to_vec2(&self) -> VecX<f64, 2> {
101 VecX::new([self.y, self.x])
102 }
103
104 pub fn to_ll(&self) -> LL {
108 let (long, lat) = jpr2ll(self.to_tuple(), self.origin);
109 LL::new(long, lat)
110 }
111
112 pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
116 let (x, y) = ll2pixel(self.to_ll().to_tuple(), zoom_lv);
117 Pixel::new(x, y, zoom_lv)
118 }
119
120 pub fn to_xyz(&self, altitude: f64) -> XYZ {
124 let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), altitude);
125 XYZ::new(x, y, z)
126 }
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
133pub struct Pixel {
134 x: u32,
135 y: u32,
136 zoom: ZoomLv,
137}
138
139impl Pixel {
140 pub fn new(x: u32, y: u32, zoom: ZoomLv) -> Self {
144 Self { x, y, zoom }
145 }
146
147 pub fn to_tuple(&self) -> (u32, u32) {
151 (self.x, self.y)
152 }
153
154 #[cfg(feature = "vec-x")]
158 pub fn to_array(&self) -> VecX<u32, 2> {
159 VecX::new([self.x, self.y])
160 }
161
162 pub fn to_ll(&self) -> LL {
166 let (long, lat) = pixel2ll(self.to_tuple(), self.zoom);
167 LL::new(long, lat)
168 }
169
170 pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
174 let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
175 JPR::new(y, x, origin)
176 }
177
178 pub fn to_xyz(&self, altitude: f64) -> XYZ {
182 let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), altitude);
183 XYZ::new(x, y, z)
184 }
185}
186
187#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
193pub struct Voxel {
194 x: u32,
195 y: u32,
196 z: u32,
197 resolution: f64,
198 zoom_lv: ZoomLv,
199}
200
201impl Voxel {
202 pub fn new(x: u32, y: u32, z: u32, resolution: f64, zoom_lv: ZoomLv) -> Self {
206 Self { x, y, z, resolution, zoom_lv }
207 }
208
209 pub fn to_tuple(&self) -> (u32, u32, u32) {
213 (self.x, self.y, self.z)
214 }
215
216 #[cfg(feature = "vec-x")]
220 pub fn to_vec3(&self) -> VecX<u32, 3> {
221 VecX::new([self.x, self.y, self.z])
222 }
223
224 pub fn to_2d_tuple(&self) -> (u32, u32) {
228 (self.x, self.y)
229 }
230
231 #[cfg(feature = "vec-x")]
235 pub fn to_vec2(&self) -> VecX<u32, 2> {
236 VecX::new([self.x, self.y])
237 }
238
239 pub fn to_ll(&self) -> LL {
243 let (long, lat) = pixel2ll(self.to_2d_tuple(), self.zoom_lv);
244 LL::new(long, lat)
245 }
246
247 pub fn to_ll_with_altitude(&self) -> (LL, f64) {
251 let ll = self.to_ll();
252 let altitude = self.z as f64 * self.resolution;
253 (ll, altitude)
254 }
255
256 pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
260 let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
261 JPR::new(y, x, origin)
262 }
263
264 pub fn to_jpr_with_altitude(&self, origin: JprOrigin) -> (JPR, f64) {
268 let (ll, altitude) = self.to_ll_with_altitude();
269 let jpr = ll.to_jpr(origin);
270 (jpr, altitude)
271 }
272
273 pub fn to_pixel(&self) -> Pixel {
277 Pixel::new(self.x, self.y, self.zoom_lv)
278 }
279
280 pub fn to_pixel_with_altitude(&self) -> (Pixel, f64) {
284 let (ll, altitude) = self.to_ll_with_altitude();
285 let pixel = ll.to_pixel(self.zoom_lv);
286 (pixel, altitude)
287 }
288
289 pub fn to_xyz(&self) -> XYZ {
293 let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), self.z as f64 * self.resolution);
294 XYZ::new(x, y, z)
295 }
296
297 pub fn to_xyz_with_altitude(&self) -> (XYZ, f64) {
301 let (ll, altitude) = self.to_ll_with_altitude();
302 let xyz = ll.to_xyz(altitude);
303 (xyz, altitude)
304 }
305}
306
307#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
311pub struct XYZ {
312 x: f64,
313 y: f64,
314 z: f64,
315}
316
317impl XYZ {
318 pub fn new(x: f64, y: f64, z: f64) -> Self {
322 Self { x, y, z }
323 }
324
325 pub fn to_tuple(&self) -> (f64, f64, f64) {
329 (self.x, self.y, self.z)
330 }
331
332 #[cfg(feature = "vec-x")]
336 pub fn to_vec3(&self) -> VecX<f64, 3> {
337 VecX::new([self.x, self.y, self.z])
338 }
339
340 pub fn to_ll(&self) -> LL {
344 let ((long, lat), ..) = xyz2llz(self.to_tuple());
345 LL::new(long, lat)
346 }
347
348 pub fn to_ll_with_altitude(&self) -> (LL, f64) {
352 let ((long, lat), altitude) = xyz2llz(self.to_tuple());
353 (LL::new(long, lat), altitude)
354 }
355
356 pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
360 let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
361 JPR::new(y, x, origin)
362 }
363
364 pub fn to_jpr_with_altitude(&self, origin: JprOrigin) -> (JPR, f64) {
368 let (ll, altitude) = self.to_ll_with_altitude();
369 let jpr = ll.to_jpr(origin);
370 (jpr, altitude)
371 }
372
373 pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
376 let (x, y) = ll2pixel(self.to_ll().to_tuple(), zoom_lv);
377 Pixel::new(x, y, zoom_lv)
378 }
379
380 pub fn to_pixel_with_altitude(&self, zoom_lv: ZoomLv) -> (Pixel, f64) {
384 let (ll, altitude) = self.to_ll_with_altitude();
385 let pixel = ll.to_pixel(zoom_lv);
386 (pixel, altitude)
387 }
388}
389