PIBD-14_Boyko_M_S_Cursach_DFS/Cursach/Realisations/Node.cs
2024-05-16 00:37:58 +04:00

67 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProtoBuf;
namespace Cursach.Realisations;
[ProtoContract]
[Serializable]
public class Node()
{
[ProtoMember(1)] private int Id { get; set; }
[ProtoMember(2)] private MyPoint Position { get; set; }
public Node(int id) : this()
{
Id = id;
}
public Node(string name) : this(int.Parse(name.Split("#")[1]))
{
}
public Node(int id, Point position) : this(id)
{
Position = new MyPoint(position);
}
public override bool Equals(object? obj)
{
try
{
return ((obj as Node)!).Id == Id;
}
catch (Exception)
{
return false;
}
}
public override int GetHashCode()
{
return Id;
}
public Point GetPosition()
{
return Position.GetPoint;
}
public override string ToString() => "Вершина #" + Id;
}
[Serializable]
[ProtoContract]
public struct MyPoint(int x, int y)
{
[ProtoMember(1)] public int X = x;
[ProtoMember(2)] public int Y = y;
public MyPoint(Point point) : this(x: point.X, y: point.Y) { }
public Point GetPoint => new(x: X, y: Y);
}