SRL Archive - Help and Support

if TPA1 <> TPA2 then results in error?


Gu3st...

2009-10-31 09:02:29

I tried to do "Result := TPA1 <> TPA2;" but it results in a type mismatch error… Is there any function for checking if two TPA's are similar?
EDIT: And yes, the function's result is set to as Boolean (function Thefunction : Boolean; )

Sabzi

2009-10-31 09:10:14

Do it with Length(TPA1) and Length(TPA2). They are TPointArrays, right? I don't know if it's possible or not to use "<", "=" and things like that with them. But you can get their Lengths.

Narcle

2009-10-31 09:19:05

Only way u could compare TPAs like that is making another function that runs through TPoints. Umm lets see here.

Something like this (haven't tested)
Function SameTPA(TPA1, TPA2: TIntegerArray): Boolean;
var
i: integer;
begin
if Length(TPA1) = Length(TPA2) then
begin
for i := 0 to High(TPA1) do
if (TPA1[i].x <> TPA2[i].x) or (TPA1[i].y <> TPA2[i].y) then
Exit;
end else
Exit;
Result := True;
end;

Gu3st...

2009-10-31 09:26:10

From: Sabzi
Do it with Length(TPA1) and Length(TPA2). They are TPointArrays, right? I don't know if it's possible or not to use "<", "=" and things like that with them. But you can get their Lengths.

Yeah, but what if they have the same length?
From: Narcle
Only way u could compare TPAs like that is making another function that runs through TPoints. Umm lets see here.

Something like this (haven't tested)
Function SameTPA(TPA1, TPA2: TPointArray): Boolean;
var
i: integer;
begin
if Length(TPA1) = Length(TPA2) then
begin
for i := 0 to High(TPA1) do
if (TPA1[i].x <> TPA2[i].x) or (TPA1[i].y <> TPA2[i].y) then
Exit;
end else
Exit;
Result := True;
end;

Thank you, works great! :)

Nava2

2009-10-31 10:22:02

function SameTPA(TPA1, TPA2: TPointArray): Boolean;
var
i, h: integer;
begin
h := Length(TPA1);
if h = Length(TPA2) then
begin
Dec(h);
for i := 0 to h do
if (TPA1[i].x <> TPA2[i].x) or (TPA1[i].y <> TPA2[i].y) then
Exit;
end else
Exit;
Result := True;
end;

I believe this is in Wizzy, by the way.

Narcle

2009-10-31 10:32:53

From: Nava2
function SameTPA(TPA1, TPA2: TPointArray): Boolean;
var
i, h: integer;
begin
h := Length(TPA1);
if h = Length(TPA2) then
begin
Dec(h);
for i := 0 to h do
if (TPA1[i].x <> TPA2[i].x) or (TPA1[i].y <> TPA2[i].y) then
Exit;
end else
Exit;
Result := True;
end;

I believe this is in Wizzy, by the way.


Really? I just wrote mine in like a minute lol. Simple stuff either way.

BTW, if its in wizzy plugin use his. ;) its faster

Gu3st...

2009-10-31 11:31:20

From: Narcle
Really? I just wrote mine in like a minute lol. Simple stuff either way.

BTW, if its in wizzy plugin use his. ;) its faster
Yeah, I though about putting it in a plugin, but now if it's already in one then I'll just use that one :P
EDIT: I can't find it

mixster

2009-10-31 12:46:06

Could probably setup a faster method by getting TPA bounds, if they match then drawing each TPoint onto bitmap with different colours and searching for initial colour. Whether or not it's faster would depend a few things though - using WizzyPlugin's DrawTPACanvas would be a good start for speed boosts as long as it's roughly based on 0,0 origin rather than something like MIX/Y1/2 box as that would result in a large bitmap being required. Likewise negative points would screw it up.

Gu3st...

2009-10-31 13:07:49

From: mixster
Could probably setup a faster method by getting TPA bounds, if they match then drawing each TPoint onto bitmap with different colours and searching for initial colour. Whether or not it's faster would depend a few things though - using WizzyPlugin's DrawTPACanvas would be a good start for speed boosts as long as it's roughly based on 0,0 origin rather than something like MIX/Y1/2 box as that would result in a large bitmap being required. Likewise negative points would screw it up.
The boundaries are the same and each TPoint.X is greater than 1100

mixster

2009-10-31 13:19:00

DrawTPACanvas doesn't use values based upon TPA bounds, so it would require a bitmap with an incredible size making it pretty much silly to do it this way. Narcles method would probably be better. Just remember that it would require both TPA's to be identically ordered though, so if they're not you would probably want to use a SortTPAFrom to make it so they would be ordered the same if they are identical.

lordsaturn

2009-11-01 11:34:43

Mi(x)ster overanalytical

nielsie95

2009-11-01 13:18:45

From: mixster
Could probably setup a faster method by getting TPA bounds, if they match then drawing each TPoint onto bitmap with different colours and searching for initial colour. Whether or not it's faster would depend a few things though - using WizzyPlugin's DrawTPACanvas would be a good start for speed boosts as long as it's roughly based on 0,0 origin rather than something like MIX/Y1/2 box as that would result in a large bitmap being required. Likewise negative points would screw it up.


This is probably the fastest method if the arrays have to be in the same order. If they don't have to be in the same order, I think a 2 dimensional boolean array instead of a canvas would do the trick (negative points wouldn't screw up as you'd do Array[Index].x - Bound.x1).

mixster

2009-11-01 15:51:09

Having to remove values from each one would add up though, which is why I didn't suggest offsetting them all based on the boundary - depending on the size, I would think using SortTPAFrom first then just assuming identical order would still be faster. Of course, we're now debating ms's, so unless it's vital I think both are good Method's.

Gu3st...

2009-11-01 17:50:01

To be honest I would like to see this procedure in WizzyPlugin :)

Nava2

2009-11-01 17:58:02

From: mixster
Having to remove values from each one would add up though, which is why I didn't suggest offsetting them all based on the boundary - depending on the size, I would think using SortTPAFrom first then just assuming identical order would still be faster. Of course, we're now debating ms's, so unless it's vital I think both are good Method's.


You can't hilight people on the forums :>