Janilabo

Untitled

Aug 23rd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.97 KB | None | 0 0
  1. procedure TPAClassify(TPA: TPointArray; dist: Integer; var output: T2DPointArray); callconv
  2. var
  3.   h, i, l, c, s, x, y, o: Integer;
  4.   p: T2DIntegerArray;
  5.   q: TPointArray;
  6.   a, b: TBox;
  7. begin
  8.   SetLength(output, 0);
  9.   h := High(TPA);
  10.   if (h > -1) then
  11.   begin
  12.     b := TPABounds(TPA);
  13.     CreateATIA(0, ((b.X2 - b.X1) + 1), ((b.Y2 - b.Y1) + 1), p);
  14.     EnsureRange(dist, 0, Max(((b.X2 - b.X1) + 1), ((b.Y2 - b.Y1) + 1)));
  15.     dist := (dist + 1);
  16.     for i := 0 to h do
  17.       Inc(p[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)]);
  18.     for i := 0 to h do
  19.       if (p[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] > 0) then
  20.       begin
  21.         c := Length(output);
  22.         SetLength(output, (c + 1));
  23.         SetLength(output[c], p[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)]);
  24.         for o := 0 to (p[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] - 1) do
  25.           output[c][o] := TPA[i];
  26.         SetLength(q, 1);
  27.         q[0] := TPA[i];
  28.         p[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := 0;
  29.         s := 1;
  30.         while (s > 0) do
  31.         begin
  32.           s := High(q);
  33.           SetLength(q, s);
  34.           l := High(output[c]);
  35.           a.X1 := (output[c][l].X - dist);
  36.           a.Y1 := (output[c][l].Y - dist);
  37.           a.X2 := (output[c][l].X + dist);
  38.           a.Y2 := (output[c][l].Y + dist);
  39.           BoxConstraint(a, b);
  40.           for x := a.X1 to a.X2 do
  41.             for y := a.Y1 to a.Y2 do
  42.               if (p[(x - b.X1)][(y - b.Y1)] > 0) then
  43.               begin
  44.                 l := Length(output[c]);
  45.                 SetLength(output[c], (l + p[(x - b.X1)][(y - b.Y1)]));
  46.                 for o := 0 to (p[(x - b.X1)][(y - b.Y1)] - 1) do
  47.                 begin
  48.                   output[c][(l + o)].X := x;
  49.                   output[c][(l + o)].Y := y;
  50.                 end;
  51.                 p[(x - b.X1)][(y - b.Y1)] := 0;
  52.                 SetLength(q, (s + 1));
  53.                 q[s] := output[c][l];
  54.                 Inc(s);
  55.               end;
  56.         end;
  57.       end;
  58.   end;
  59. end;
Advertisement
Add Comment
Please, Sign In to add comment