Skip to main content

knearest_brute

Function knearest_brute 

Source
pub fn knearest_brute(
    xyz: &[[f64; 3]],
    simbox: &Cell,
    k: usize,
    mask: Option<&[bool]>,
) -> Result<Vec<Neighbors>, Error>
Expand description

Brute-force k-nearest. Tests and small systems only.

An orthorhombic box calls crate::dist2_ortho_diffs: SoA differences, one reciprocal per axis, then the Highway wrap dr -= box * round(dr / box). On a rectangular box that wrap is the Euclidean nearest image. Any other box stays on Cell::dist2_euclidean: Smith half-edge test, then a Minkowski-reduced 27-image. A hex-prism body diagonal is a fractional wrap that is not the nearest image.

use linkcell::{knearest, knearest_brute, Cell};

let sim = Cell::ortho(10.0, 10.0, 10.0)?;
let xyz = [[0.2, 0.0, 0.0], [9.4, 0.0, 0.0]];
let cell = knearest(&xyz, &sim, 1, None, None)?;
let brute = knearest_brute(&xyz, &sim, 1, None)?;
assert_eq!(cell[0].indices, brute[0].indices);
assert!((cell[0].dist2[0] - brute[0].dist2[0]).abs() < 1e-12);