Advertisement
Janilabo

diag3

Nov 21st, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.29 KB | None | 0 0
  1. function TPAFromBoxDiagonal(bx: TBox; startCorner: Integer): TPointArray;
  2. var
  3.   x, y, z, l, j, r, w, h, e, o, s, n: Integer;
  4.   c: TPoint;
  5. begin
  6.   l := pp_BoxSize(bx);
  7.   SetLength(Result, l);
  8.   if (l > 0) then
  9.   begin
  10.     s := startCorner;
  11.     pp_EnsureRange(s, 0, 3);
  12.     pp_BoxDimensions(bx, w, h);
  13.     z := ((bx.X1 + h) - 1);
  14.     if ((s = 1) or (s = 4)) then
  15.       c := Point(bx.X2, bx.Y1)
  16.     else
  17.       c := Point(bx.X1, bx.Y1);
  18.     r := 0;
  19.     e := 0;
  20.     o := 0;
  21.     j := 0;
  22.     n := -1;
  23.     case s of
  24.       0: // TOP-LEFT
  25.       repeat
  26.         if (c.X > z) then
  27.           e := (c.X - z);
  28.         if (c.X > bx.X2) then
  29.           o := (c.X - bx.X2);
  30.         y := (bx.Y1 + o);
  31.         for x := (c.X - o) downto (bx.X1 + e) do
  32.         begin
  33.           Result[r] := Point(x, y);
  34.           if (y < bx.Y2) then
  35.             y := (y + 1);
  36.           r := (r + 1);
  37.         end;
  38.         c.X := (c.X + 1);
  39.       until (c.X > (bx.X2 + h));
  40.       1: // TOP-RIGHT
  41.       repeat
  42.         if (c.X < bx.X1) then
  43.           o := (o + 1);
  44.         y := (bx.Y1 + o);
  45.         for x := (c.X + o) to (bx.X2 - e) do
  46.         begin
  47.           Result[r] := Point(x, y);
  48.           if (y < bx.Y2) then
  49.             y := (y + 1);
  50.           r := (r + 1);
  51.         end;
  52.         c.X := (c.X - 1);
  53.         if ((bx.X2 - c.X) > (h - 1)) then
  54.           e := (e + 1);
  55.       until (r >= l);
  56.       2: // BOTTOM-LEFT
  57.       repeat
  58.         if (c.X > bx.X2) then
  59.           o := (c.X - bx.X2);
  60.         if (c.X > z) then
  61.           e := (c.X - z)
  62.         else
  63.           n := (n + 1);
  64.         y := (bx.Y2 - n);
  65.         for x := (bx.X1 + e) to (c.X - o) do
  66.         begin
  67.           Result[r] := Point(x, y);
  68.           if (y < bx.Y2) then
  69.             y := (y + 1);
  70.           r := (r + 1);
  71.         end;
  72.         c.X := (c.X + 1);
  73.       until (c.X > (bx.X2 + h));
  74.       3: // BOTTOM-RIGHT
  75.       repeat
  76.         if (c.X < (bx.X2 - h)) then
  77.           o := (o + 1);
  78.         y := (bx.Y2 - o);
  79.         for x := (c.X + o) to (bx.X2 - e) do
  80.         begin
  81.           Result[r] := Point(x, y);
  82.           if (y > bx.Y2) then
  83.             y := (y + 1);
  84.           r := (r + 1);
  85.         end;
  86.         c.X := (c.X - 1);
  87.         if ((bx.X2 - c.X) > (h - 1)) then
  88.           e := (e + 1);
  89.       until (r >= l);
  90.     end;
  91.   end;
  92. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement