array_matrix/vector/
div.rs

1use std::ops::Div;
2
3use crate::Vector;
4
5pub trait VDiv<Rhs>: Vector
6where Self::Output: Vector
7{
8    type Output;
9
10    /// Returns the vector-array divided by a scalar
11    /// 
12    /// u/b
13    /// 
14    /// # Arguments
15    /// 
16    /// * `rhs` - A scalar
17    /// 
18    /// # Examples
19    /// 
20    /// ```rust
21    /// let u = [1.0, 2.0];
22    /// let b = 2.0
23    /// let u_b = [u[0]/b, u[1]/b];
24    /// assert_eq!(u.div(b), u_b);
25    /// ```
26    fn div(&self, rhs: Rhs) -> Self::Output;
27}
28
29impl<F, R, const N: usize> VDiv<R> for [F; N]
30where
31    Self: Vector,
32    [<F as Div<R>>::Output; N]: Vector,
33    F: Div<R> + Clone,
34    R: Clone
35{
36    type Output = [<F as Div<R>>::Output; N];
37    fn div(&self, rhs: R) -> Self::Output
38    {
39        array_init::array_init(|i| self[i].clone()/rhs.clone())
40    }
41}