Had to restart my comp because I messed around with delphi to much
I finally got this: (see below)
It's still overall 500ms slower than using FilterPointsPie, but it gets the job done :D
If anyone can tell me a way to make it go faster by any means, please let me know.
Edit: After adding two other functions I am using in the main script I was able to cut down another 1000 ms… it's still around 600ms which is awesome! and will be even less once I move the entire main function into the plugin :) but still if you see any speed improvements let me know!
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(var 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;
begin
Ind := 0;
Box:= GetTPABounds(Points);
SetLength(B, max(Box.x2, Round(sin(Radial) * Radius + MX)) + 1);
y:= max(Box.x2, -Round(cos(Radial) * Radius) + MY);
for I:= 0 to High(B) do
SetLength(B[I], y + 1);
Hi:= High(Points);
for I:= 0 to Hi do
B[Points[I].x][Points[I].y]:= True;
SetLength(P, Hi + 1);
for I:= 0 to Radius do
begin
if(B[Round(sin(Radial) * I) + MX][-Round(cos(Radial) * I) + MY])then
begin
P[Ind].X := Round(sin(Radial) * I) + MX;
P[Ind].Y := -Round(cos(Radial) * I) + MY;
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(var Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer);');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount;
exports GetFunctionInfo;
end.