use crate::geometry::primitives::{Bounds, Point};
use crate::geometry::shapes::Rectangle;
pub trait Distance<Rhs = Self> {
fn distance(&self, other: &Rhs) -> f64;
}
pub trait Area {
fn area(&self) -> f64;
}
pub trait Centroid {
fn centroid(&self) -> Point;
}
pub trait Perimeter {
fn perimeter(&self) -> f64;
}
pub trait BoundingBox {
fn bounds(&self) -> Bounds;
}
pub trait Closed: Sized + Area + BoundingBox + Perimeter + Centroid {
fn contains(&self, other: &Self) -> bool;
fn contains_point(&self, point: &Point) -> bool;
fn intersects(&self, other: &Self) -> bool;
fn intersection_area(&self, other: &Self) -> f64;
fn intersection_points(&self, other: &Self) -> Vec<Point>;
}
pub trait DiagramShape: Closed {
fn compute_exclusive_regions(
shapes: &[Self],
) -> std::collections::HashMap<crate::geometry::diagram::RegionMask, f64>
where
Self: Sized;
#[doc(hidden)]
fn optimizer_params_from_circle(x: f64, y: f64, radius: f64) -> Vec<f64>
where
Self: Sized;
fn mds_target_distance(
area_i: f64,
area_j: f64,
target_overlap: f64,
) -> Result<f64, crate::error::DiagramError>
where
Self: Sized;
fn n_params() -> usize
where
Self: Sized;
fn from_params(params: &[f64]) -> Self
where
Self: Sized;
fn to_params(&self) -> Vec<f64>;
#[doc(hidden)]
fn from_optimizer_params(params: &[f64]) -> Self
where
Self: Sized,
{
Self::from_params(params)
}
#[doc(hidden)]
fn to_optimizer_params(&self) -> Vec<f64> {
self.to_params()
}
fn compute_exclusive_regions_with_gradient(
_shapes: &[Self],
) -> Option<ExclusiveRegionsAndGradient>
where
Self: Sized,
{
None
}
fn compute_exclusive_regions_clipped(
_shapes: &[Self],
_container: &Rectangle,
) -> Option<std::collections::HashMap<crate::geometry::diagram::RegionMask, f64>>
where
Self: Sized,
{
None
}
fn compute_exclusive_regions_clipped_with_gradient(
_shapes: &[Self],
_container: &Rectangle,
) -> Option<ExclusiveRegionsAndGradient>
where
Self: Sized,
{
None
}
fn canonical_venn_layout(n: usize) -> Option<Vec<Self>>
where
Self: Sized,
{
let _ = n;
None
}
}
pub type ExclusiveRegionsAndGradient = (
std::collections::HashMap<crate::geometry::diagram::RegionMask, f64>,
std::collections::HashMap<crate::geometry::diagram::RegionMask, Vec<f64>>,
);
pub trait Polygonize {
fn polygonize(&self, n_vertices: usize) -> crate::geometry::shapes::Polygon;
}
pub fn bounds<S: BoundingBox>(shapes: &[S]) -> Bounds {
let mut acc = Bounds::new(
f64::INFINITY,
f64::NEG_INFINITY,
f64::INFINITY,
f64::NEG_INFINITY,
);
for shape in shapes {
acc = acc.union(&shape.bounds());
}
acc
}