Skip to main content

Vector

Trait Vector 

Source
pub trait Vector:
    Add<Self, Output = Self>
    + AddAssign
    + Copy
    + Div<f64, Output = Self>
    + DivAssign<f64>
    + PartialEq
    + Metric
    + Mul<f64, Output = Self>
    + MulAssign<f64>
    + Sub<Self, Output = Self>
    + SubAssign
    + Neg<Output = Self> { }
Expand description

Operate on elements of a metric vector space.

Specifically, Vector defines methods that can be performed on any vector in a metric vector space. Note that this is not an inner product space by default, and calculations requiring an inner product should use the InnerProduct subtrait.

§Vector Operations

The following examples demonstrate vector operations applied to the following vectors:

use hoomd_vector::Cartesian;

let mut a = Cartesian::from([1.0, 2.0]);
let mut b = Cartesian::from([4.0, 8.0]);

Vector addition:

let c = a + b;
assert_eq!(c, [5.0, 10.0].into())
a += b;
assert_eq!(a, [5.0, 10.0].into())

Vector subtraction:

let c = b - a;
assert_eq!(c, [3.0, 6.0].into())
b -= a;
assert_eq!(b, [3.0, 6.0].into())

Multiplication of a vector by a scalar:

let c = a * 2.0;
assert_eq!(c, [2.0, 4.0].into())
a *= 2.0;
assert_eq!(a, [2.0, 4.0].into())

Division of a vector by a scalar:

let c = b / 2.0;
assert_eq!(c, [2.0, 4.0].into())
b /= 2.0;
assert_eq!(b, [2.0, 4.0].into())

Negation:

let mut c = -a;
assert_eq!(c, [-1.0, -2.0].into());

Equality:

assert!(a != b)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const N: usize> Vector for Cartesian<N>