45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
|
namespace Graph;
|
|||
|
|
|||
|
public class Graph
|
|||
|
{
|
|||
|
public readonly Dictionary<ulong, Node> Nodes = new();
|
|||
|
public readonly Dictionary<ulong, Way> Ways = new ();
|
|||
|
|
|||
|
public void ConcatGraph(Graph graph)
|
|||
|
{
|
|||
|
foreach ((ulong id, Node n) in graph.Nodes)
|
|||
|
this.Nodes.TryAdd(id, n);
|
|||
|
foreach ((ulong id, Way w) in graph.Ways)
|
|||
|
this.Ways.TryAdd(id, w);
|
|||
|
}
|
|||
|
|
|||
|
public bool ContainsNode(Node node)
|
|||
|
{
|
|||
|
return Nodes.ContainsValue(node);
|
|||
|
}
|
|||
|
|
|||
|
public bool ContainsNode(ulong nodeId)
|
|||
|
{
|
|||
|
return Nodes.ContainsKey(nodeId);
|
|||
|
}
|
|||
|
|
|||
|
public bool ContainsWay(Way way)
|
|||
|
{
|
|||
|
return Ways.ContainsValue(way);
|
|||
|
}
|
|||
|
|
|||
|
public bool ContainsWay(ulong wayId)
|
|||
|
{
|
|||
|
return Ways.ContainsKey(wayId);
|
|||
|
}
|
|||
|
|
|||
|
public KeyValuePair<ulong, Node> ClosestNodeToCoordinates(float lat, float lon)
|
|||
|
{
|
|||
|
return Nodes.MinBy(n => n.Value.DistanceTo(lat, lon));
|
|||
|
}
|
|||
|
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return $"Graph {Nodes.Count} Nodes {Ways.Count} Ways.";
|
|||
|
}
|
|||
|
}
|