use alloc::vec::Vec;
use core::cmp::Ordering;
use s2json::{LineStringMValues, MValue};
#[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>),
}