Janilabo

Untitled

Sep 13th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.25 KB | None | 0 0
  1. function CleanAndSortTPA(TPA: TPointArray): TPointArray;
  2. var
  3.   Matrix: array of TBoolArray;
  4.   i, c, H, j, idx, x, y: Integer;
  5.   area: TBox;
  6. begin
  7.   area := GetTPABounds(TPA);
  8.   H := High(TPA);
  9.   SetLength(Matrix, ((area.Y2 - area.Y1) + 1));
  10.   for i := 0 to (area.Y2 - area.Y1) do
  11.     SetLength(Matrix[i], ((area.X2 - area.X1) + 1));
  12.   C := 0;
  13.   for i :=0 to H do
  14.   begin
  15.     if Matrix[(TPA[i].y - area.X1)][(TPA[i].x - area.Y1)] then
  16.       Continue;
  17.     Matrix[(TPA[i].y - area.X1)][(TPA[i].x - area.Y1)] := True;
  18.     Inc(C);
  19.   end;
  20.   SetLength(Result, C);
  21.   idx := 0;
  22.   for x := area.X1 to area.X2 do
  23.     for y := area.Y1 to area.Y2 do
  24.       if Matrix[(y - area.X1)][(x - area.Y1)] then
  25.       begin
  26.         Result[idx] := Point(x, y);
  27.         Inc(idx);
  28.         if (idx >= C) then
  29.           Exit;
  30.       end;
  31. end;
  32.  
  33. function RandomTPA(Amount:Integer; MinX,MinY,MaxX,MaxY:Integer): TPointArray;
  34. var i:Integer;
  35. begin
  36.   SetLength(Result, Amount+1);
  37.   for i:=0 to Amount do
  38.   begin
  39.     Result[i] := Point(RandomRange(MinX, MaxX), RandomRange(MinY, MaxY));
  40.   end;
  41. end;
  42.  
  43. var
  44.   a, b: TPointArray;
  45.  
  46. begin
  47.   b := RandomTPA(10, -2, -2, 2, 2);
  48.   WriteLn('BEFORE: ' + ToStr(b));
  49.   a := CleanAndSortTPA(b);
  50.   WriteLn('AFTER: ' + ToStr(a));
  51. end.
Advertisement
Add Comment
Please, Sign In to add comment