OSMServer/OSMDatastructure/Region.cs

62 lines
1.6 KiB
C#
Raw Normal View History

using System.Text.Json;
using System.Text.Json.Serialization;
using OSMDatastructure.Graph;
2023-02-06 17:32:55 +01:00
namespace OSMDatastructure;
2023-02-02 22:30:43 +01:00
[Serializable]
2023-02-06 17:32:55 +01:00
public class Region
{
[JsonIgnore]public const float RegionSize = 0.025f;
[JsonIgnore]public static readonly JsonSerializerOptions serializerOptions = new()
{
IncludeFields = true,
MaxDepth = 32,
IgnoreReadOnlyFields = false//,
//WriteIndented = true
};
[JsonRequired]public HashSet<OsmNode> nodes { get; set; }
public ulong regionHash { get; }
[JsonRequired]public TagManager tagManager { get; set; }
[JsonConstructor]
public Region(ulong regionHash)
2023-02-06 17:32:55 +01:00
{
this.regionHash = regionHash;
tagManager = new TagManager();
nodes = new HashSet<OsmNode>();
2023-02-06 17:32:55 +01:00
}
public Region(Coordinates coordinates)
2023-02-06 17:32:55 +01:00
{
regionHash = Coordinates.GetRegionHashCode(coordinates);
tagManager = new TagManager();
nodes = new HashSet<OsmNode>();
2023-02-06 17:32:55 +01:00
}
public bool ContainsNode(ulong id)
2023-02-06 17:32:55 +01:00
{
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;
}
2023-02-02 22:30:43 +01:00
}