pub(crate) use edge_end_builder::EdgeEndBuilder;
pub use geomgraph::intersection_matrix::IntersectionMatrix;
use crate::geometry::*;
use crate::{GeoFloat, GeometryCow};
mod edge_end_builder;
mod geomgraph;
mod relate_operation;
pub trait Relate<F, T> {
fn relate(&self, other: &T) -> IntersectionMatrix;
}
impl<F: GeoFloat> Relate<F, GeometryCow<'_, F>> for GeometryCow<'_, F> {
fn relate(&self, other: &GeometryCow<F>) -> IntersectionMatrix {
let mut relate_computer = relate_operation::RelateOperation::new(self, other);
relate_computer.compute_intersection_matrix()
}
}
macro_rules! relate_impl {
($k:ty, $t:ty) => {
relate_impl![($k, $t),];
};
($(($k:ty, $t:ty),)*) => {
$(
impl<F: GeoFloat> Relate<F, $t> for $k {
fn relate(&self, other: &$t) -> IntersectionMatrix {
GeometryCow::from(self).relate(&GeometryCow::from(other))
}
}
)*
};
}
macro_rules! cartesian_pairs {
($macro_name:ident, [$($a:ty),*]) => {
cartesian_pairs_helper! { [] [$($a,)*] [$($a,)*] [$($a,)*] $macro_name}
};
}
macro_rules! cartesian_pairs_helper {
([$($out_pairs:tt)*] [] [$($b:ty,)*] $init_b:tt $macro_name:ident) => {
$macro_name!{$($out_pairs)*}
};
($out_pairs:tt [$a_car:ty, $($a_cdr:ty,)*] [] $init_b:tt $macro_name:ident) => {
cartesian_pairs_helper!{$out_pairs [$($a_cdr,)*] $init_b $init_b $macro_name}
};
([$($out_pairs:tt)*] [$a_car:ty, $($a_cdr:ty,)*] [$b_car:ty, $($b_cdr:ty,)*] $init_b:tt $macro_name:ident) => {
cartesian_pairs_helper!{[$($out_pairs)* ($a_car, $b_car),] [$a_car, $($a_cdr,)*] [$($b_cdr,)*] $init_b $macro_name}
};
}
cartesian_pairs!(relate_impl, [Point<F>, Line<F>, LineString<F>, Polygon<F>, MultiPoint<F>, MultiLineString<F>, MultiPolygon<F>, Rect<F>, Triangle<F>, GeometryCollection<F>]);
relate_impl!(Geometry<F>, Geometry<F>);