Skip to main content

relative_neighborhood_graph

Function relative_neighborhood_graph 

Source
pub fn relative_neighborhood_graph(points: &[Vec<f64>]) -> IgraphResult<Graph>
Expand description

Build the relative neighborhood graph of a point set.

points holds one row per point with a shared, arbitrary dimensionality (inferred from the first row). The result is an undirected Graph on points.len() vertices whose edges are exactly the relatively-neighborly pairs.

This is an O(n²·d) candidate enumeration with an O(n·d) empty-lune test per pair (O(n³·d) overall), which reproduces the reference filter exactly: the RNG is a subgraph of the Delaunay triangulation, so testing every pair yields the same edge set as the reference’s Delaunay-pruned candidate superset.

§Errors

§Examples

use rust_igraph::relative_neighborhood_graph;

// An equilateral triangle: every pair is mutually nearest, and the
// third vertex sits exactly on the open lune's boundary, so all three
// edges survive (the open lune distinguishes the RNG from the closed
// β = 2 skeleton, which would delete them).
let h = 3.0_f64.sqrt() / 2.0;
let pts = vec![vec![0.0, 0.0], vec![1.0, 0.0], vec![0.5, h]];
let g = relative_neighborhood_graph(&pts).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 3); // complete triangle