nalgebra_glm/ext/
matrix_relationnal.rs

1use crate::aliases::{TMat, TVec};
2use crate::traits::Number;
3
4/// Perform a component-wise equal-to comparison of two matrices.
5///
6/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
7pub fn equal_columns<T: Number, const R: usize, const C: usize>(
8    x: &TMat<T, R, C>,
9    y: &TMat<T, R, C>,
10) -> TVec<bool, C> {
11    let mut res = TVec::<_, C>::repeat(false);
12
13    for i in 0..C {
14        res[i] = x.column(i) == y.column(i)
15    }
16
17    res
18}
19
20/// Returns the component-wise comparison of `|x - y| < epsilon`.
21///
22/// True if this expression is satisfied.
23pub fn equal_columns_eps<T: Number, const R: usize, const C: usize>(
24    x: &TMat<T, R, C>,
25    y: &TMat<T, R, C>,
26    epsilon: T,
27) -> TVec<bool, C> {
28    equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
29}
30
31/// Returns the component-wise comparison on each matrix column `|x - y| < epsilon`.
32///
33/// True if this expression is satisfied.
34pub fn equal_columns_eps_vec<T: Number, const R: usize, const C: usize>(
35    x: &TMat<T, R, C>,
36    y: &TMat<T, R, C>,
37    epsilon: &TVec<T, C>,
38) -> TVec<bool, C> {
39    let mut res = TVec::<_, C>::repeat(false);
40
41    for i in 0..C {
42        res[i] = (x.column(i) - y.column(i)).abs() < TVec::<_, R>::repeat(epsilon[i])
43    }
44
45    res
46}
47
48/// Perform a component-wise not-equal-to comparison of two matrices.
49///
50/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
51pub fn not_equal_columns<T: Number, const R: usize, const C: usize>(
52    x: &TMat<T, R, C>,
53    y: &TMat<T, R, C>,
54) -> TVec<bool, C> {
55    let mut res = TVec::<_, C>::repeat(false);
56
57    for i in 0..C {
58        res[i] = x.column(i) != y.column(i)
59    }
60
61    res
62}
63
64/// Returns the component-wise comparison of `|x - y| < epsilon`.
65///
66/// True if this expression is not satisfied.
67pub fn not_equal_columns_eps<T: Number, const R: usize, const C: usize>(
68    x: &TMat<T, R, C>,
69    y: &TMat<T, R, C>,
70    epsilon: T,
71) -> TVec<bool, C> {
72    not_equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
73}
74
75/// Returns the component-wise comparison of `|x - y| >= epsilon`.
76///
77/// True if this expression is not satisfied.
78pub fn not_equal_columns_eps_vec<T: Number, const R: usize, const C: usize>(
79    x: &TMat<T, R, C>,
80    y: &TMat<T, R, C>,
81    epsilon: &TVec<T, C>,
82) -> TVec<bool, C> {
83    let mut res = TVec::<_, C>::repeat(false);
84
85    for i in 0..C {
86        res[i] = (x.column(i) - y.column(i)).abs() >= TVec::<_, R>::repeat(epsilon[i])
87    }
88
89    res
90}