use super::knn_within;
use crate::{KnnOptions, KnnResult, PeriodicBox, SpatialBackend, SpatialError};
use molframe_core::{AtomSelection, ExecutionContext};
pub fn knn_between(
targets: &[[f32; 3]],
queries: &[[f32; 3]],
k: usize,
options: KnnOptions,
backend: SpatialBackend,
periodic: Option<&PeriodicBox>,
context: &ExecutionContext,
) -> Result<KnnResult, SpatialError> {
let total = targets
.len()
.checked_add(queries.len())
.and_then(|total| u32::try_from(total).ok())
.ok_or(SpatialError::AtomOutOfBounds(u32::MAX))?;
let split =
u32::try_from(targets.len()).map_err(|_| SpatialError::AtomOutOfBounds(u32::MAX))?;
let mut joined = Vec::with_capacity(targets.len() + queries.len());
joined.extend_from_slice(targets);
joined.extend_from_slice(queries);
knn_within(
&joined,
&AtomSelection::range(split..total),
&AtomSelection::range(0..split),
k,
options,
backend,
periodic,
context,
)
}