@@ -439,6 +439,8 @@ where
439439pub struct Multivector < B : Algebra > {
440440 /// Symbolic storage.
441441 pub map : BTreeMap < B , Polynomial > ,
442+ /// Whether to leverage orthonormalization conditions (ONC).
443+ pub onc : bool ,
442444}
443445
444446impl < B : Algebra > Multivector < B > {
@@ -525,6 +527,14 @@ impl<B: Algebra> Multivector<B> {
525527 self . map . values_mut ( ) . for_each ( |p| * p = take ( p) . swp ( ) ) ;
526528 self
527529 }
530+ /// Leverages orthonormalization conditions.
531+ ///
532+ /// Assumes <code>[Self::squared_norm]\(self\) == [Self::one()]</code>.
533+ #[ must_use]
534+ pub const fn unit ( mut self ) -> Self {
535+ self . onc = true ;
536+ self
537+ }
528538 /// Collects all grades.
529539 #[ must_use]
530540 pub fn grades ( & self ) -> BTreeSet < u32 > {
@@ -565,7 +575,7 @@ impl<B: Algebra> Multivector<B> {
565575 // .collect();
566576 let mut map = self . map . clone ( ) ;
567577 map. retain ( |b, _p| b. grade ( ) == grade) ;
568- vectors. insert ( grade, Self { map } ) ;
578+ vectors. insert ( grade, Self { map, onc : false } ) ;
569579 }
570580 vectors
571581 }
@@ -646,6 +656,7 @@ where
646656 . into_iter ( )
647657 . map ( |( p, b) | ( b, Polynomial :: from_iter ( p) ) )
648658 . collect ( ) ,
659+ onc : false ,
649660 }
650661 }
651662}
@@ -710,7 +721,7 @@ impl<B: Algebra> Mul for Multivector<B> {
710721 }
711722 }
712723 map. retain ( |_b, p| !p. map . is_empty ( ) ) ;
713- Self { map }
724+ Self { map, onc : false }
714725 }
715726}
716727
@@ -795,7 +806,7 @@ impl<B: Algebra> Not for Multivector<B> {
795806 map. insert ( b, p * i32:: from ( s) ) ;
796807 map
797808 } ) ;
798- Self { map }
809+ Self { map, onc : false }
799810 }
800811}
801812
@@ -820,6 +831,10 @@ impl<B: Algebra> Shl for Multivector<B> {
820831 type Output = Self ;
821832
822833 fn shl ( mut self , other : Self ) -> Self :: Output {
834+ let onc = other
835+ . onc
836+ . then ( || self . clone ( ) | ( Self :: one ( ) - other. clone ( ) . squared_norm ( ) ) )
837+ . unwrap_or_default ( ) ;
823838 if self
824839 . grade ( )
825840 . zip ( other. grade ( ) )
@@ -828,7 +843,7 @@ impl<B: Algebra> Shl for Multivector<B> {
828843 {
829844 self = -self ;
830845 }
831- other. clone ( ) * self * other. rev ( )
846+ other. clone ( ) * self * other. rev ( ) + onc
832847 }
833848}
834849
0 commit comments