58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using OSMDatastructure.Graph;
|
|
|
|
namespace OSMDatastructure;
|
|
|
|
[Serializable]
|
|
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)
|
|
{
|
|
this.regionHash = regionHash;
|
|
tagManager = new TagManager();
|
|
nodes = new HashSet<OsmNode>();
|
|
}
|
|
|
|
public Region(Coordinates coordinates)
|
|
{
|
|
regionHash = Coordinates.GetRegionHashCode(coordinates);
|
|
tagManager = new TagManager();
|
|
nodes = new HashSet<OsmNode>();
|
|
}
|
|
|
|
public bool ContainsNode(ulong id)
|
|
{
|
|
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)
|
|
{
|
|
return ContainsNode(id) ? nodes.First(node => node.nodeId == id) : null;
|
|
}
|
|
|
|
public OsmNode? GetNode(Coordinates coordinates)
|
|
{
|
|
return ContainsNode(coordinates) ? nodes.First(node => node.coordinates.Equals(coordinates)) : null;
|
|
}
|
|
|
|
} |