Skip to content

RustedBytes/nanoflann

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nanoflann

Crates.io Version

A safe Rust KD-tree crate ported from the nanoflann.hpp project.

This is not a line-by-line syntax translation. It keeps the behaviorally important pieces of the C++ API while replacing raw pointers, pooled allocation, output buffers, and template-heavy result sets with safe Rust ownership and Result-based errors.

Implemented

  • Static KD-tree over an adaptor-style dataset trait.
  • PointCloud and flat MatrixDataset adaptors.
  • L1, squared L2, L2-simple, SO2, and SO3 metrics.
  • KNN, radius search, radius-limited KNN, and inclusive bounding-box search.
  • Dynamic logarithmic multi-tree wrapper with lazy deletion and reactivation.
  • Portable save/load of the index structure. As in nanoflann, data points are not serialized.
  • Integration tests comparing searches with brute force and checking edge semantics.

Example

use nanoflann::{KdTree, KdTreeParams, L2, PointCloud};

fn main() -> nanoflann::Result<()> {
    let cloud = PointCloud::new(vec![
        vec![0.0, 0.0],
        vec![1.0, 0.0],
        vec![0.0, 2.0],
    ])?;

    let tree = KdTree::new(2, &cloud, L2, KdTreeParams::default())?;
    let nearest = tree.knn_search(&[0.9, 0.1], 1)?;
    assert_eq!(nearest[0].index, 1);
    Ok(())
}

Validation

cargo test
cargo fmt
cargo +nightly clippy --all-targets --all-features -- -D warnings

Benchmarking

cargo bench

About

Safe Rust KD-tree port inspired by nanoflann's adaptor API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages