Save direction of edge to neighbor
This commit is contained in:
parent
87d210abe5
commit
2ba8bca590
@ -1,8 +1,8 @@
|
||||
namespace Graph;
|
||||
|
||||
public class Node(float lat, float lon, Dictionary<ulong, ulong>? neighbors = null)
|
||||
public class Node(float lat, float lon, Dictionary<ulong, KeyValuePair<ulong, bool>>? neighbors = null)
|
||||
{
|
||||
public readonly Dictionary<ulong, ulong> Neighbors = neighbors??new(); //nodeId, wayId
|
||||
public readonly Dictionary<ulong, KeyValuePair<ulong, bool>> Neighbors = neighbors??new(); //nodeId, wayId, forward
|
||||
public readonly float Lat = lat, Lon = lon;
|
||||
|
||||
public double DistanceTo(Node n2) => Utils.NodeUtils.DistanceBetween(this, n2);
|
||||
|
@ -3,13 +3,13 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace OSM_Graph;
|
||||
|
||||
public class Node(ulong id, float lat, float lon, Dictionary<ulong, ulong>? neighbors = null) : Graph.Node(lat, lon, neighbors), IOSMSerializable<Node>
|
||||
public class Node(ulong id, float lat, float lon, Dictionary<ulong, KeyValuePair<ulong, bool>>? neighbors = null) : Graph.Node(lat, lon, neighbors), IOSMSerializable<Node>
|
||||
{
|
||||
public readonly ulong ID = id;
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
return $"{this.ID}#{this.Lat.ToString(CultureInfo.InvariantCulture)}#{this.Lon.ToString(CultureInfo.InvariantCulture)}#{string.Join(',', this.Neighbors.Select(n => $"{n.Key}-{n.Value}"))}";
|
||||
return $"{this.ID}#{this.Lat.ToString(CultureInfo.InvariantCulture)}#{this.Lon.ToString(CultureInfo.InvariantCulture)}#{string.Join(',', this.Neighbors.Select(n => $"{n.Key}-{n.Value.Key}-{n.Value.Value}"))}";
|
||||
}
|
||||
|
||||
public static Node Deserialize(string serialized)
|
||||
@ -22,9 +22,11 @@ public class Node(ulong id, float lat, float lon, Dictionary<ulong, ulong>? neig
|
||||
ulong id = ulong.Parse(parts[0]);
|
||||
float lat = float.Parse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture);
|
||||
float lon = float.Parse(parts[2], NumberStyles.Float, CultureInfo.InvariantCulture);
|
||||
Dictionary<ulong, ulong> neighbors = parts[3].Length > 3
|
||||
? parts[3].Split(',').ToDictionary(str => ulong.Parse(str.Split('-')[0]), str => ulong.Parse(str.Split('-')[1]))
|
||||
: new();
|
||||
Dictionary<ulong, KeyValuePair<ulong, bool>> neighbors = parts[3].Length > 3
|
||||
? parts[3].Split(',').ToDictionary(str => ulong.Parse(str.Split('-')[0]),
|
||||
str => new KeyValuePair<ulong, bool>(ulong.Parse(str.Split('-')[1]),
|
||||
bool.Parse(str.Split('-')[2])))
|
||||
: new();
|
||||
|
||||
return new Node(id, lat, lon, neighbors);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user