matrics: create helpers for Matrix4x4 and add it to prelude.
This commit is contained in:
parent
4936839723
commit
0965ac9ddf
@ -39,5 +39,8 @@ pub mod float {
|
||||
pub use float::Float;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::tuples::{point, vector, Color};
|
||||
pub use crate::{
|
||||
matrices::{identity, rotation_x, rotation_y, rotation_z, scaling, shearing, translation},
|
||||
tuples::{point, vector, Color},
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,6 +3,87 @@ use std::ops::{Index, IndexMut, Mul, Sub};
|
||||
|
||||
use crate::{tuples::Tuple, Float, EPSILON};
|
||||
|
||||
/// Short hand for creating a Matrix4x4 set to the identity matrix.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{identity, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(identity(), Matrix4x4::identity());
|
||||
/// ```
|
||||
pub fn identity() -> Matrix4x4 {
|
||||
Matrix4x4::identity()
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 for rotating around the X-axis.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{rotation_x, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(rotation_x(10.), Matrix4x4::rotation_x(10.));
|
||||
/// ```
|
||||
pub fn rotation_x(radians: Float) -> Matrix4x4 {
|
||||
Matrix4x4::rotation_x(radians)
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 for rotating around the Y-axis.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{rotation_y, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(rotation_y(10.), Matrix4x4::rotation_y(10.));
|
||||
/// ```
|
||||
pub fn rotation_y(radians: Float) -> Matrix4x4 {
|
||||
Matrix4x4::rotation_y(radians)
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 for rotating around the Z-axis.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{rotation_z, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(rotation_z(10.), Matrix4x4::rotation_z(10.));
|
||||
/// ```
|
||||
pub fn rotation_z(radians: Float) -> Matrix4x4 {
|
||||
Matrix4x4::rotation_z(radians)
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 that scales in the given x,y,z axis.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{scaling, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(scaling(1., 2., 3.), Matrix4x4::scaling(1., 2., 3.));
|
||||
/// ```
|
||||
pub fn scaling(x: Float, y: Float, z: Float) -> Matrix4x4 {
|
||||
Matrix4x4::scaling(x, y, z)
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 that shears across the given axis pairs.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{shearing, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// shearing(1., 2., 3., 4., 5., 6.),
|
||||
/// Matrix4x4::shearing(1., 2., 3., 4., 5., 6.)
|
||||
/// );
|
||||
/// ```
|
||||
pub fn shearing(xy: Float, xz: Float, yx: Float, yz: Float, zx: Float, zy: Float) -> Matrix4x4 {
|
||||
Matrix4x4::shearing(xy, xz, yx, yz, zx, zy)
|
||||
}
|
||||
/// Short hand for creating a Matrix4x4 that translations along the given x,y,z axis.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::matrices::{translation, Matrix4x4};
|
||||
///
|
||||
/// assert_eq!(translation(1., 2., 3.), Matrix4x4::translation(1., 2., 3.));
|
||||
/// ```
|
||||
pub fn translation(x: Float, y: Float, z: Float) -> Matrix4x4 {
|
||||
Matrix4x4::translation(x, y, z)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Matrix2x2 {
|
||||
m: [[Float; 2]; 2],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user