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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use serde::Serialize;
use crate::error::Error;
pub use h3edge::{H3EdgeGraph, H3EdgeGraphBuilder};
use h3ron::{H3Cell, H3DirectedEdge};
use node::NodeType;
pub use prepared::PreparedH3EdgeGraph;
use crate::graph::longedge::LongEdge;
pub mod h3edge;
pub mod longedge;
pub mod modifiers;
pub mod node;
pub mod prepared;
#[derive(Serialize)]
pub struct GraphStats {
pub h3_resolution: u8,
pub num_nodes: usize,
pub num_edges: usize,
}
pub trait GetStats {
fn get_stats(&self) -> Result<GraphStats, Error>;
}
pub trait GetCellNode {
fn get_cell_node(&self, cell: &H3Cell) -> Option<NodeType>;
}
pub trait IterateCellNodes<'a> {
type CellNodeIterator;
fn iter_cell_nodes(&'a self) -> Self::CellNodeIterator;
}
pub trait GetCellEdges {
type EdgeWeightType;
#[allow(clippy::complexity)]
fn get_edges_originating_from(
&self,
cell: &H3Cell,
) -> Result<Vec<(H3DirectedEdge, EdgeWeight<Self::EdgeWeightType>)>, Error>;
}
pub trait GetEdge {
type EdgeWeightType;
fn get_edge(
&self,
edge: &H3DirectedEdge,
) -> Result<Option<EdgeWeight<Self::EdgeWeightType>>, Error>;
}
impl<G> GetEdge for G
where
G: GetCellEdges,
{
type EdgeWeightType = G::EdgeWeightType;
fn get_edge(
&self,
edge: &H3DirectedEdge,
) -> Result<Option<EdgeWeight<Self::EdgeWeightType>>, Error> {
let cell = edge.origin_cell()?;
for (found_edge, value) in self.get_edges_originating_from(&cell)? {
if edge == &found_edge {
return Ok(Some(value));
}
}
Ok(None)
}
}
#[derive(Clone)]
pub struct EdgeWeight<'a, W> {
pub weight: W,
pub longedge: Option<(&'a LongEdge, W)>,
}
impl<'a, W> From<W> for EdgeWeight<'a, W> {
fn from(weight: W) -> Self {
EdgeWeight {
weight,
longedge: None,
}
}
}