FourMat

Struct FourMat 

Source
pub struct FourMat { /* private fields */ }
Expand description

Four Matrix

Implementations§

Source§

impl FourMat

Source

pub fn new(n0: FourVec, n1: FourVec, n2: FourVec, n3: FourVec) -> FourMat

Returns a new FourMat from four FourVecs

§Arguments
  • n0 - calcify::FourVec
  • n1 - calcify::FourVec
  • n2 - calcify::FourVec
  • n3 - calcify::FourVec
§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
Source

pub fn from(slice: &[FourVec]) -> FourMat

Returns a new FourVec from a slice

§Arguments
§Panics
  • slice length < 4
Source

pub fn eye() -> FourMat

Returns a new FourMat identity matrix

§Example
use calcify::FourMat;
let mat4 = FourMat::eye();

assert_eq!(*mat4.n1().m1(),1.0);
Source

pub fn zero() -> FourMat

Returns a new FourMat zero matrix

§Example
use calcify::FourMat;
let mat4 = FourMat::zero();

assert_eq!(*mat4.n1().m1(),0.0);
Source

pub fn metric() -> FourMat

Returns a new FourMat metric tensor

§Example
use calcify::FourMat;
let mat4 = FourMat::metric();

assert_eq!(*mat4.n0().m0(),1.0);
assert_eq!(*mat4.n1().m1(),-1.0);
assert_eq!(*mat4.n2().m1(),0.0);
Source

pub fn one() -> FourMat

Returns a new FourMat one matrix

§Example
use calcify::FourMat;
let mat4 = FourMat::one();

assert_eq!(*mat4.n1().m1(),1.0);
Source

pub fn n0(&self) -> &FourVec

Returns a reference to the first row of the matrix.

§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
let row_zero: FourVec = *mat4.n0();
let element_zero_zero: f64 = *mat4.n0().m0();
assert_eq!(row_zero,FourVec::new(1.0,2.0,3.0,4.0));
assert_eq!(element_zero_zero,1.0);
Source

pub fn n1(&self) -> &FourVec

Returns a reference to the second row of the matrix.

§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
let row_one: FourVec = *mat4.n1();
let element_one_one: f64 = *mat4.n1().m1();
assert_eq!(row_one,FourVec::new(5.0,6.0,7.0,8.0));
assert_eq!(element_one_one,6.0);
Source

pub fn n2(&self) -> &FourVec

Returns a reference to the third row of the matrix.

§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
let row_two: FourVec = *mat4.n2();
let element_two_two: f64 = *mat4.n2().m2();
assert_eq!(row_two,FourVec::new(9.0,10.0,11.0,12.0));
assert_eq!(element_two_two,11.0);
Source

pub fn n3(&self) -> &FourVec

Returns a reference to the forth row of the matrix.

§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
let row_three: FourVec = *mat4.n3();
let element_three_three: f64 = *mat4.n3().m3();
assert_eq!(row_three,FourVec::new(13.0,14.0,15.0,16.0));
assert_eq!(element_three_three,16.0);
Source

pub fn c0(&self) -> FourVec

Returns a new memory FourVec of the first column of the matrix.

§Example
use calcify::FourVec;
use calcify::FourMat;
let mat4 = FourMat::new(
              FourVec::new(1.0,2.0,3.0,4.0),
              FourVec::new(5.0,6.0,7.0,8.0),
              FourVec::new(9.0,10.0,11.0,12.0),
              FourVec::new(13.0,14.0,15.0,16.0)
           );
let col_one: FourVec = mat4.c0();
let element_one_one: f64 = *mat4.c0().m0();
assert_eq!(col_one,FourVec::new(1.0,5.0,9.0,13.0));
assert_eq!(element_one_one,1.0);
Source

pub fn c1(&self) -> FourVec

Source

pub fn c2(&self) -> FourVec

Source

pub fn c3(&self) -> FourVec

Trait Implementations§

Source§

impl Add for FourMat

