clifford 0.3.0

Geometric Algebra (Clifford Algebra) for Rust: rotors, motors, PGA for 3D rotations and rigid transforms
Documentation
#![doc = " Multivector conversions for projective2."]
#![doc = ""]
#![doc = " This file is auto-generated by clifford-codegen."]
#![doc = " Do not edit manually."]
use super::types::{Flector, Line, Motor, Point, Scalar, Trivector};
use crate::algebra::Multivector;
use crate::basis::Blade;
use crate::scalar::Float;
use crate::signature::Projective2;
impl<T: Float> From<Flector<T>> for Multivector<T, Projective2> {
    fn from(value: Flector<T>) -> Self {
        Self::from_coeffs(&[
            value.s(),
            T::zero(),
            T::zero(),
            value.d(),
            T::zero(),
            -value.ny(),
            value.nx(),
            T::zero(),
        ])
    }
}
impl<T: Float> From<Line<T>> for Multivector<T, Projective2> {
    fn from(value: Line<T>) -> Self {
        Self::from_coeffs(&[
            T::zero(),
            T::zero(),
            T::zero(),
            value.d(),
            T::zero(),
            -value.ny(),
            value.nx(),
            T::zero(),
        ])
    }
}
impl<T: Float> From<Motor<T>> for Multivector<T, Projective2> {
    fn from(value: Motor<T>) -> Self {
        Self::from_coeffs(&[
            T::zero(),
            value.ty(),
            value.tx(),
            T::zero(),
            value.r(),
            T::zero(),
            T::zero(),
            value.ps(),
        ])
    }
}
impl<T: Float> From<Point<T>> for Multivector<T, Projective2> {
    fn from(value: Point<T>) -> Self {
        Self::from_coeffs(&[
            T::zero(),
            value.x(),
            value.y(),
            T::zero(),
            value.w(),
            T::zero(),
            T::zero(),
            T::zero(),
        ])
    }
}
impl<T: Float> From<Scalar<T>> for Multivector<T, Projective2> {
    fn from(value: Scalar<T>) -> Self {
        Self::from_coeffs(&[
            value.s(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
        ])
    }
}
impl<T: Float> From<Trivector<T>> for Multivector<T, Projective2> {
    fn from(value: Trivector<T>) -> Self {
        Self::from_coeffs(&[
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            T::zero(),
            value.ps(),
        ])
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Flector<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(
            mv.get(Blade::from_index(0usize)),
            mv.get(Blade::from_index(3usize)),
            mv.get(Blade::from_index(6usize)),
            -mv.get(Blade::from_index(5usize)),
        )
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Line<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(
            mv.get(Blade::from_index(3usize)),
            mv.get(Blade::from_index(6usize)),
            -mv.get(Blade::from_index(5usize)),
        )
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Motor<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(
            mv.get(Blade::from_index(1usize)),
            mv.get(Blade::from_index(2usize)),
            mv.get(Blade::from_index(4usize)),
            mv.get(Blade::from_index(7usize)),
        )
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Point<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(
            mv.get(Blade::from_index(1usize)),
            mv.get(Blade::from_index(2usize)),
            mv.get(Blade::from_index(4usize)),
        )
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Scalar<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(mv.get(Blade::from_index(0usize)))
    }
}
impl<T: Float> From<Multivector<T, Projective2>> for Trivector<T> {
    #[doc = r" Extracts this type from a multivector."]
    #[doc = r""]
    #[doc = r" Note: This is a lossy projection that only extracts the relevant"]
    #[doc = r" grades. Other components of the multivector are discarded."]
    fn from(mv: Multivector<T, Projective2>) -> Self {
        Self::new_unchecked(mv.get(Blade::from_index(7usize)))
    }
}