src/sets.rs

branch
dev
changeset 81
d2acaaddd9af
parent 41
121cf065e9ed
--- a/src/sets.rs	Sun Nov 10 09:02:57 2024 -0500
+++ b/src/sets.rs	Tue Dec 31 09:12:43 2024 -0500
@@ -59,15 +59,19 @@
 /// vector and $t$ the offset.
 ///
 /// `U` is the element type, `F` the floating point number type, and `A` the type of the
-/// orthogonal (dual) vectors. They need implement [`Dot<U, F>`].
+/// orthogonal (dual) vectors. They need implement [`Dot<U, Output=F>`].
 #[derive(Clone,Copy,Debug,Serialize,Eq,PartialEq)]
-pub struct Halfspace<A, F, U> where A : Dot<U, F>, F : Float {
+pub struct Halfspace<A, F, U>
+where A : Dot<U, Field=F> + for<'a> Dot<&'a U>,
+      F : Float {
     pub orthogonal : A,
     pub offset : F,
     _phantom : PhantomData<U>,
 }
 
-impl<A,F,U> Halfspace<A,F,U> where A : Dot<U,F>, F : Float {
+impl<A,F,U> Halfspace<A,F,U>
+where A : Dot<U, Field=F> + for<'a> Dot<&'a U>,
+      F : Float {
     #[inline]
     pub fn new(orthogonal : A, offset : F) -> Self {
         Halfspace{ orthogonal : orthogonal, offset : offset, _phantom : PhantomData }
@@ -77,7 +81,7 @@
 /// Trait for generating a halfspace spanned by another set `Self` of elements of type `U`.
 pub trait SpannedHalfspace<F, U> where  F : Float {
     /// Type of the orthogonal vector describing the halfspace.
-    type A : Dot<U, F>;
+    type A : Dot<U, Field=F> + for<'a> Dot<&'a U>;
     /// Returns the halfspace spanned by this set.
     fn spanned_halfspace(&self) -> Halfspace<Self::A, F, U>;
 }
@@ -103,7 +107,9 @@
     }
 }
 
-impl<A,U,F> Set<U> for Halfspace<A,F,U> where A : Dot<U,F>, F : Float {
+impl<A,U,F> Set<U> for Halfspace<A,F,U>
+where A : Dot<U, Field=F> + for<'a> Dot<&'a U>,
+      F : Float {
     #[inline]
     fn contains(&self, item : &U) -> bool {
         self.orthogonal.dot(item) >= self.offset
@@ -111,10 +117,14 @@
 }
 
 /// Polygons defined by `N` `Halfspace`s.
-#[derive(Clone,Copy,Debug,Eq,PartialEq)]
-pub struct NPolygon<A, F, U, const N : usize>(pub [Halfspace<A,F,U>; N]) where A : Dot<U,F>, F : Float;
+#[derive(Clone,Debug,Eq,PartialEq)]
+pub struct NPolygon<A, F, U, const N : usize>(pub [Halfspace<A,F,U>; N])
+where A : Dot<U, Field=F> + for<'a> Dot<&'a U>,
+      F : Float;
 
-impl<A,U,F,const N : usize> Set<U> for NPolygon<A,F,U,N> where A : Dot<U,F>, F : Float {
+impl<A,U,F,const N : usize> Set<U> for NPolygon<A,F,U,N>
+where A : Dot<U, Field=F> + for<'a> Dot<&'a U>,
+      F : Float {
     fn contains(&self, item : &U) -> bool {
         self.0.iter().all(|halfspace| halfspace.contains(item))
     }

mercurial