Source§

type Output = FourMat

The resulting type after applying the + operator.
Source§

fn add(self, other: FourMat) -> FourMat

Performs the + operation. Read more
Source§

impl AddAssign for FourMat

Source§

fn add_assign(&mut self, other: FourMat)

Performs the += operation. Read more
Source§

impl Clone for FourMat

Source§

fn clone(&self) -> FourMat

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 FourMat

Source§

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

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

impl Deserializable for FourMat

Source§

fn from_json(s: &str) -> Result<Self, Box<dyn Error>>

Return Self from string
Source§

fn from_msg(bytes: &[u8]) -> Result<(Self, &[u8]), Box<dyn Error>>

Return a tuple of Self and a &u8 of remaining unparsed bytes from a byte array
Source§

impl Display for FourMat

Source§

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

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

impl Mul<FourMat> for f64

Source§

type Output = FourMat

The resulting type after applying the * operator.
Source§

fn mul(self, vec: FourMat) -> FourMat

Performs the * operation. Read more
Source§

impl Mul<FourVec> for FourMat

Source§

fn mul(self, other: FourVec) -> FourVec

Matrix multiplication with vector

§Note

Only works in one direction FourMat*FourVec, implying FourVec as a column vector.

§Example
use calcify::FourMat;
use calcify::FourVec;

let mat4 = FourMat::new(FourVec::new(1.0,2.0,3.0,4.0),
                            FourVec::new(1.0,2.0,3.0,4.0),
                            FourVec::new(1.0,2.0,3.0,4.0),
                            FourVec::new(1.0,2.0,3.0,4.0));

assert_eq!(
    mat4*FourVec::new(2.0,2.0,2.0,2.0),
    FourVec::new(20.0,20.0,20.0,20.0)
);
Source§

type Output = FourVec

The resulting type after applying the * operator.
Source§

impl Mul<f64> for FourMat

Source§

type Output = FourMat

The resulting type after applying the * operator.
Source§

fn mul(self, coef: f64) -> FourMat

Performs the * operation. Read more
Source§

impl Mul for FourMat

Source§

fn mul(self, other: FourMat) -> FourMat

Matrix multiplication

§Example
use calcify::FourMat;
use calcify::FourVec;

let mat4 = FourMat::new(FourVec::new(1.0,2.0,3.0,4.0),
                            FourVec::new(5.0,6.0,7.0,8.0),
                            FourVec::new(9.0,10.0,11.0,12.0),
                            FourVec::new(13.0,14.0,15.0,16.0));

assert_eq!(
    mat4*mat4,
    FourMat::new(FourVec::new(90.0,100.0,110.0,120.0),
                FourVec::new(202.0,228.0,254.0,280.0),
                FourVec::new(314.0,356.0,398.0,440.0),
                FourVec::new(426.0,484.0,542.0,600.0)));
Source§

type Output = FourMat

The resulting type after applying the * operator.
Source§

impl Neg for FourMat

Source§

type Output = FourMat

The resulting type after applying the - operator.
Source§

fn neg(self) -> FourMat

Performs the unary - operation. Read more
Source§

impl PartialEq for FourMat

Source§

fn eq(&self, other: &FourMat) -> 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 Serializable for FourMat

Source§

fn to_json(&self) -> String

Return object intensive json string Read more
Source§

fn to_msg(&self) -> Result<Vec<u8>, ValueWriteError>

Return Result wrapped Vec in MsgPack Format is not like to_json it is array intensive not object Read more
Source§

impl Sub for FourMat

Source§

type Output = FourMat

The resulting type after applying the - operator.
Source§

fn sub(self, other: FourMat) -> FourMat

Performs the - operation. Read more
Source§

impl SubAssign for FourMat

Source§

fn sub_assign(&mut self, other: FourMat)

Performs the -= operation. Read more
Source§

impl Copy for FourMat

Source§

impl StructuralPartialEq for FourMat

Auto Trait Implementations§

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> 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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.