delphi Code:
library RCrB_Plugin;
uses
FastShareMem,
SysUtils,
Windows,
Math;
{$R *.res}
type
TBox = record
x1, y1, x2, y2: Integer;
end;
TPointArray = array of TPoint;
function GetTPABounds(TPA: TPointArray): TBox; stdcall;
var
I,L : Integer;
begin;
L := High(TPA);
if (l < 0) then Exit;
Result.x1 := TPA[0].x;
Result.y1 := TPA[0].y;
Result.x2 := TPA[0].x;
Result.y2 := TPA[0].y;
for I:= 1 to L do
begin;
if TPA[i].x > Result.x2 then
Result.x2 := TPA[i].x
else if TPA[i].x < Result.x1 then
Result.x1 := TPA[i].x;
if TPA[i].y > Result.y2 then
Result.y2 := TPA[i].y
else if TPA[i].y < Result.y1 then
Result.y1 := TPA[i].y;
end;
end;
procedure FilterPointsLine(out Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer); stdcall;
var
I, Hi, Ind, y: Integer;
P: TPointArray;
Box: TBox;
B: Array of Array of Boolean;
sinRadial, cosRadial: Extended;
sinRadMult, cosRadMult: Integer;
begin
Ind := 0;
Box:= GetTPABounds(Points);
sinRadial := sin(Radial);
cosRadial := cos(Radial);
SetLength(B, max(Box.x2, Round(sinRadial * Radius + MX)) + 1);
y:= max(Box.x2, -Round(cosRadial * Radius) + MY);
for I:= High(B) downto 0 do
SetLength(B[I], y + 1);
Hi:= High(Points);
for I:= Hi downto 0 do
B[Points[I].x][Points[I].y]:= True;
SetLength(P, Hi + 1);
for I:= 0 to Radius do
begin
sinRadMult := Round(sinRadial * I) + MX;
cosRadMult := -Round(cosRadial * I) + MY;
if(B[sinRadMult][cosRadMult])then
begin
P[Ind].X := sinRadMult;
P[Ind].Y := cosRadMult;
inc(Ind);
end;
end;
SetLength(P, Ind);
Points:= P;
end;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall;
begin
case x of
0:begin
ProcAddr := @FilterPointsLine;
StrPCopy(ProcDef, 'procedure FilterPointsLine(out Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer);');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
end.