pub struct Blade { /* private fields */ }Expand description
A basis blade in a geometric algebra.
Blades are represented as bitmasks where bit i indicates the presence
of basis vector eᵢ. This representation is always canonical since
bits are inherently ordered.
§Examples
use clifford_codegen::algebra::Blade;
// Scalar (grade 0)
let scalar = Blade::scalar();
assert_eq!(scalar.grade(), 0);
assert_eq!(scalar.index(), 0);
// Basis vector e₁
let e1 = Blade::basis(0);
assert_eq!(e1.grade(), 1);
assert_eq!(e1.index(), 1);
// Bivector e₁₂
let e12 = Blade::from_index(0b11);
assert_eq!(e12.grade(), 2);Implementations§
Source§impl Blade
impl Blade
Sourcepub const fn from_index(index: usize) -> Self
pub const fn from_index(index: usize) -> Self
Creates a blade from its bitmask index.
§Example
use clifford_codegen::algebra::Blade;
let e12 = Blade::from_index(0b11);
assert_eq!(e12.index(), 3);Sourcepub const fn scalar() -> Self
pub const fn scalar() -> Self
Creates the scalar blade (grade 0, index 0).
§Example
use clifford_codegen::algebra::Blade;
let s = Blade::scalar();
assert_eq!(s.index(), 0);
assert_eq!(s.grade(), 0);Sourcepub const fn basis(i: usize) -> Self
pub const fn basis(i: usize) -> Self
Creates a basis vector blade.
Blade::basis(i) creates blade eᵢ₊₁ (using 0-based indexing internally).
§Example
use clifford_codegen::algebra::Blade;
let e1 = Blade::basis(0);
assert_eq!(e1.index(), 1);
let e2 = Blade::basis(1);
assert_eq!(e2.index(), 2);
let e3 = Blade::basis(2);
assert_eq!(e3.index(), 4);Sourcepub const fn index(&self) -> usize
pub const fn index(&self) -> usize
Returns the blade’s bitmask index.
§Example
use clifford_codegen::algebra::Blade;
let e12 = Blade::from_index(3);
assert_eq!(e12.index(), 3);Sourcepub const fn grade(&self) -> usize
pub const fn grade(&self) -> usize
Returns the grade (number of basis vectors in this blade).
The grade equals the number of 1-bits in the index.
§Example
use clifford_codegen::algebra::Blade;
assert_eq!(Blade::scalar().grade(), 0);
assert_eq!(Blade::basis(0).grade(), 1);
assert_eq!(Blade::from_index(0b111).grade(), 3);Sourcepub const fn contains(&self, i: usize) -> bool
pub const fn contains(&self, i: usize) -> bool
Checks if this blade contains basis vector i.
§Example
use clifford_codegen::algebra::Blade;
let e12 = Blade::from_index(0b11);
assert!(e12.contains(0)); // contains e1
assert!(e12.contains(1)); // contains e2
assert!(!e12.contains(2)); // does not contain e3Sourcepub fn basis_vectors(&self) -> impl Iterator<Item = usize> + '_
pub fn basis_vectors(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over the basis vector indices in this blade.
Indices are yielded in ascending order.
§Example
use clifford_codegen::algebra::Blade;
let e135 = Blade::from_index(0b10101);
let indices: Vec<_> = e135.basis_vectors().collect();
assert_eq!(indices, vec![0, 2, 4]);Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of basis vectors in this blade.
This is equivalent to self.grade().
Sourcepub const fn xor(&self, other: Self) -> Self
pub const fn xor(&self, other: Self) -> Self
Computes the XOR of two blade indices.
This gives the result blade of the geometric product (before considering sign).
§Example
use clifford_codegen::algebra::Blade;
let e1 = Blade::basis(0);
let e2 = Blade::basis(1);
let e12 = e1.xor(e2);
assert_eq!(e12.index(), 3);Sourcepub const fn overlaps(&self, other: Self) -> bool
pub const fn overlaps(&self, other: Self) -> bool
Returns true if this blade shares any basis vectors with another.
§Example
use clifford_codegen::algebra::Blade;
let e12 = Blade::from_index(0b11);
let e23 = Blade::from_index(0b110);
let e45 = Blade::from_index(0b11000);
assert!(e12.overlaps(e23)); // share e2
assert!(!e12.overlaps(e45)); // disjointSourcepub fn name(&self) -> String
pub fn name(&self) -> String
Returns the blade name using standard notation.
Uses 1-based indexing for display: e1, e12, e123, etc.
§Example
use clifford_codegen::algebra::Blade;
assert_eq!(Blade::scalar().name(), "1");
assert_eq!(Blade::basis(0).name(), "e1");
assert_eq!(Blade::from_index(0b11).name(), "e12");Trait Implementations§
Source§impl Ord for Blade
impl Ord for Blade
Source§impl PartialOrd for Blade
impl PartialOrd for Blade
impl Copy for Blade
impl Eq for Blade
impl StructuralPartialEq for Blade
Auto Trait Implementations§
impl Freeze for Blade
impl RefUnwindSafe for Blade
impl Send for Blade
impl Sync for Blade
impl Unpin for Blade
impl UnwindSafe for Blade
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more