1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Spatial data structures for efficient nearest neighbor search
//!
//! This module provides efficient spatial data structures for nearest neighbor
//! searches, which are fundamental to many interpolation methods. These data
//! structures drastically improve performance for local interpolation techniques
//! that rely on finding nearby points.
//!
//! The implementations include:
//!
//! - **KD-Tree**: A space-partitioning data structure that recursively partitions
//! points along axis-aligned hyperplanes. KD-trees are particularly efficient
//! for low to medium dimensional data (up to about 20 dimensions).
//!
//! - **Ball Tree**: A metric tree that partitions points into nested hyperspheres.
//! Ball trees generally perform better than KD-trees in higher dimensions and
//! for datasets with non-uniform density.
//!
//! These data structures support:
//! - Finding the single nearest neighbor to a query point
//! - Finding the k nearest neighbors to a query point
//! - Finding all points within a specified radius of a query point
//!
//! # When to use which data structure
//!
//! - **KD-Tree**: Best for low to medium dimensional data (2-20 dimensions) with
//! relatively uniform density. Performs well when the number of dimensions is
//! much less than the number of points.
//!
//! - **Ball Tree**: Better for higher dimensional data, datasets with varying density,
//! or when distance computations are expensive. More robust to the "curse of
//! dimensionality."
//!
//! # Examples
//!
//! ```rust
//! use scirs2_core::ndarray::Array2;
//! use scirs2_interpolate::spatial::kdtree::KdTree;
//!
//! // Create sample 2D points
//! let points = Array2::from_shape_vec((5, 2), vec![
//! 0.0, 0.0,
//! 1.0, 0.0,
//! 0.0, 1.0,
//! 1.0, 1.0,
//! 0.5, 0.5,
//! ]).expect("doc example: should succeed");
//!
//! // Build a KD-tree
//! let kdtree = KdTree::new(points).expect("doc example: should succeed");
//!
//! // Find the nearest neighbor to point (0.6, 0.6)
//! let query = vec![0.6, 0.6];
//! let (idx, distance) = kdtree.nearest_neighbor(&query).expect("doc example: should succeed");
//!
//! // Find the 3 nearest neighbors
//! let neighbors = kdtree.k_nearest_neighbors(&query, 3).expect("doc example: should succeed");
//!
//! // Find all points within radius 0.5
//! let points_in_radius = kdtree.points_within_radius(&query, 0.5).expect("doc example: should succeed");
//! ```
pub use BallTree;
pub use ;
pub use KdTree;
pub use ParallelQueryProcessor;
pub use ;
pub use ;