mod domm;
mod doms;
pub use domm::*;
pub use doms::*;
use nalgebra::{
DefaultAllocator, Dim, OVector, RealField, Scalar, U1, VectorView, allocator::Allocator,
};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
pub trait Domain<T, D>: Clone + Debug + PartialEq + Send + Sync
where
T: Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
{
fn clip<RStride: Dim, CStride: Dim>(
&self,
sample: &VectorView<T, D, RStride, CStride>,
) -> OVector<T, D>;
fn contains<RStride: Dim, CStride: Dim>(
&self,
sample: &VectorView<T, D, RStride, CStride>,
) -> bool;
fn maximum_values(&self) -> Option<OVector<T, D>>;
fn minimum_values(&self) -> Option<OVector<T, D>>;
fn size(&self) -> OVector<Option<T>, D>
where
T: RealField;
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct UDomain<D>(D);
impl<D> UDomain<D> {
pub fn new(dim: D) -> Self {
UDomain(dim)
}
}
impl<T, D> Domain<T, D> for UDomain<D>
where
T: PartialOrd + Scalar,
D: Dim,
DefaultAllocator: Allocator<D>,
{
fn clip<RStride: Dim, CStride: Dim>(
&self,
sample: &VectorView<T, D, RStride, CStride>,
) -> OVector<T, D> {
sample.clone_owned()
}
fn contains<RStride: Dim, CStride: Dim>(
&self,
_sample: &VectorView<T, D, RStride, CStride>,
) -> bool {
true
}
fn maximum_values(&self) -> Option<OVector<T, D>> {
None
}
fn minimum_values(&self) -> Option<OVector<T, D>> {
None
}
fn size(&self) -> OVector<Option<T>, D> {
OVector::<Option<T>, D>::from_element_generic(self.0, U1, None)
}
}