/// <summary> /// Get the straight-line distance between two points. /// </summary> /// <param name="origin">Starting point.</param> /// <param name="destination">Ending point.</param> /// <returns></returns> public static double DistanceTo(this Position origin, Position destination) { int xDiff = origin.X - destination.X; int yDiff = origin.Y - destination.Y; double a2 = xDiff * xDiff; double b2 = yDiff * yDiff; return Math.Sqrt(Math.Abs(a2 + b2)); }
public void CheckY() { Position position = new Position(0, 0); position = position.SetY(5); Assert.AreEqual(5, position.Y); }
public void CheckX() { Position position = new Position(0, 0); position = position.SetX(5); Assert.AreEqual(5, position.X); }
public void CalculateVertical() { Position start = new Position(0, 0); Position end = new Position(0, 5); Assert.AreEqual(5, start.DistanceTo(end)); }
public void CalculateHorizontal() { Position start = new Position(0, 0); Position end = new Position(5, 0); Assert.AreEqual(5, start.DistanceTo(end)); }
public void CalculateDiagonal() { Position start = new Position(0, 0); Position end = new Position(3, 4); Assert.AreEqual(5, start.DistanceTo(end)); }