pub mod area;
pub mod bounds;
pub mod builder;
pub mod centroid;
pub mod context;
pub mod measure;
pub mod string;
mod tests;
use std::fmt;
use std::fmt::Debug;
use std::fmt::Display;
use std::marker::PhantomData;
use std::ops::AddAssign;
use geo::CoordFloat;
use geo_types::Coord;
use num_traits::AsPrimitive;
use num_traits::FloatConst;
use crate::clip::clipper::Connectable as ClipConnectable;
use crate::path::area::Area;
use crate::path::bounds::Bounds;
use crate::path::centroid::Centroid;
use crate::projection::projector::Projector;
use crate::stream::Connectable;
use crate::stream::Stream;
use crate::stream::Streamable;
use self::measure::Measure;
pub trait Result {
type Out;
fn result(&mut self) -> Self::Out;
}
pub trait PointRadiusTrait {
type T;
fn point_radius(&mut self, val: Self::T);
}
pub enum PointRadiusEnum<T> {
Val(T),
F(Box<dyn Fn() -> T>),
}
#[cfg(not(tarpaulin_include))]
impl<T> Debug for PointRadiusEnum<T>
where
T: CoordFloat,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PointRadiusEnum").finish()
}
}
#[derive(Debug)]
#[allow(dead_code)]
pub struct Path<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone,
CLIPU: Clone,
T: CoordFloat,
{
p_pcnc: PhantomData<PCNC>,
p_rc: PhantomData<RC>,
context_stream: CS,
point_radius: PointRadiusEnum<T>,
projection: Projector<CLIPC, CLIPU, CS, PCNU, PR, RC, RU, T>,
}
impl<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T> Path<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone,
CLIPU: Clone,
T: CoordFloat,
{
pub fn new(
context_stream: CS,
projection: Projector<CLIPC, CLIPU, CS, PCNU, PR, RC, RU, T>,
) -> Self {
Self {
p_pcnc: PhantomData::<PCNC>,
p_rc: PhantomData::<RC>,
context_stream,
point_radius: PointRadiusEnum::Val(T::from(4.5_f64).unwrap()),
projection,
}
}
}
impl<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T> Path<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T>
where
CLIPU: Clone + ClipConnectable<Output = CLIPC, SC = RC>,
CLIPC: Clone + Stream<EP = CS, T = T>,
CS: Clone + Default + PartialEq + Result,
PCNC: Clone,
PCNU: Clone + Connectable<Output<CS> = PCNC>,
RC: Clone + Stream<EP = CS, T = T>,
RU: Clone + Connectable<Output<PCNC> = RC>,
T: 'static + CoordFloat + FloatConst,
{
pub fn object(&mut self, object: &impl Streamable<T = T>) -> <CS as Result>::Out {
let mut stream_in = self.projection.stream(&self.context_stream);
object.to_stream(&mut stream_in);
stream_in.endpoint().result()
}
}
impl<CLIPC, CLIPU, PCNC, PCNU, PR, RC, RU, T>
Path<CLIPC, CLIPU, Measure<T>, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone + Stream<EP = Measure<T>, T = T>,
CLIPU: Clone + ClipConnectable<Output = CLIPC, SC = RC>,
PCNU: Clone + Connectable<Output<Measure<T>> = PCNC>,
PCNC: Clone,
RC: Clone + Stream<EP = Measure<T>, T = T>,
RU: Clone + Connectable<Output<PCNC> = RC>,
T: AddAssign + CoordFloat,
{
pub fn measure(mut self, object: &impl Streamable<T = T>) -> T
where
T: AsPrimitive<T> + CoordFloat + Display + FloatConst,
{
let stream_dst = Measure::default();
let mut stream_in = self.projection.stream(&stream_dst);
object.to_stream(&mut stream_in);
stream_in.0.sink.endpoint().result()
}
}
impl<CLIPC, CLIPU, PCNC, PCNU, PR, RC, RU, T> Path<CLIPC, CLIPU, Area<T>, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone + Stream<EP = Area<T>, T = T>,
CLIPU: Clone + ClipConnectable<Output = CLIPC, SC = RC>,
PCNC: Clone,
PCNU: Clone + Connectable<Output<Area<T>> = PCNC>,
RC: Clone + Stream<EP = Area<T>, T = T>,
RU: Clone + Connectable<Output<PCNC> = RC>,
T: CoordFloat,
{
pub fn area(mut self, object: &impl Streamable<T = T>) -> T
where
T: AsPrimitive<T> + CoordFloat + Display + FloatConst,
{
let stream_dst = Area::default();
let mut stream_in = self.projection.stream(&stream_dst);
object.to_stream(&mut stream_in);
stream_in.0.sink.endpoint().result()
}
}
impl<CLIPC, CLIPU, PCNC, PCNU, PR, RC, RU, T>
Path<CLIPC, CLIPU, Bounds<T>, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone + Stream<EP = Bounds<T>, T = T>,
CLIPU: Clone + ClipConnectable<Output = CLIPC, SC = RC>,
PCNC: Clone,
PCNU: Clone + Connectable<Output<Bounds<T>> = PCNC>,
RC: Clone + Stream<EP = Bounds<T>, T = T>,
RU: Clone + Connectable<Output<PCNC> = RC> + Debug,
T: 'static + CoordFloat + FloatConst,
{
pub fn bounds(mut self, object: &impl Streamable<T = T>) -> [Coord<T>; 2] {
let stream_dst = Bounds::default();
let mut stream_in = self.projection.stream(&stream_dst);
object.to_stream(&mut stream_in);
stream_in.endpoint().result()
}
}
impl<CLIPC, CLIPU, PCNC, PCNU, PR, RC, RU, T>
Path<CLIPC, CLIPU, Centroid<T>, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone + Stream<EP = Centroid<T>, T = T>,
CLIPU: Clone + ClipConnectable<Output = CLIPC, SC = RC>,
PCNC: Clone + Stream<EP = Centroid<T>, T = T>,
PCNU: Clone + Connectable<Output<Centroid<T>> = PCNC>,
RC: Clone + Stream<EP = Centroid<T>, T = T>,
RU: Clone + Connectable<Output<PCNC> = RC>,
T: 'static + AddAssign + CoordFloat + FloatConst,
{
pub fn centroid(mut self, object: &impl Streamable<T = T>) -> Coord<T> {
let stream_dst = Centroid::default();
let mut stream_in = self.projection.stream(&stream_dst);
object.to_stream(&mut stream_in);
stream_in.endpoint().result()
}
}
impl<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T> Path<CLIPC, CLIPU, CS, PCNC, PCNU, PR, RC, RU, T>
where
CLIPC: Clone,
CLIPU: Clone,
T: CoordFloat,
{
pub fn context(&mut self, context_stream: CS) -> &mut Self {
self.context_stream = context_stream;
self
}
}