1extern crate itertools;
9extern crate num_traits;
10
11#[cfg(feature = "serialize")]
12#[macro_use]
13extern crate serde;
14
15mod macros;
16
17import_all!(card);
18
19pub mod discrete;
20pub mod real;
21
22import_all!(interval);
23import_all!(partition);
24
25import_all!(arrays);
26import_all!(tuples);
27
28pub type Euclidean<const N: usize> = [real::Reals; N];
29
30pub type Intervals<const N: usize> = [Interval; N];
31
32pub trait Space {
34 const DIM: usize;
36
37 type Value: Clone;
39
40 fn card(&self) -> Card;
42
43 fn contains(&self, val: &Self::Value) -> bool;
45}
46
47impl<D: Space> Space for Box<D> {
48 const DIM: usize = D::DIM;
49
50 type Value = D::Value;
51
52 fn card(&self) -> Card { (**self).card() }
53
54 fn contains(&self, val: &Self::Value) -> bool { (**self).contains(val) }
55}
56
57impl<'a, D: Space> Space for &'a D {
58 const DIM: usize = D::DIM;
59
60 type Value = D::Value;
61
62 fn card(&self) -> Card { (**self).card() }
63
64 fn contains(&self, val: &Self::Value) -> bool { (**self).contains(val) }
65}
66
67pub trait OrderedSpace: Space
68where Self::Value: PartialOrd
69{
70 fn min(&self) -> Option<Self::Value> { None }
72
73 fn inf(&self) -> Option<Self::Value> { self.min() }
75
76 fn max(&self) -> Option<Self::Value> { None }
78
79 fn sup(&self) -> Option<Self::Value> { self.max() }
81
82 fn is_lower_bounded(&self) -> bool { self.inf().is_some() }
84
85 fn is_upper_bounded(&self) -> bool { self.sup().is_some() }
87
88 fn is_bounded(&self) -> bool { self.is_lower_bounded() && self.is_upper_bounded() }
90}
91
92pub trait FiniteSpace: Space {
94 fn to_ordinal(&self) -> ::std::ops::Range<usize> {
95 0..self
96 .card()
97 .expect_finite("Finite spaces must have finite cardinality.")
98 }
99}
100
101pub trait Union<S = Self> {
106 fn union(self, other: &S) -> Self;
108
109 fn union_many(self, other_spaces: &[S]) -> Self
112 where Self: Sized {
113 other_spaces
114 .into_iter()
115 .fold(self, |acc, other_space| acc.union(other_space))
116 }
117}
118
119pub trait Intersect<S = Self> {
124 fn intersect(self, other: &S) -> Self;
126
127 fn intersect_many(self, other_spaces: &[S]) -> Self
130 where Self: Sized {
131 other_spaces
132 .into_iter()
133 .fold(self, |acc, other_space| acc.intersect(other_space))
134 }
135}
136
137mod prelude {
138 pub use super::{Card, FiniteSpace, Intersect, OrderedSpace, Space, Union};
139}