pub fn squared_euclidean<T: Float>(a: &[T], b: &[T]) -> T
Expand description
Returns the squared euclidean distance between two points. When you only need to compare distances, rather than having the exact distance between the points, this metric is benefitial because it avoids the expensive square root computation.
§Examples
use kdtree::distance::squared_euclidean;
assert!(0.0 == squared_euclidean(&[0.0, 0.0], &[0.0, 0.0]));
assert!(2.0 == squared_euclidean(&[0.0, 0.0], &[1.0, 1.0]));
assert!(1.0 == squared_euclidean(&[0.0, 0.0], &[1.0, 0.0]));
§Panics
Only in debug mode, the length of the slices at input will be compared. If they do not match, there will be a panic:
ⓘ
// this is broken
let _ = squared_euclidean(&[0.0, 0.0], &[1.0, 0.0, 0.0]);