Advertisement
WarPie90

Untitled

Jun 14th, 2023
1,421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.83 KB | None | 0 0
  1. function SplitPoints(list: TPointArray; w,h: Int32): T2DPointArray;
  2. var
  3.   lo,hi: Int32;
  4.   function extract_connections_of(p: TPoint): TPointArray;
  5.   var i: Int32;
  6.   begin
  7.     for i:=hi downto lo+1 do
  8.       if (Abs(p.x-list[i].x) <= w) and (Abs(p.y-list[i].y) <= h) then
  9.       begin
  10.         Result += list[i];
  11.         Swap(list[i], list[hi]); //move towards end
  12.         Dec(hi);                 //and ever look at it again
  13.       end;
  14.   end;
  15.  
  16.   function recurse_connections(p: TPoint): TPointArray;
  17.   var i: Int32;
  18.   begin
  19.     Result := extract_connections_of(p);
  20.     for i:=0 to High(result) do
  21.       Result += recurse_connections(result[i]); //extend
  22.   end;
  23. begin
  24.   lo := 0;
  25.   hi := High(list);
  26.   while lo <= hi do
  27.   begin
  28.     Result += recurse_connections(list[lo]) + [list[lo]]; //append group
  29.     inc(lo);
  30.   end;
  31. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement