2023-04-06 01:29:30 +02:00
|
|
|
using System.Text.Json.Serialization;
|
2023-04-01 14:42:49 +02:00
|
|
|
|
2023-03-14 17:00:59 +01:00
|
|
|
namespace OSMDatastructure.Graph;
|
2023-02-06 17:32:55 +01:00
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
[Serializable]
|
2023-02-07 23:52:23 +01:00
|
|
|
public class OsmNode
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
public ulong nodeId { get; }
|
2023-04-06 01:29:30 +02:00
|
|
|
public HashSet<OsmEdge> edges { get; set; }
|
2023-04-11 01:04:19 +02:00
|
|
|
public Coordinates coordinates { get; }
|
2023-04-01 14:42:49 +02:00
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
public OsmNode(ulong nodeId, float lat, float lon)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02: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
|
|
|
}
|
|
|
|
|
2023-04-06 01:29:30 +02:00
|
|
|
[JsonConstructor]
|
2023-03-30 18:24:57 +02:00
|
|
|
public OsmNode(ulong nodeId, Coordinates coordinates)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-03-30 18:24:57 +02: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
|
|
|
}
|
|
|
|
|
2023-04-01 01:47:56 +02:00
|
|
|
public OsmEdge? GetEdgeToNode(OsmNode n)
|
2023-02-06 17:32:55 +01:00
|
|
|
{
|
2023-04-01 14:42:49 +02: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
|
|
|
}
|
2023-02-08 18:08:01 +01:00
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
{
|
2023-03-30 18:24:57 +02:00
|
|
|
return obj != null && obj.GetType() == this.GetType() && ((OsmNode)obj).nodeId == this.nodeId;
|
2023-02-08 18:08:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2023-05-17 19:14:36 +02:00
|
|
|
return $"Node id:{nodeId} coordinates:{coordinates} edges-count:{edges.Count}";
|
2023-02-08 18:08:01 +01:00
|
|
|
}
|
2023-02-06 17:32:55 +01:00
|
|
|
}
|