Janilabo

Janilabo | GetATPALinesEx

Nov 7th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.48 KB | None | 0 0
  1. function GetATPALinesEx(ATPA: T2DPointArray): T2DPointArray;
  2. {==============================================================================]  
  3.   Explanation: Returns the MULTI-line from ATPA items (works like an array of [2D] waypoints)
  4.                Breaks each ATPA index to its own multiline for result ATPA.                  
  5. [==============================================================================}
  6. var
  7.   a, b, h, i, l, o, x, s: Integer;
  8. begin
  9.   SetLength(Result, 0);
  10.   a := Length(ATPA);  
  11.   if (a < 1) then
  12.     Exit;
  13.   SetLength(Result, a);
  14.   for b := 0 to (a - 1) do
  15.   begin
  16.     l := Length(ATPA[b]);
  17.     if (l > 0) then
  18.     case (l = 1) of
  19.       True:
  20.       begin
  21.         o := Length(Result[b]);          
  22.         SetLength(Result[b], (o + 1));
  23.         Result[b][o] := ATPA[b][0];
  24.       end;
  25.       False:
  26.       for x := 0 to (l - 2) do  
  27.       begin
  28.         o := Length(Result[b]);
  29.         h := Max(Round(Abs(ATPA[b][x].X - ATPA[b][(x + 1)].X)), Round(Abs(ATPA[b][x].Y - ATPA[b][(x + 1)].Y)));
  30.         if (h = 0) then
  31.           Inc(h);
  32.         SetLength(Result[b], (o + (h + 1) - s));
  33.         for i := s to h do
  34.           Result[b][((o + i) - s)] := Point((ATPA[b][x].X + Round((ATPA[b][(x + 1)].X - ATPA[b][x].X) * (i / h))), (ATPA[b][x].Y + Round((ATPA[b][(x + 1)].Y - ATPA[b][x].Y) * (i / h))));
  35.         s := 1;
  36.       end;    
  37.     end;
  38.     s := 0;
  39.   end;      
  40. end;
  41.  
  42. procedure TPADebug(var bmp: TSCARBitmap; TPA: TPointArray; color: Integer);
  43. var
  44.   h, i: Integer;
  45. begin
  46.   h := High(TPA);
  47.   for i := 0 to h do
  48.     if ((TPA[i].X > -1) and (TPA[i].X < bmp.Width) and (TPA[i].Y > -1) and (TPA[i].Y < bmp.Height)) then
  49.       bmp.Pixels[TPA[i].X, TPA[i].Y] := color;
  50. end;
  51.  
  52. var
  53.   i: Integer;
  54.   bmp: TSCARBitmap;
  55.   ATPA, pts: T2DPointArray;
  56.   TPA: TPointArray;
  57.  
  58. begin
  59.   ClearDebug;
  60.   bmp := TSCARBitmap.Create('');
  61.   bmp.SetSize(135, 90);  
  62.   SetLength(pts, 5);
  63.   pts[0] := [Point(38, 17), Point(38, 70), Point(16, 70), Point(16, 58)]; // J
  64.   pts[1] := [Point(50, 70), Point(50, 17), Point(68, 17), Point(68, 70)]; // A
  65.   pts[2] := [Point(50, 40), Point(68, 40)]; // A-"line" (line to the middle of letter A)
  66.   pts[3] := [Point(78, 70), Point(78, 17), Point(103, 70), Point(103, 17)]; // N
  67.   pts[4] := [Point(117, 17), Point(117, 70)]; // I
  68.   ATPA := GetATPALinesEx(pts);
  69.   SetLength(pts, 0);
  70.   TPA := MergeATPA(ATPA);    
  71.   SetLength(ATPA, 0);      
  72.   TPADebug(bmp, TPA, clWhite);
  73.   DebugBitmap(bmp);    
  74.   bmp.Free;
  75.   SetLength(TPA, 0);
  76. end.
Advertisement
Add Comment
Please, Sign In to add comment