pub trait RailwayGraphExt {
    // Required methods
    fn get_edge_by_id(&self, id: EdgeId) -> Option<RailwayEdge>;
    fn get_node_by_id(&self, id: NodeId) -> Option<&RailwayNode>;
    fn railway_edge(
        &self,
        start_node_id: NodeId,
        end_node_id: NodeId
    ) -> Option<&RailwayEdge>;
    fn get_edges_of_node(&self, node_id: NodeId) -> Vec<&RailwayEdge>;
    fn bounding_box(&self) -> (Coord, Coord);
    fn total_length(&self) -> f64;
    fn nearest_node(
        &self,
        edge_id: EdgeId,
        position_on_edge: f64,
        current_node_id: Option<NodeId>
    ) -> Option<NodeId>;
}
Expand description

An extension trait for the RailwayGraph.

Required Methods§

source

fn get_edge_by_id(&self, id: EdgeId) -> Option<RailwayEdge>

Retrieve an edge from the graph by its ID.

Arguments
  • id - The ID of the edge to be retrieved.
Returns

An Option<RailwayEdge> that contains the edge if found, or None if not found.

source

fn get_node_by_id(&self, id: NodeId) -> Option<&RailwayNode>

Returns a reference to a RailwayNode with the specified NodeId if it exists in the graph.

This method searches the railway graph for a node with the given NodeId. If the node is found, it returns a reference to the RailwayNode. If the node is not found, it returns None.

Arguments
  • id - The NodeId of the node to be retrieved from the railway graph.
Returns

An Option containing a reference to the RailwayNode if it exists, otherwise None.

source

fn railway_edge( &self, start_node_id: NodeId, end_node_id: NodeId ) -> Option<&RailwayEdge>

Retrieve the railway edge between two nodes.

Arguments
  • start_node_id - The ID of the starting node.
  • end_node_id - The ID of the ending node.
Returns

An Option<&RailwayEdge> that contains the railway edge connecting the two nodes if it exists, or None if no such edge exists.

source

fn get_edges_of_node(&self, node_id: NodeId) -> Vec<&RailwayEdge>

Retrieve the edges connected to a node by its ID.

Arguments
  • node_id - The ID of the node whose edges are to be retrieved.
Returns

A Vec<&RailwayEdge> containing the edges connected to the node, or an empty vector if the node is not found.

source

fn bounding_box(&self) -> (Coord, Coord)

Calculate the bounding box of the graph.

The bounding box is represented as a tuple containing the minimum and maximum latitude and longitude values of the nodes in the graph.

Returns

A tuple containing two Coordinate structs representing the minimum and maximum coordinates of the bounding box of the graph.

source

fn total_length(&self) -> f64

Calculate the total length of the railway network.

The total length is the sum of the lengths of all edges in the graph.

Returns

A f64 value representing the total length of the railway network in meters.

source

fn nearest_node( &self, edge_id: EdgeId, position_on_edge: f64, current_node_id: Option<NodeId> ) -> Option<NodeId>

Returns the nearest node to the given position on the specified edge.

Arguments
  • edge_id - The ID of the edge.
  • position_on_edge - The position on the edge, ranging from 0.0 to 1.0.
  • current_node_id - An optional NodeId of the current node to determine the start node.
Returns

An Option<NodeId> containing the ID of the nearest node if found, or None if the edge is not found.

Implementors§