Skip to main content

spatial_edge_lengths

Function spatial_edge_lengths 

Source
pub fn spatial_edge_lengths(
    graph: &Graph,
    coords: &[Vec<f64>],
    metric: DistanceMetric,
) -> IgraphResult<Vec<f64>>
Expand description

Compute edge lengths from spatial vertex coordinates.

Given a graph and a matrix of vertex coordinates (one row per vertex, arbitrary dimensionality), returns a Vec<f64> of length ecount where entry i is the spatial distance between the endpoints of edge i under the chosen metric.

§Errors

  • InvalidArgument if coords.len() != vcount.
  • InvalidArgument if dim == 0 and vcount > 0.

§Examples

use rust_igraph::{Graph, spatial_edge_lengths, DistanceMetric};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();

// 2D coords: (0,0), (3,0), (3,4)
let coords = vec![vec![0.0, 0.0], vec![3.0, 0.0], vec![3.0, 4.0]];
let lengths = spatial_edge_lengths(&g, &coords, DistanceMetric::Euclidean).unwrap();
assert!((lengths[0] - 3.0).abs() < 1e-10);
assert!((lengths[1] - 4.0).abs() < 1e-10);