#[cfg(feature = "vec-x")]
use vec_x::VecX;
use crate::{jpr2ll, JprOrigin, ll2jpr, ll2pixel, llz2xyz, pixel2ll, xyz2llz, ZoomLv};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct LL {
long: f64,
lat: f64,
}
impl LL {
pub fn new(long: f64, lat: f64) -> Self {
Self { long, lat }
}
pub fn to_tuple(&self) -> (f64, f64) {
(self.long, self.lat)
}
#[cfg(feature = "vec-x")]
pub fn to_vec2(&self) -> VecX<f64, 2> {
VecX::new([self.long, self.lat])
}
pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
let (y, x) = ll2jpr(self.to_tuple(), origin);
JPR::new(y, x, origin)
}
pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
let (x, y) = ll2pixel(self.to_tuple(), zoom_lv);
Pixel::new(x, y, zoom_lv)
}
pub fn to_xyz(&self, altitude: f64) -> XYZ {
let (x, y, z) = llz2xyz(self.to_tuple(), altitude);
XYZ::new(x, y, z)
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct JPR {
y: f64,
x: f64,
origin: JprOrigin,
}
impl JPR {
pub fn new(x: f64, y: f64, origin: JprOrigin) -> Self {
Self { y, x, origin }
}
pub fn to_tuple(&self) -> (f64, f64) {
(self.y, self.x)
}
#[cfg(feature = "vec-x")]
pub fn to_vec2(&self) -> VecX<f64, 2> {
VecX::new([self.y, self.x])
}
pub fn to_ll(&self) -> LL {
let (long, lat) = jpr2ll(self.to_tuple(), self.origin);
LL::new(long, lat)
}
pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
let (x, y) = ll2pixel(self.to_ll().to_tuple(), zoom_lv);
Pixel::new(x, y, zoom_lv)
}
pub fn to_xyz(&self, altitude: f64) -> XYZ {
let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), altitude);
XYZ::new(x, y, z)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Pixel {
x: u32,
y: u32,
zoom: ZoomLv,
}
impl Pixel {
pub fn new(x: u32, y: u32, zoom: ZoomLv) -> Self {
Self { x, y, zoom }
}
pub fn to_tuple(&self) -> (u32, u32) {
(self.x, self.y)
}
#[cfg(feature = "vec-x")]
pub fn to_array(&self) -> VecX<u32, 2> {
VecX::new([self.x, self.y])
}
pub fn to_ll(&self) -> LL {
let (long, lat) = pixel2ll(self.to_tuple(), self.zoom);
LL::new(long, lat)
}
pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
JPR::new(y, x, origin)
}
pub fn to_xyz(&self, altitude: f64) -> XYZ {
let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), altitude);
XYZ::new(x, y, z)
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Voxel {
x: u32,
y: u32,
z: u32,
resolution: f64,
zoom_lv: ZoomLv,
}
impl Voxel {
pub fn new(x: u32, y: u32, z: u32, resolution: f64, zoom_lv: ZoomLv) -> Self {
Self { x, y, z, resolution, zoom_lv }
}
pub fn to_tuple(&self) -> (u32, u32, u32) {
(self.x, self.y, self.z)
}
#[cfg(feature = "vec-x")]
pub fn to_vec3(&self) -> VecX<u32, 3> {
VecX::new([self.x, self.y, self.z])
}
pub fn to_2d_tuple(&self) -> (u32, u32) {
(self.x, self.y)
}
#[cfg(feature = "vec-x")]
pub fn to_vec2(&self) -> VecX<u32, 2> {
VecX::new([self.x, self.y])
}
pub fn to_ll(&self) -> LL {
let (long, lat) = pixel2ll(self.to_2d_tuple(), self.zoom_lv);
LL::new(long, lat)
}
pub fn to_ll_with_altitude(&self) -> (LL, f64) {
let ll = self.to_ll();
let altitude = self.z as f64 * self.resolution;
(ll, altitude)
}
pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
JPR::new(y, x, origin)
}
pub fn to_jpr_with_altitude(&self, origin: JprOrigin) -> (JPR, f64) {
let (ll, altitude) = self.to_ll_with_altitude();
let jpr = ll.to_jpr(origin);
(jpr, altitude)
}
pub fn to_pixel(&self) -> Pixel {
Pixel::new(self.x, self.y, self.zoom_lv)
}
pub fn to_pixel_with_altitude(&self) -> (Pixel, f64) {
let (ll, altitude) = self.to_ll_with_altitude();
let pixel = ll.to_pixel(self.zoom_lv);
(pixel, altitude)
}
pub fn to_xyz(&self) -> XYZ {
let (x, y, z) = llz2xyz(self.to_ll().to_tuple(), self.z as f64 * self.resolution);
XYZ::new(x, y, z)
}
pub fn to_xyz_with_altitude(&self) -> (XYZ, f64) {
let (ll, altitude) = self.to_ll_with_altitude();
let xyz = ll.to_xyz(altitude);
(xyz, altitude)
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct XYZ {
x: f64,
y: f64,
z: f64,
}
impl XYZ {
pub fn new(x: f64, y: f64, z: f64) -> Self {
Self { x, y, z }
}
pub fn to_tuple(&self) -> (f64, f64, f64) {
(self.x, self.y, self.z)
}
#[cfg(feature = "vec-x")]
pub fn to_vec3(&self) -> VecX<f64, 3> {
VecX::new([self.x, self.y, self.z])
}
pub fn to_ll(&self) -> LL {
let ((long, lat), ..) = xyz2llz(self.to_tuple());
LL::new(long, lat)
}
pub fn to_ll_with_altitude(&self) -> (LL, f64) {
let ((long, lat), altitude) = xyz2llz(self.to_tuple());
(LL::new(long, lat), altitude)
}
pub fn to_jpr(&self, origin: JprOrigin) -> JPR {
let (y, x) = ll2jpr(self.to_ll().to_tuple(), origin);
JPR::new(y, x, origin)
}
pub fn to_jpr_with_altitude(&self, origin: JprOrigin) -> (JPR, f64) {
let (ll, altitude) = self.to_ll_with_altitude();
let jpr = ll.to_jpr(origin);
(jpr, altitude)
}
pub fn to_pixel(&self, zoom_lv: ZoomLv) -> Pixel {
let (x, y) = ll2pixel(self.to_ll().to_tuple(), zoom_lv);
Pixel::new(x, y, zoom_lv)
}
pub fn to_pixel_with_altitude(&self, zoom_lv: ZoomLv) -> (Pixel, f64) {
let (ll, altitude) = self.to_ll_with_altitude();
let pixel = ll.to_pixel(zoom_lv);
(pixel, altitude)
}
}