2023-02-03 21:13:51 +01:00
|
|
|
namespace OSMDatastructure
|
2023-02-02 22:30:43 +01:00
|
|
|
{
|
|
|
|
public class Region
|
|
|
|
{
|
2023-02-05 20:02:22 +01:00
|
|
|
public const float regionSize = 0.01f; //For Splitting
|
2023-02-03 21:13:51 +01:00
|
|
|
private readonly Dictionary<ulong, Node> _nodesInRegion = new();
|
2023-02-02 22:30:43 +01:00
|
|
|
public ulong regionHash { get; }
|
|
|
|
|
2023-02-03 23:34:51 +01:00
|
|
|
public Region(Coordinates regionCoordinates)
|
2023-02-02 22:30:43 +01:00
|
|
|
{
|
2023-02-03 23:34:51 +01:00
|
|
|
this.regionHash = regionCoordinates.GetRegionHash();
|
2023-02-02 22:30:43 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 23:34:51 +01:00
|
|
|
public Region(ulong nodeId, Node firstNode)
|
2023-02-02 22:30:43 +01:00
|
|
|
{
|
2023-02-03 23:34:51 +01:00
|
|
|
this.regionHash = firstNode.GetRegionHash();
|
2023-02-02 22:30:43 +01:00
|
|
|
this._nodesInRegion.Add(nodeId, value: firstNode);
|
|
|
|
}
|
|
|
|
|
2023-02-03 21:13:51 +01:00
|
|
|
public Region(ulong regionHash)
|
|
|
|
{
|
|
|
|
this.regionHash = regionHash;
|
|
|
|
}
|
|
|
|
|
2023-02-02 22:30:43 +01:00
|
|
|
public void AddNode(ulong nodeId, Node node)
|
|
|
|
{
|
|
|
|
this._nodesInRegion.Add(nodeId, value: node);
|
|
|
|
}
|
|
|
|
|
2023-02-03 00:02:04 +01:00
|
|
|
public Dictionary<ulong, Node> GetNodes()
|
2023-02-02 22:30:43 +01:00
|
|
|
{
|
2023-02-03 00:02:04 +01:00
|
|
|
return this._nodesInRegion;
|
2023-02-02 22:30:43 +01:00
|
|
|
}
|
2023-02-03 21:13:51 +01:00
|
|
|
|
2023-02-03 23:34:51 +01:00
|
|
|
public Node? GetNode(ulong id)
|
|
|
|
{
|
|
|
|
return this._nodesInRegion.ContainsKey(id) ? this._nodesInRegion[id] : null;
|
|
|
|
}
|
2023-02-05 20:02:22 +01:00
|
|
|
|
|
|
|
public Node? GetNode(Coordinates coordinates)
|
|
|
|
{
|
|
|
|
foreach (Node node in this._nodesInRegion.Values)
|
|
|
|
{
|
|
|
|
if (node.Equals(coordinates))
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-02 22:30:43 +01:00
|
|
|
}
|
|
|
|
}
|