OSMServer/OSMDatastructure/Graph/OsmNode.cs

45 lines
1.1 KiB
C#
Raw Normal View History

using System.Text.Json.Serialization;
namespace OSMDatastructure.Graph;
2023-02-06 17:32:55 +01:00
[Serializable]
2023-02-07 23:52:23 +01:00
public class OsmNode
2023-02-06 17:32:55 +01:00
{
public ulong nodeId { get; }
public HashSet<OsmEdge> edges { get; set; }
public Coordinates coordinates { get; }
public OsmNode(ulong nodeId, float lat, float lon)
2023-02-06 17:32:55 +01:00
{
this.nodeId = nodeId;
2023-04-20 23:02:38 +02:00
edges = new();
coordinates = new Coordinates(lat, lon);
2023-02-06 17:32:55 +01:00
}
[JsonConstructor]
public OsmNode(ulong nodeId, Coordinates coordinates)
2023-02-06 17:32:55 +01:00
{
this.nodeId = nodeId;
2023-04-20 23:02:38 +02:00
edges = new();
2023-02-07 23:52:23 +01:00
this.coordinates = coordinates;
2023-02-06 17:32:55 +01:00
}
public OsmEdge? GetEdgeToNode(OsmNode n)
2023-02-06 17:32:55 +01:00
{
HashSet<OsmEdge> e = edges.Where(edge => edge.neighborId == n.nodeId).ToHashSet();
if (e.Count > 0)
return e.First();
2023-04-20 23:02:38 +02:00
return null;
2023-02-06 17:32:55 +01:00
}
public override bool Equals(object? obj)
{
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
}
public override string ToString()
{
return $"Node id:{nodeId} coordinates:{coordinates} edges-count:{edges.Count}";
}
2023-02-06 17:32:55 +01:00
}