Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetATPALinesEx(ATPA: T2DPointArray): T2DPointArray;
- {==============================================================================]
- Explanation: Returns the MULTI-line from ATPA items (works like an array of [2D] waypoints)
- Breaks each ATPA index to its own multiline for result ATPA.
- [==============================================================================}
- var
- a, b, h, i, l, o, x, s: Integer;
- begin
- SetLength(Result, 0);
- a := Length(ATPA);
- if (a < 1) then
- Exit;
- SetLength(Result, a);
- for b := 0 to (a - 1) do
- begin
- l := Length(ATPA[b]);
- if (l > 0) then
- case (l = 1) of
- True:
- begin
- o := Length(Result[b]);
- SetLength(Result[b], (o + 1));
- Result[b][o] := ATPA[b][0];
- end;
- False:
- for x := 0 to (l - 2) do
- begin
- o := Length(Result[b]);
- h := Max(Round(Abs(ATPA[b][x].X - ATPA[b][(x + 1)].X)), Round(Abs(ATPA[b][x].Y - ATPA[b][(x + 1)].Y)));
- if (h = 0) then
- Inc(h);
- SetLength(Result[b], (o + (h + 1) - s));
- for i := s to h do
- 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))));
- s := 1;
- end;
- end;
- s := 0;
- end;
- end;
- procedure TPADebug(var bmp: TSCARBitmap; TPA: TPointArray; color: Integer);
- var
- h, i: Integer;
- begin
- h := High(TPA);
- for i := 0 to h do
- if ((TPA[i].X > -1) and (TPA[i].X < bmp.Width) and (TPA[i].Y > -1) and (TPA[i].Y < bmp.Height)) then
- bmp.Pixels[TPA[i].X, TPA[i].Y] := color;
- end;
- var
- i: Integer;
- bmp: TSCARBitmap;
- ATPA, pts: T2DPointArray;
- TPA: TPointArray;
- begin
- ClearDebug;
- bmp := TSCARBitmap.Create('');
- bmp.SetSize(135, 90);
- SetLength(pts, 5);
- pts[0] := [Point(38, 17), Point(38, 70), Point(16, 70), Point(16, 58)]; // J
- pts[1] := [Point(50, 70), Point(50, 17), Point(68, 17), Point(68, 70)]; // A
- pts[2] := [Point(50, 40), Point(68, 40)]; // A-"line" (line to the middle of letter A)
- pts[3] := [Point(78, 70), Point(78, 17), Point(103, 70), Point(103, 17)]; // N
- pts[4] := [Point(117, 17), Point(117, 70)]; // I
- ATPA := GetATPALinesEx(pts);
- SetLength(pts, 0);
- TPA := MergeATPA(ATPA);
- SetLength(ATPA, 0);
- TPADebug(bmp, TPA, clWhite);
- DebugBitmap(bmp);
- bmp.Free;
- SetLength(TPA, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment