Region no longer contains ways. Ways are Edges added to nodes.
Combined outputfiles into single Regionfile.
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using OSMDatastructure.Graph;
|
||||
|
||||
namespace OSMDatastructure;
|
||||
@ -7,7 +8,6 @@ public class Region
|
||||
{
|
||||
[NonSerialized]public const float RegionSize = 0.1f;
|
||||
public readonly HashSet<OsmNode> nodes = new();
|
||||
public readonly HashSet<OsmEdge> ways = new();
|
||||
public ulong regionHash { get; }
|
||||
public TagManager tagManager { get; }
|
||||
|
||||
@ -23,11 +23,43 @@ public class Region
|
||||
tagManager = new TagManager();
|
||||
}
|
||||
|
||||
public OsmNode? GetNodeWithCoordinates(Coordinates coordinates)
|
||||
public bool ContainsNode(ulong id)
|
||||
{
|
||||
foreach(OsmNode node in this.nodes)
|
||||
if (node.coordinates.Equals(coordinates))
|
||||
return node;
|
||||
return null;
|
||||
return nodes.Any(node => node.nodeId == id);
|
||||
}
|
||||
|
||||
public bool ContainsNode(Coordinates coordinates)
|
||||
{
|
||||
return nodes.Any(node => node.coordinates.Equals(coordinates));
|
||||
}
|
||||
|
||||
public OsmNode? GetNode(ulong id)
|
||||
{
|
||||
if (ContainsNode(id))
|
||||
return nodes.First(node => node.nodeId == id);
|
||||
else return null;
|
||||
}
|
||||
|
||||
public OsmNode? GetNode(Coordinates coordinates)
|
||||
{
|
||||
if (ContainsNode(coordinates))
|
||||
return nodes.First(node => node.coordinates.Equals(coordinates));
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static Region? FromFile(string filePath)
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
#pragma warning disable SYSLIB0011
|
||||
if (File.Exists(filePath))
|
||||
return (Region)bFormatter.Deserialize(new FileStream(filePath, FileMode.Open));
|
||||
#pragma warning restore SYSLIB0011
|
||||
else return null;
|
||||
}
|
||||
|
||||
public static Region? FromId(string path, ulong regionId)
|
||||
{
|
||||
string filePath = Path.Join(path, $"{regionId}.region");
|
||||
return FromFile(filePath);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user