nalgebra/nalgebra-glm/src/gtc/matrix_access.rs

66 lines
1.5 KiB
Rust
Raw Normal View History

2021-04-11 17:00:38 +08:00
use na::Scalar;
2019-03-23 21:29:07 +08:00
use crate::aliases::{TMat, TVec};
/// The `index`-th column of the matrix `m`.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`row`](fn.row.html)
/// * [`set_column`](fn.set_column.html)
/// * [`set_row`](fn.set_row.html)
2021-04-11 17:00:38 +08:00
pub fn column<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
) -> TVec<T, R> {
m.column(index).into_owned()
}
/// Sets to `x` the `index`-th column of the matrix `m`.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_row`](fn.set_row.html)
2021-04-11 17:00:38 +08:00
pub fn set_column<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
2018-10-22 04:11:27 +08:00
index: usize,
2021-04-11 17:00:38 +08:00
x: &TVec<T, R>,
) -> TMat<T, R, C> {
let mut res = m.clone();
res.set_column(index, x);
res
}
/// The `index`-th row of the matrix `m`.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`set_column`](fn.set_column.html)
/// * [`set_row`](fn.set_row.html)
2021-04-11 17:00:38 +08:00
pub fn row<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
) -> TVec<T, C> {
m.row(index).into_owned().transpose()
}
/// Sets to `x` the `index`-th row of the matrix `m`.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_column`](fn.set_column.html)
2021-04-11 17:00:38 +08:00
pub fn set_row<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
2018-10-22 04:11:27 +08:00
index: usize,
2021-04-11 17:00:38 +08:00
x: &TVec<T, C>,
) -> TMat<T, R, C> {
let mut res = m.clone();
res.set_row(index, &x.transpose());
res
}