Skip to main content

knearest_into

Function knearest_into 

Source
pub fn knearest_into(
    xyz: &[[f64; 3]],
    simbox: &Cell,
    k: usize,
    mask: Option<&[bool]>,
    cell_hint: Option<f64>,
    out: &mut [i32],
) -> Result<(), Error>
Expand description

Write k-nearest indices, nearest first, into caller storage.

out has length n * k (Error::BufferSize otherwise). Unused slots are -1. Neighbours of source i occupy out[i * k ..]. mask is None or length n (Error::MaskLen otherwise).

use linkcell::{knearest_into, Cell};

let sim = Cell::ortho(10.0, 10.0, 10.0)?;
let xyz = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]];
let mut out = [0; 4];
knearest_into(&xyz, &sim, 2, None, None, &mut out)?;
assert_eq!(out, [1, -1, 0, -1]);