Guest User

Untitled

a guest
Jan 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1.         public Point[] GenerateDiagonalLine(Point dest)
  2.         {
  3.             if (dest.X == Location.X || dest.Y == Location.Y)
  4.             {
  5.                 return null;
  6.             }
  7.             var rise = Location.Y - dest.Y;
  8.             var run = Location.X - dest.X;
  9.             if (rise / run != 1 && run / rise != -1)
  10.             {
  11.                 return null;
  12.             }
  13.             var lower = Location.Y < dest.Y ? Location.Y : dest.Y;
  14.             var upper = Location.Y < dest.Y ? dest.Y : Location.Y;
  15.             var dx = Location.X < dest.X ? 1 : -1;
  16.             var dy = Location.Y < dest.Y ? 1 : -1;
  17.             var pl = new List<Point>();
  18.             var cx = dest.X - Location.X;// Location.X < dest.X ? dest.X - Location.X : Location.X - dest.X;
  19.             var cy = Location.Y < dest.Y ? dest.Y - Location.Y : Location.Y - dest.Y;
  20.             System.Diagnostics.Debug.Print("Location " + Location + " " + dest);
  21.             for (var i = lower + 1; i < upper; i++)
  22.             {
  23.                 pl.Add(new Point(cx, i - 1));
  24.                 cx += dx;
  25.                 //cy += dy;
  26.             }
  27.             return pl.ToArray();
  28.         }
Add Comment
Please, Sign In to add comment