Extract make_vec and make_mat into mathx
This commit is contained in:
parent
c1b7d5ea00
commit
33906f51b3
16
src/mathx.rs
16
src/mathx.rs
|
|
@ -142,6 +142,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_vec2(f: impl Fn(usize) -> f32) -> Vec2 {
|
||||||
|
Vec2::from_array(std::array::from_fn(|i| f(i)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_mat2(f: impl Fn(usize, usize) -> f32) -> Mat2 {
|
||||||
|
Mat2::from_cols_array_2d(&std::array::from_fn(|i| std::array::from_fn(|j| f(i, j))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_vec3(f: impl Fn(usize) -> f32) -> Vec3 {
|
||||||
|
Vec3::from_array(std::array::from_fn(|i| f(i)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_mat3(f: impl Fn(usize, usize) -> f32) -> Mat3 {
|
||||||
|
Mat3::from_cols_array_2d(&std::array::from_fn(|i| std::array::from_fn(|j| f(i, j))))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::mathx::Decomp3;
|
use crate::mathx::{make_mat3, Decomp3};
|
||||||
use glam::*;
|
use glam::*;
|
||||||
|
|
||||||
pub type Tens3 = [Mat3; 3];
|
pub type Tens3 = [Mat3; 3];
|
||||||
|
|
@ -86,14 +86,6 @@ pub fn contract2(t: Tens3, v: Vec3) -> Vec3 {
|
||||||
contract(t, v) * v
|
contract(t, v) * v
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_vec3(f: impl Fn(usize) -> f32) -> Vec3 {
|
|
||||||
Vec3::from_array(std::array::from_fn(|i| f(i)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_mat3(f: impl Fn(usize, usize) -> f32) -> Mat3 {
|
|
||||||
Mat3::from_cols_array_2d(&std::array::from_fn(|i| std::array::from_fn(|j| f(i, j))))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_tens3(f: impl Fn(usize, usize, usize) -> f32) -> Tens3 {
|
fn make_tens3(f: impl Fn(usize, usize, usize) -> f32) -> Tens3 {
|
||||||
std::array::from_fn(|i| make_mat3(|j, k| f(i, j, k)))
|
std::array::from_fn(|i| make_mat3(|j, k| f(i, j, k)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user