AStar/Graph/Graph.cs

84 lines
1.6 KiB
C#
Raw Normal View History

2022-11-13 14:02:27 +01:00

namespace Graph
{
public class Graph
{
private List<Node> nodes { get; }
2022-11-13 14:02:27 +01:00
public Graph()
{
this.nodes = new();
}
public bool AddNode(Node n)
{
if (!this.ContainsNode(n.id))
{
this.nodes.Add(n);
return true;
}
else
{
return false;
}
}
public Node GetNodeAtIndex(int i)
{
return this.nodes[i];
}
public int GetNodeCount()
{
return this.nodes.Count;
}
2022-11-13 14:02:27 +01:00
public Node? GetNode(ulong id)
{
foreach(Node n in this.nodes)
{
if (n.id == id)
return n;
}
return null;
}
public bool ContainsNode(ulong id)
{
return this.GetNode(id) != null;
}
public bool RemoveNode(ulong id)
{
Node? n = this.GetNode(id);
if(n != null)
{
this.nodes.Remove(n);
return true;
}
else
{
return false;
}
}
public bool RemoveNode(Node n)
{
if (this.RemoveNode(n.id))
{
this.nodes.Remove(n);
return true;
}
else
{
return false;
}
}
public Node ClosestNodeToCoordinates(float lat, float lon)
{
throw new NotImplementedException();
}
}
}