Skip to main content

Blade

Struct Blade 

Source
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

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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 e3
Source

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]);
Source

pub const fn len(&self) -> usize

Returns the number of basis vectors in this blade.

This is equivalent to self.grade().

Source

pub const fn is_empty(&self) -> bool

Returns true if this is the scalar blade.

Source

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);
Source

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)); // disjoint
Source

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 Clone for Blade

Source§

fn clone(&self) -> Blade

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Blade

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Blade

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Blade

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Blade

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Blade

Source§

fn cmp(&self, other: &Blade) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Blade

Source§

fn eq(&self, other: &Blade) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Blade

Source§

fn partial_cmp(&self, other: &Blade) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Blade

Source§

impl Eq for Blade

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.