OSMServer/Pathfinding/RegionManager.cs

56 lines
2.1 KiB
C#
Raw Normal View History

2023-02-03 23:35:22 +01:00
using OSMDatastructure;
using OSMDatastructure.Graph;
2023-02-03 23:35:22 +01:00
namespace OSMImporter
{
public class RegionManager
{
private string workingDirectory { get; }
private readonly Dictionary<ulong, Region> _regions = new();
2023-02-03 23:35:22 +01:00
public RegionManager(string workingDirectory)
{
this.workingDirectory = workingDirectory;
}
/// <summary>
/// Checks wether the Region is already loaded and returns the Region, or tries to load the Region from file in workingDirectory
/// </summary>
/// <param name="coordinates">Coordinates of the Region (or within the Region) to load</param>
/// <returns>The Region at the specified Coordinates containing Nodes and Connections</returns>
/// <exception cref="FileNotFoundException">If the Regionfile can not be found.</exception>
public Region GetRegion(Coordinates coordinates)
2023-02-03 23:35:22 +01:00
{
if(_regions.ContainsKey(Coordinates.GetRegionHashCode(coordinates)))
return _regions[Coordinates.GetRegionHashCode(coordinates)];
2023-02-03 23:35:22 +01:00
else
{
Region loadedRegion = LoadRegion(coordinates);
_regions.Add(loadedRegion.regionHash, value: loadedRegion);
2023-02-03 23:35:22 +01:00
return loadedRegion;
}
}
public Region[] GetAllRegions()
{
return this._regions.Values.ToArray();
}
/// <summary>
///
/// </summary>
/// <param name="coordinates">Coordinates of the Region (or within the Region) to load</param>
/// <returns>The Region at the specified Coordinates containing Nodes and Connections</returns>
/// <exception cref="FileNotFoundException">If the Regionfile can not be found.</exception>
private Region LoadRegion(Coordinates coordinates)
2023-02-03 23:35:22 +01:00
{
throw new NotImplementedException();
2023-02-03 23:35:22 +01:00
}
2023-02-06 17:32:55 +01:00
public OsmNode? GetNode(Coordinates coordinates)
{
2023-02-06 17:32:55 +01:00
Region regionWithNode = GetRegion(coordinates);
return regionWithNode.GetNode(coordinates);
}
2023-02-03 23:35:22 +01:00
}
}