OSMServer/OSMDatastructure/Graph/OsmNode.cs
2023-04-20 23:02:38 +02:00

45 lines
1.1 KiB
C#

using System.Text.Json.Serialization;
namespace OSMDatastructure.Graph;
[Serializable]
public class OsmNode
{
public ulong nodeId { get; }
public HashSet<OsmEdge> edges { get; set; }
public Coordinates coordinates { get; }
public OsmNode(ulong nodeId, float lat, float lon)
{
this.nodeId = nodeId;
edges = new();
coordinates = new Coordinates(lat, lon);
}
[JsonConstructor]
public OsmNode(ulong nodeId, Coordinates coordinates)
{
this.nodeId = nodeId;
edges = new();
this.coordinates = coordinates;
}
public OsmEdge? GetEdgeToNode(OsmNode n)
{
HashSet<OsmEdge> e = edges.Where(edge => edge.neighborId == n.nodeId).ToHashSet();
if (e.Count > 0)
return e.First();
return null;
}
public override bool Equals(object? obj)
{
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
}
public override string ToString()
{
return $"{nodeId} {coordinates} ec:{edges.Count}";
}
}