Janilabo

Untitled

Aug 9th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.52 KB | None | 0 0
  1. {==============================================================================]
  2.  @action: Keeps only corner points in TPA.
  3.  @note: None
  4.  @contributors: Janilabo, slacky
  5. [==============================================================================}
  6. procedure TPACorners(var TPA: TPointArray); callconv
  7. var
  8.   x, y, h, r, i: Integer;
  9.   C: T2DIntegerArray;
  10.   bx: TBox;
  11.   up, down, left, right, topLeft, topRight, bottomLeft, bottomRight: Boolean;
  12. begin;
  13.   h := High(TPA);
  14.   if (h > 0) then
  15.   begin
  16.     r := 0;
  17.     bx := TPABounds(TPA);
  18.     BoxExpand(bx);
  19.     CreateATIA(0, ((bx.X2 - bx.X1) + 1), ((bx.Y2 - bx.Y1) + 1), C);
  20.     for i := 0 to h do
  21.       Inc(C[(TPA[i].X - bx.X1)][(TPA[i].Y - bx.Y1)]);
  22.     for y := 0 to (bx.Y2 - bx.Y1) do
  23.       for x := 0 to (bx.X2 - bx.X1) do
  24.         if (C[x][y] > 0) then
  25.         begin    
  26.           topLeft := (C[(x - 1)][(y - 1)] > 0);
  27.           up := (C[x][(y - 1)] > 0);
  28.           topRight := (c[(x + 1)][(y - 1)] > 0);
  29.           left := (c[(x - 1)][y] > 0);
  30.           right := (c[(x + 1)][y] > 0);
  31.           bottomLeft := (c[(x - 1)][(y + 1)] > 0);
  32.           down := (c[x][(y + 1)] > 0);
  33.           bottomRight := (c[(x + 1)][(y + 1)] > 0);
  34.           if not ((topLeft and bottomRight) or (up and down) or (topRight and bottomLeft) or (left and right)) then
  35.           begin
  36.             for i := 0 to (C[x][y] - 1) do
  37.               TPA[(r + i)] := Point((x + bx.X1), (y + bx.Y1));
  38.             r := (r + C[x][y]);
  39.           end;
  40.         end;
  41.     SetLength(TPA, r);
  42.   end;
  43. end;
Advertisement
Add Comment
Please, Sign In to add comment