use crate::open::{LineStringMValues, MValue};
use core::cmp::Ordering;
use alloc::vec::Vec;
#[derive(Default, Copy, Clone, Debug, PartialEq, PartialOrd, Eq)]
pub struct BBox<T = f64> {
pub left: T,
pub bottom: T,
pub right: T,
pub top: T,
}
impl<T> BBox<T> {
pub fn new(left: T, bottom: T, right: T, top: T) -> Self {
Self { left, bottom, right, top }
}
}
#[derive(Default, Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq)]
pub struct BBox3D<T = f64> {
pub left: T,
pub bottom: T,
pub right: T,
pub top: T,
pub far: T,
pub near: T,
}
impl<T> BBox3D<T> {
pub fn new(left: T, bottom: T, right: T, top: T, near: T, far: T) -> Self {
Self { left, bottom, right, top, near, far }
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BBOX {
BBox(BBox),
BBox3D(BBox3D),
}
impl Eq for BBOX {}
impl PartialOrd for BBOX {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for BBOX {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(BBOX::BBox(a), BBOX::BBox(b)) => a.partial_cmp(b).unwrap_or(Ordering::Equal),
(BBOX::BBox3D(a), BBOX::BBox3D(b)) => a.partial_cmp(b).unwrap_or(Ordering::Equal),
(BBOX::BBox(_), BBOX::BBox3D(_)) => Ordering::Less,
(BBOX::BBox3D(_), BBOX::BBox(_)) => Ordering::Greater,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Point {
pub x: i32,
pub y: i32,
pub m: Option<MValue>,
}
impl Point {
pub fn new(x: i32, y: i32) -> Point {
Point { x, y, m: None }
}
pub fn new_with_m(x: i32, y: i32, m: MValue) -> Point {
Point { x, y, m: Some(m) }
}
}
impl PartialOrd for Point {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(core::cmp::Ord::cmp(self, other))
}
}
impl Eq for Point {}
impl Ord for Point {
fn cmp(&self, other: &Self) -> Ordering {
self.x.cmp(&other.x).then(self.y.cmp(&other.y))
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Point3D {
pub x: i32,
pub y: i32,
pub z: i32,
pub m: Option<MValue>,
}
impl Point3D {
pub fn new(x: i32, y: i32, z: i32) -> Point3D {
Point3D { x, y, z, m: None }
}
pub fn new_with_m(x: i32, y: i32, z: i32, m: MValue) -> Point3D {
Point3D { x, y, z, m: Some(m) }
}
}
impl PartialOrd for Point3D {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(core::cmp::Ord::cmp(self, other))
}
}
impl Eq for Point3D {}
impl Ord for Point3D {
fn cmp(&self, other: &Self) -> Ordering {
self.x.cmp(&other.x).then(self.y.cmp(&other.y)).then(self.z.cmp(&other.z))
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct VectorLineWithOffset {
pub offset: f64,
pub geometry: VectorLine,
}
impl From<&[Point]> for VectorLineWithOffset {
fn from(p: &[Point]) -> Self {
Self { offset: 0.0, geometry: p.to_vec() }
}
}
impl VectorLineWithOffset {
pub fn new(offset: f64, geometry: VectorLine) -> Self {
Self { offset, geometry }
}
pub fn has_offset(&self) -> bool {
self.offset != 0.0
}
pub fn has_m_values(&self) -> bool {
self.geometry.iter().any(|p| p.m.is_some())
}
pub fn m_values(&self) -> Option<LineStringMValues> {
if !self.has_m_values() {
return None;
}
Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
}
}
pub type VectorLinesWithOffset = Vec<VectorLineWithOffset>;
#[derive(Debug, Clone, PartialEq)]
pub struct VectorLine3DWithOffset {
pub offset: f64,
pub geometry: VectorLine3D,
}
impl VectorLine3DWithOffset {
pub fn new(offset: f64, geometry: VectorLine3D) -> Self {
Self { offset, geometry }
}
pub fn has_offset(&self) -> bool {
self.offset != 0.0
}
pub fn has_m_values(&self) -> bool {
self.geometry.iter().any(|p| p.m.is_some())
}
pub fn m_values(&self) -> Option<LineStringMValues> {
if !self.has_m_values() {
return None;
}
Some(self.geometry.iter().map(|p| p.m.clone().unwrap_or_default()).collect())
}
}
pub type VectorLines3DWithOffset = Vec<VectorLine3DWithOffset>;
pub type VectorPoints = Vec<Point>;
pub type VectorPoints3D = Vec<Point3D>;
pub type VectorLine = Vec<Point>;
pub type VectorLine3D = Vec<Point3D>;
pub type VectorLines = Vec<VectorLine>;
pub type VectorLines3D = Vec<VectorLine3D>;
pub type VectorPoly = Vec<VectorLine>;
pub type VectorPoly3D = Vec<VectorLine3D>;
pub type VectorMultiPoly = Vec<VectorPoly>;
pub type VectorMultiPoly3D = Vec<VectorPoly3D>;
#[derive(Debug, Clone, PartialEq)]
pub enum VectorGeometry {
VectorPoints(VectorPoints),
VectorLines(VectorLinesWithOffset),
VectorPolys(Vec<VectorLinesWithOffset>),
VectorPoints3D(VectorPoints3D),
VectorLines3D(VectorLines3DWithOffset),
VectorPolys3D(Vec<VectorLines3DWithOffset>),
}