ndarray_cg/vector/
arithmetics.rs

1/// Internal namespace.
2mod private
3{
4  use crate::*;
5  use vector::arithmetics::inner_product::*;
6
7  impl< E : MatEl + NdFloat, const LEN : usize > Vector< E, LEN >
8  {
9    /// Normalizes the vector
10    pub fn normalize( self ) -> Self
11    {
12      normalized( &self )
13    }
14
15    /// Compute the length of the vector
16    pub fn mag( &self ) -> E
17    {
18      mag( self )
19    }
20
21    /// Computer the squared length of the vector
22    pub fn mag2( &self ) -> E
23    {
24      mag2( self )
25    }
26
27    /// Compute a vector, whose elements are minimum of both vectors: `r[ i ] = a[ i ].min( b [ i ] )`
28    pub fn min( self, rhs : Self ) -> Self
29    {
30      min( &self, &rhs )
31    }
32
33    /// Compute a vector, whose elements are maximum of both vectors: `r[ i ] = a[ i ].max( b [ i ] )`
34    pub fn max( self, rhs : Self ) -> Self
35    {
36      max( &self, &rhs )
37    }
38
39    /// Computes length of the vector between two points in space
40    pub fn distance( &self, rhs: &Self ) -> E
41    {
42      ( rhs - self ).mag()
43    }
44
45    /// Computes squared length of the vector between two points in space
46    pub fn distance_squared( &self, rhs: &Self ) -> E
47    {
48      ( rhs - self ).mag2()
49    }
50  }
51
52}
53
54crate::mod_interface!
55{
56  own use ::mdmath_core::vector::inner_product;
57
58  /// Mul trait implementations
59  layer mul;
60  /// Sub trait implementations
61  layer sub;
62  /// Add trait implementations
63  layer add;
64  /// Div trait implementations
65  layer div;
66}