SRL Archive - SRL Archives

Symbol.scar IsPointInTPA();


NCDS

2010-02-12 18:43:12

Just a bunch of unnecessary stuff..

Current one:

{*******************************************************************************
Function IsPointInTPA(Point:TPoint; TPA:TPointArray):Boolean;
By: Bad Boy JH
Description:
*******************************************************************************}
Function IsPointInTPA(Point:TPoint; TPA:TPointArray):Boolean;
var I:integer;
begin
for i := 0 to high(TPA)-1 do
begin
if (TPA[i].x = Point.x) and (TPA[i].y = Point.y) then
begin
Result:= True
Exit;
end;
end;
Result := False
end;

New one

{*******************************************************************************
Function IsPointInTPA(Point:TPoint; TPA:TPointArray):Boolean;
By: Bad Boy JH
Description:
*******************************************************************************}
Function IsPointInTPA(Point:TPoint; TPA:TPointArray):Boolean;
var I:integer;
begin
for i := 0 to high(TPA) - 1 do
Result := (TPA[i].x = Point.x) and (TPA[i].y = Point.y);
end;

Cigue

2010-02-12 18:45:42

That would slow it down a little.

Wanted

2010-02-12 18:46:13

Sorry, but this won't work. It needs to break out of the loop otherwise the last points in the TPA corresponding will determine whether the argument is true or not.

NCDS

2010-02-12 18:49:35

From: IceFire908
Sorry, but this won't work. It needs to break out of the loop otherwise the last points in the TPA corresponding will determine whether the argument is true or not.


Ah >.< I see what you mean. Never mind then

mixster

2010-02-12 18:55:19

erm, it seems that it should be looping up to high, not high -1? At the moment it looks like it will return false if the matching TPoint was the last one in the loop… If you did want to speed it up though, I think I suggested in his original thread somewhere that you can sort the TPA based on the TPoint then just compare the first point.

Wanted

2010-02-12 18:59:24

{*******************************************************************************
function IsPointInTPA(Point:TPoint; TPA:TPointArray): Boolean;
By: IceFire908
*******************************************************************************}

function IsPointInTPA(Point: TPoint; TPA: TPointArray): Boolean;
var
I: LongInt;
begin
for I := High(TPA) downto 0 do
if ((TPA[I].X = Point.X) and (TPA[I].Y = Point.Y)) then
begin
Result:= True
Exit;
end;
end;

That's as fast as it will go SCAR side… I'll commit later when something else needs to be done.

nielsie95

2010-02-12 20:35:48

Isn't it faster to split the comparison?


function IsPointInTPA2(Point: TPoint; TPA: TPointArray): Boolean;
var
I: LongInt;
begin
for I := High(TPA) downto 0 do
if (TPA[I].X = Point.X) then if (TPA[I].Y = Point.Y) then
begin
Result:= True
Exit;
end;
Result := False;
end;

Wanted

2010-02-12 20:51:28

From: nielsie95
Isn't it faster to split the comparison?


function IsPointInTPA2(Point: TPoint; TPA: TPointArray): Boolean;
var
I: LongInt;
begin
for I := High(TPA) downto 0 do
if (TPA[I].X = Point.X) then if (TPA[I].Y = Point.Y) then
begin
Result:= True
Exit;
end;
Result := False;
end;


Yea I'll do that.

ZephyrsFury

2010-02-13 10:08:23

Use WizzyPlugin's PointInTPA - same purpose, same params.

mixster

2010-02-13 10:12:45

The problem of rewriting in Scar originates in that the WizzyPlugin one suddenly started crashing Scar or something or other. Unless you mean just steal the code.

ZephyrsFury

2010-02-13 10:18:36

From: mixster
The problem of rewriting in Scar originates in that the WizzyPlugin one suddenly started crashing Scar or something or other. Unless you mean just steal the code.


Oh sorry, wasn't aware of that. Ignore my post then.

Sir R. M8gic1an

2010-02-13 10:32:46

Use nielsie's as scar doesn't have short circuit evalution. If you don't know what it is, wikipedia.


~RM

Wanted

2010-02-17 21:12:39

Committed.

From: Rasta Magician
Use nielsie's as scar doesn't have short circuit evalution. If you don't know what it is, wikipedia.


~RM


I'm pretty sure I know what you mean by that.

I hope what you meant was this:

SRL Rev 388+
{*******************************************************************************
function IsPointInTPA(Point:TPoint; TPA:TPointArray): Boolean;
By: IceFire908
*******************************************************************************}

function IsPointInTPA(Point: TPoint; TPA: TPointArray): Boolean;
var
I: LongInt;
begin
for I := High(TPA) downto 0 do
if (TPA[I].X = Point.X) then
if (TPA[I].Y = Point.Y) then
begin
Result:= True
Exit;
end;
end;

noidea

2010-02-17 23:36:30

From: Rasta Magician
Use nielsie's as scar doesn't have short circuit evalution. If you don't know what it is, wikipedia.


~RM


wtf.
Any good interpreter/language uses short circuit evaluation :duh:

Sir R. M8gic1an

2010-02-18 03:41:32

From: noidea
wtf.
Any good interpreter/language uses short circuit evaluation :duh:


Not scar tho.

~RM

Gu3st...

2010-02-18 07:35:55

From: Rasta Magician
Not scar tho.

~RM
I think I can vaguely remember Wizzup? saying that SCAR had short circuit evaluation..?

mixster

2010-02-18 09:00:04

It doesn't. You can easily test it and see.

function meow: Boolean;
begin
Writeln('Meow!');
Result := True;
end;

begin
Writeln('Begin');

if (False) and (meow) then
Writeln('Defying the laws of Booleans!');

if (True) or (meow) then
Writeln('Following the laws of Booleans!');

Writeln('End');
end.

Sir R. M8gic1an

2010-02-18 09:20:02

From: Zyt3x
I think I can vaguely remember Wizzup? saying that SCAR had short circuit evaluation..?



program New;

var
time, i: integer;
boolF, boolT: boolean;

begin
boolF := False;
boolT := True;

Time := GetSystemTime;
for i := 0 to 99999 do
if (boolF)and(boolT) then
wait(1);
writeln(GetSystemTime - Time);

Time := GetSystemTime;
for i := 0 to 99999 do
if (boolF) then
if (boolT) then
wait(1);
writeln(GetSystemTime - Time);


end.

From: scar

546
312


~RM

Timer

2010-02-18 15:15:42

[SPAM]
Successfully compiled (21 ms)
124
75
Successfully executed

Funny. :p[/SPAM]

MylesMadness

2010-02-18 17:44:58

From: Timer
[SPAM]
Successfully compiled (21 ms)
124
75
Successfully executed

Funny. :p[/SPAM]
Oh you have a faster computer what a cool kid…

Wizzup?

2010-02-19 09:00:20

/facepalm
Stop caring about speed within the interpreter!