44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
namespace OSMImporter
|
|
{
|
|
public class Node : Coordinates
|
|
{
|
|
private readonly HashSet<Connection> _connections = new HashSet<Connection>();
|
|
|
|
public Node(float lat, float lon) : base(lat, lon)
|
|
{
|
|
|
|
}
|
|
|
|
public void AddConnection(Connection connection)
|
|
{
|
|
this._connections.Add(connection);
|
|
}
|
|
|
|
public Connection[] GetConnections()
|
|
{
|
|
return this._connections.ToArray();
|
|
}
|
|
|
|
/*
|
|
* Returns byte array in order:
|
|
* Value 1: Latitude (4bytes)
|
|
* Value 2: Longitude (4bytes)
|
|
* Value 3: Connections-Count (1 byte)
|
|
* Value x: Connection (8bytes) //TODO
|
|
*/
|
|
public byte[] ToByte()
|
|
{
|
|
float[] coords = { this.lat, this.lon };
|
|
byte[] ret = new byte[sizeof(float) * coords.Length + 1 + _connections.Count * sizeof(ulong)];
|
|
Buffer.BlockCopy(coords, 0, ret, 0, sizeof(float) * coords.Length );
|
|
byte countConnections = Convert.ToByte(_connections.Count);
|
|
Connection[] conns = this._connections.ToArray();
|
|
for (int i = 0; i < conns.Length; i++)
|
|
{
|
|
byte[] connection = conns[i].ToByte();
|
|
Buffer.BlockCopy(connection, 0, ret, sizeof(float) * coords.Length + 1 + i * connection.Length, connection.Length);
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
} |