extern crate itertools;
extern crate num_traits;
#[cfg(feature = "serialize")]
#[macro_use]
extern crate serde;
mod macros;
import_all!(card);
pub mod discrete;
pub mod real;
import_all!(interval);
import_all!(partition);
import_all!(arrays);
import_all!(tuples);
pub type Euclidean<const N: usize> = [real::Reals; N];
pub type Intervals<const N: usize> = [Interval; N];
pub trait Space {
const DIM: usize;
type Value: Clone;
fn card(&self) -> Card;
fn contains(&self, val: &Self::Value) -> bool;
}
impl<D: Space> Space for Box<D> {
const DIM: usize = D::DIM;
type Value = D::Value;
fn card(&self) -> Card { (**self).card() }
fn contains(&self, val: &Self::Value) -> bool { (**self).contains(val) }
}
impl<'a, D: Space> Space for &'a D {
const DIM: usize = D::DIM;
type Value = D::Value;
fn card(&self) -> Card { (**self).card() }
fn contains(&self, val: &Self::Value) -> bool { (**self).contains(val) }
}
pub trait OrderedSpace: Space
where Self::Value: PartialOrd
{
fn min(&self) -> Option<Self::Value> { None }
fn inf(&self) -> Option<Self::Value> { self.min() }
fn max(&self) -> Option<Self::Value> { None }
fn sup(&self) -> Option<Self::Value> { self.max() }
fn is_lower_bounded(&self) -> bool { self.inf().is_some() }
fn is_upper_bounded(&self) -> bool { self.sup().is_some() }
fn is_bounded(&self) -> bool { self.is_lower_bounded() && self.is_upper_bounded() }
}
pub trait FiniteSpace: Space {
fn to_ordinal(&self) -> ::std::ops::Range<usize> {
0..self
.card()
.expect_finite("Finite spaces must have finite cardinality.")
}
}
pub trait Union<S = Self> {
fn union(self, other: &S) -> Self;
fn union_many(self, other_spaces: &[S]) -> Self
where Self: Sized {
other_spaces
.into_iter()
.fold(self, |acc, other_space| acc.union(other_space))
}
}
pub trait Intersect<S = Self> {
fn intersect(self, other: &S) -> Self;
fn intersect_many(self, other_spaces: &[S]) -> Self
where Self: Sized {
other_spaces
.into_iter()
.fold(self, |acc, other_space| acc.intersect(other_space))
}
}
mod prelude {
pub use super::{Card, FiniteSpace, Intersect, OrderedSpace, Space, Union};
}