use geometry_cs::{CartesianFamily, CoordinateSystem, GeographicFamily, SphericalFamily, Spheroid};
use geometry_trait::Geometry;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct CartesianBuffer;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SphericalBuffer {
pub radius: f64,
}
impl SphericalBuffer {
pub const UNIT: Self = Self { radius: 1.0 };
#[must_use]
pub const fn new(radius: f64) -> Self {
Self { radius }
}
}
impl Default for SphericalBuffer {
fn default() -> Self {
Self::UNIT
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GeographicBuffer {
pub spheroid: Spheroid,
}
impl GeographicBuffer {
pub const WGS84: Self = Self {
spheroid: Spheroid::WGS84,
};
#[must_use]
pub const fn new(spheroid: Spheroid) -> Self {
Self { spheroid }
}
}
impl Default for GeographicBuffer {
fn default() -> Self {
Self::WGS84
}
}
pub trait DefaultBuffer<Family> {
type Strategy: Default;
}
impl DefaultBuffer<CartesianFamily> for CartesianFamily {
type Strategy = CartesianBuffer;
}
impl DefaultBuffer<SphericalFamily> for SphericalFamily {
type Strategy = SphericalBuffer;
}
impl DefaultBuffer<GeographicFamily> for GeographicFamily {
type Strategy = GeographicBuffer;
}
pub type DefaultBufferStrategy<G> = <<<<G as Geometry>::Point as geometry_trait::Point>::Cs as CoordinateSystem>::Family as DefaultBuffer<<<<G as Geometry>::Point as geometry_trait::Point>::Cs as CoordinateSystem>::Family>>::Strategy;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BufferDistanceStrategy {
Symmetric(f64),
Asymmetric {
left: f64,
right: f64,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BufferSideStrategy {
Straight,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BufferJoinStrategy {
Round {
points_per_circle: usize,
},
Miter {
limit: f64,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BufferEndStrategy {
Round {
points_per_circle: usize,
},
Flat,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BufferPointStrategy {
Circle {
points_per_circle: usize,
},
Square,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BufferSettings {
pub distance: BufferDistanceStrategy,
pub side: BufferSideStrategy,
pub join: BufferJoinStrategy,
pub end: BufferEndStrategy,
pub point: BufferPointStrategy,
}
impl BufferSettings {
#[must_use]
pub const fn round(distance: f64, points_per_circle: usize) -> Self {
Self {
distance: BufferDistanceStrategy::Symmetric(distance),
side: BufferSideStrategy::Straight,
join: BufferJoinStrategy::Round { points_per_circle },
end: BufferEndStrategy::Round { points_per_circle },
point: BufferPointStrategy::Circle { points_per_circle },
}
}
}
impl Default for BufferSettings {
fn default() -> Self {
Self::round(1.0, 36)
}
}