SRL Archive - Reflection Help

Combining paths


quipeace

2008-10-14 05:22:35

Hello everyone,

I just started coding with reflection, so don't just flame me…

I'm trying to combine a number of paths… Heres an example of what i mean

this is my first path:
function LoadPath2: TPointArray;
begin
SetLength(Result, 4);
Result[0] := (Point(2728, 3481));
Result[1] := (Point(2730, 3470));
Result[2] := (Point(2733, 3457));
Result[3] := (Point(2740, 3442));
end;

and this is my second:
function LoadPath3: TPointArray;
begin
SetLength(Result, 5);
Result[0] := (Point(2719, 3479));
Result[1] := (Point(2722, 3469));
Result[2] := (Point(2726, 3457));
Result[3] := (Point(2733, 3446));
Result[4] := (Point(2745, 3440));
end;

now i want it to combine those paths, so point 1 would be either:
(2728, 3481) or (2719, 3479)
second point:
(2730, 3470) or (2722, 3469)

I hope you understand what I am trying to say…

Quipeace:sasmokin:

Lee Lok Hin

2008-10-14 05:37:07

program New;

function LoadPath3: TPointArray;
begin
SetLength(Result, 5);
Result[0] := (Point(2719, 3479));
Result[1] := (Point(2722, 3469));
Result[2] := (Point(2726, 3457));
Result[3] := (Point(2733, 3446));
Result[4] := (Point(2745, 3440));
end;

function LoadPath2: TPointArray;
begin
SetLength(Result, 4);
Result[0] := (Point(2728, 3481));
Result[1] := (Point(2730, 3470));
Result[2] := (Point(2733, 3457));
Result[3] := (Point(2740, 3442));
end;

function RandomizePaths(a,b:TPointArray):TPointArray;
var
i,c,ai,bi:integer;
t:boolean;
begin
ai:= High(a);
bi:= High(b);
if bi > ai then ai := bi;
SetArrayLength(Result,ai + 1);
writeln(inttostr(ai));

for i:= 0 to ai do
begin
c:= Random(2);
try
case c of
1: Result[i] := b[i];
0: Result[i] := a[i];
end;
except
writeln('Errored at '+inttostr(i)+ ' with c being '+inttostr(c) );
case c of
1: Result[i] := a[i];
0: Result[i] := b[i];
end;
end;
end;
end;

var
tp:TPointArray;
v:integer;

begin
tp:= RandomizePaths(Loadpath3,Loadpath2);
for v:= 0 to high(tp) do
writeln(inttostr(tp[v].x) + ' '+ inttostr(tp[v].y));
end.

Rustled this up. Use RandomizePaths the way I used it in my mainloop.

quipeace

2008-10-14 08:48:08

Thanks alot!

Quipeace

EDIT:

Its working great! I modded the script a bit so it would take three paths, I'll give credits in script :)