using System.Xml.Serialization;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Collections.Generic;
namespace DrawGraph
{
public class Node
{
[XmlAttribute("positionX")]
public int X { get; set; }
[XmlAttribute("positionY")]
public int Y { get; set; }
public Node(int x, int y)
{
X = x;
Y = y;
}
///
/// Get center X-coordinate of node
///
public int CenterByX => (X * 2 + (Settings.NodeWidth/2)) / 2;
///
/// Get center Y-coordinate of node
///
public int CenterByY => (Y * 2 + (Settings.NodeHeight / 2)) / 2;
///
/// Compare two nodes
///
/// First node to compare
/// Second node to compare
/// True if nodes are equal, false if not equal
public static bool Compare(Node node1, Node node2)
{
if (Equals(node1, node2))
return true;
if (node1 == node2)
return true;
if (node1.X == node2.X && node1.Y == node2.Y)
return true;
return false;
}
///
/// Compare nodes and returns true if they are overlaid
///
///
///
/// True if overlaid, false if not
public static bool IsNodeOverlaid(Node node1, Node node2)
{
var x = node1.X - node2.X;
var y = node1.Y - node2.Y;
if(x<=Settings.NodeWidth/2 && x>=0)
if (y <= Settings.NodeHeight / 2 && y > 0)
return true;
x = node2.X - node1.X;
y = node2.Y - node1.Y;
if (x <= Settings.NodeWidth / 2 && x >= 0)
if (y <= Settings.NodeHeight / 2 && y > 0)
return true;
return false;
}
}
}