Example #1
0
 /// <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));
 }
Example #2
0
			public void CheckY()
			{
				Position position = new Position(0, 0);
				position = position.SetY(5);
				Assert.AreEqual(5, position.Y);
			}
Example #3
0
			public void CheckX()
			{
				Position position = new Position(0, 0);
				position = position.SetX(5);
				Assert.AreEqual(5, position.X);
			}
Example #4
0
			public void CalculateVertical()
			{
				Position start = new Position(0, 0);
				Position end = new Position(0, 5);
				Assert.AreEqual(5, start.DistanceTo(end));
			}
Example #5
0
			public void CalculateHorizontal()
			{
				Position start = new Position(0, 0);
				Position end = new Position(5, 0);
				Assert.AreEqual(5, start.DistanceTo(end));
			}
Example #6
0
			public void CalculateDiagonal()
			{
				Position start = new Position(0, 0);
				Position end = new Position(3, 4);
				Assert.AreEqual(5, start.DistanceTo(end));
			}