SRL Archive - Suggestions

InvertTPA to a Function


marpis

2010-07-01 10:24:41

Atm it's a procedure, but I think it should be a function that returned TPointArray.

Gu3st...

2010-07-01 10:27:41

I agree, but please read this: http://villavu.com/forum/showthread.php?t=57682

Wizzup?

2010-07-01 10:42:12

Why? If you want the original points back, you just invert it again. Or make a copy beforehand.

Wanted

2010-07-01 12:48:33

From: Wizzup?
Why? If you want the original points back, you just invert it again. Or make a copy beforehand.


This^ that or just make your own.

function InvertedTPA(TPA: TPointArray): TPointArray;
begin
Result := TPA;
InvertTPA(Result);
end;

Wizzup?

2010-07-01 16:13:29

From: IceFire908
This^ that or just make your own.

function InvertedTPA(TPA: TPointArray): TPointArray;
begin
Result := TPA;
InvertTPA(Result);
end;


This does (or should) not work. You need to copy it manually.

marpis

2010-07-01 17:16:36

From: Wizzup?
Why? If you want the original points back, you just invert it again. Or make a copy beforehand.


Because a function can do the same that the procedure
TPA := InvertTPA(TPA)

but as a procedure if we want to assign the inverted TPA to another variable
TPA2 := TPA;
InvertTPA(TPA2);
It's 2 lines :rolleyes:

Gu3st...

2010-07-01 17:18:20

TPA2 := InvertTPA(TPA)*

Wanted

2010-07-01 17:27:28

From: Wizzup?
This does (or should) not work. You need to copy it manually.


{.include SRL\SRL.scar}

function InvertedTPA(TPA: TPointArray): TPointArray;
begin
Result := TPA;
InvertTPA(Result);
end;

procedure ListTPA(TPA: TPointArray);
var
I: LongInt;
begin
for I := 0 to High(TPA) do
WriteLn(IntToStr(TPA[I].X) + ', ' + IntToStr(TPA[I].Y));
end;

var
TPA, bTPA: TPointArray;

begin
TPA := [Point(0, 0), Point(1, 1), Point(2, 2)];
ListTPA(TPA);
bTPA := InvertedTPA(TPA);
ListTPA(bTPA);
end.

Successfully compiled (4621 ms)
0, 0
1, 1
2, 2
2, 2
1, 1
0, 0
Successfully executed

Seems to work fine, why wouldn't it work?

Agreed though, this is trivial.. the current system is fine/better

Wizzup?

2010-07-01 18:28:30

From: IceFire908
{.include SRL\SRL.scar}

function InvertedTPA(TPA: TPointArray): TPointArray;
begin
Result := TPA;
InvertTPA(Result);
end;

procedure ListTPA(TPA: TPointArray);
var
I: LongInt;
begin
for I := 0 to High(TPA) do
WriteLn(IntToStr(TPA[I].X) + ', ' + IntToStr(TPA[I].Y));
end;

var
TPA, bTPA: TPointArray;

begin
TPA := [Point(0, 0), Point(1, 1), Point(2, 2)];
ListTPA(TPA);
bTPA := InvertedTPA(TPA);
ListTPA(bTPA);
end.

Successfully compiled (4621 ms)
0, 0
1, 1
2, 2
2, 2
1, 1
0, 0
Successfully executed

Seems to work fine, why wouldn't it work?

Agreed though, this is trivial.. the current system is fine/better


It shouldn't work as Arrays are technically Pointers, so you reference the same memory. But perhaps PascalScript does not do this. (It really should)

also @ marpis: Why don't you read what I posted in here before… It explains the difference and why it is there.

Wanted

2010-07-01 20:00:58

From: Wizzup?
It shouldn't work as Arrays are technically Pointers, so you reference the same memory. But perhaps PascalScript does not do this. (It really should)


Ah, we'll it's not the first rule we've broken. =P

Sir R. M8gic1an

2010-07-02 06:35:12

From: Wizzup?
It shouldn't work as Arrays are technically Pointers, so you reference the same memory. But perhaps PascalScript does not do this. (It really should)


And how else would we copy the array into memory?

Anyway, I think adding MirrorTPA / InvertedTPA wouldn't hurt.

(I Prefer mirror as it's a clear distinction)

~RM

Gu3st...

2010-07-02 06:59:54

From: Rasta Magician
And how else would we copy the array into memory?

~RM


SetArrayLength(TPA2, GetArrayLength(TPA));
H := High(TPA);
for I := 0 to H do
TPA2[I] := Point(TPA[I].X, TPA[I].Y);

Sir R. M8gic1an

2010-07-02 08:38:15

From: Zyt3x
SetArrayLength(TPA2, GetArrayLength(TPA));
H := High(TPA);
for I := 0 to H do
TPA2[I] := Point(TPA[I].X, TPA[I].Y);


True.


function MirrorTPA(TPA: TPointArray): TPointArray;
var
i, h: integer;
begin d

h := 0;
SetLength(Result, Length(TPA));

for i := High(TPA) DownTo 0 do
begin
Result[h] := TPA[i];
Inc(h);
end;

end;

~RM

Coh3n

2010-07-02 09:17:17

RM, why the h var? If the lengths are the same, is there a reason you shouldn't do

Result[i] := TPA[i];
?

E: Nevermind. :duh: Didn't consider the downto. -.-