pub struct FourMat { /* private fields */ }Expand description
Four Matrix
Implementations§
Source§impl FourMat
impl FourMat
Sourcepub fn new(n0: FourVec, n1: FourVec, n2: FourVec, n3: FourVec) -> FourMat
pub fn new(n0: FourVec, n1: FourVec, n2: FourVec, n3: FourVec) -> FourMat
Returns a new FourMat from four FourVecs
§Arguments
n0- calcify::FourVecn1- calcify::FourVecn2- calcify::FourVecn3- 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)
);Sourcepub fn eye() -> FourMat
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);Sourcepub fn zero() -> FourMat
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);Sourcepub fn metric() -> FourMat
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);Sourcepub fn one() -> FourMat
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);Sourcepub fn n0(&self) -> &FourVec
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);Sourcepub fn n1(&self) -> &FourVec
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);Sourcepub fn n2(&self) -> &FourVec
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);Sourcepub fn n3(&self) -> &FourVec
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);Sourcepub fn c0(&self) -> FourVec
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);pub fn c1(&self) -> FourVec
pub fn c2(&self) -> FourVec
pub fn c3(&self) -> FourVec
Trait Implementations§
Source§impl AddAssign for FourMat
impl AddAssign for FourMat
Source§fn add_assign(&mut self, other: FourMat)
fn add_assign(&mut self, other: FourMat)
Performs the
+= operation. Read moreSource§impl Deserializable for FourMat
impl Deserializable for FourMat
Source§impl Mul<FourVec> for FourMat
impl Mul<FourVec> for FourMat
Source§fn mul(self, other: FourVec) -> FourVec
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§impl Mul for FourMat
impl Mul for FourMat
Source§fn mul(self, other: FourMat) -> FourMat
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§impl Serializable for FourMat
impl Serializable for FourMat
Source§impl SubAssign for FourMat
impl SubAssign for FourMat
Source§fn sub_assign(&mut self, other: FourMat)
fn sub_assign(&mut self, other: FourMat)
Performs the
-= operation. Read moreimpl Copy for FourMat
impl StructuralPartialEq for FourMat
Auto Trait Implementations§
impl Freeze for FourMat
impl RefUnwindSafe for FourMat
impl Send for FourMat
impl Sync for FourMat
impl Unpin for FourMat
impl UnwindSafe for FourMat
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
Mutably borrows from an owned value. Read more