Skip to main content

Metric

Trait Metric 

Source
pub trait Metric {
    // Required methods
    fn distance_squared(&self, other: &Self) -> f64;
    fn n_dimensions(&self) -> usize;
    fn distance(&self, other: &Self) -> f64;
}
Expand description

Operates on elements on a metric space.

Metric implements a distance metric between points.

Required Methods§

Source

fn distance_squared(&self, other: &Self) -> f64

Compute the squared distance between two vectors belonging to a metric space.

§Example
use hoomd_vector::{Cartesian, Metric};

let x = Cartesian::from([0.0, 1.0, 1.0]);
let y = Cartesian::from([1.0, 0.0, 0.0]);
assert_eq!(3.0, x.distance_squared(&y));
Source

fn n_dimensions(&self) -> usize

Return the number of dimensions in this vector space.

§Example
use hoomd_vector::{Cartesian, Metric};

let vec2 = Cartesian::<2>::default();
let vec3 = Cartesian::<3>::default();
assert_eq!(2, vec2.n_dimensions());
assert_eq!(3, vec3.n_dimensions());
Source

fn distance(&self, other: &Self) -> f64

Compute the distance between two vectors belonging to a metric space.

§Example
use hoomd_vector::{Cartesian, Metric};

let x = Cartesian::from([0.0, 0.0]);
let y = Cartesian::from([3.0, 4.0]);
assert_eq!(5.0, x.distance(&y));

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> Metric for Cartesian<N>