SRL Archive - SRL Archives

Color.scar ColorsInBox();


NCDS

2010-02-10 22:27:31

Pretty simple but I have used it on numerous occasions so I thought I may as well share:

{*******************************************************************************
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
By: NCDS & Nava2
Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
*******************************************************************************}
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
var
tia: TIntegerArray; i, o: Integer;
begin
o := 0;
tia := GetColorsBox(x1, y1, x2, y2, True);
clearSameIntegers(tia);
clearSameIntegers(color);
for i := High(Color) downto 0 do
if InIntArray(tia, Color[i]) then
Inc(o);
Result := (o = Length(Color));
end;

Any thoughts on this?

i luffs yeww

2010-02-11 00:19:59

Really necessary? :p It's just FindColor/FindColors without the variables..

NCDS

2010-02-11 00:52:04

From: i luffs yeww
Really necessary? :p It's just FindColor/FindColors without the variables..


Hmm..I guess your right lol. Honestly, in all my time of using this, I never thought of it like that.

I always normally used it for location checks and such as a "line saver" :redface:

noidea

2010-02-11 01:00:21

I like it :)
Could be used in lots of cases, such as using a blacklist if searching for colours.

i luffs yeww

2010-02-11 01:09:33

Well since it's essentially the same thing as FindColors, you could just do something like


function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
var
x, y: Integer;
begin
Result := FindColors(x, y, [Color], x1, y1, x2, y2);
end;

Or whatever the params are.. I know it's basically the same thing.. ;)

Nava2

2010-02-11 01:53:44

{*******************************************************************************
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
By: NCDS
Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
*******************************************************************************}
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
var
tia: TIntegerArray; i, o: Integer;
begin
o := 0;
tia := GetColorsBox(x1, y1, x2, y2, True);
clearSameIntegers(tia);
clearSameIntegers(color);
for i := High(Color) downto 0 do
if InIntArray(tia, Color[i]) then
Inc(o);
Result := (o = Length(Color));
end;

NCDS

2010-02-11 02:43:58

From: Nava2
{*******************************************************************************
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
By: NCDS
Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
*******************************************************************************}
function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
var
tia: TIntegerArray; i, o: Integer;
begin
o := 0;
tia := GetColorsBox(x1, y1, x2, y2, True);
clearSameIntegers(tia);
clearSameIntegers(color);
for i := High(Color) downto 0 do
if InIntArray(tia, Color[i]) then
Inc(o);
Result := (o = Length(Color));
end;

That way looks nice ;)

Out of curiosity though, why for..downto..do instead of for..to..do?

Nava2

2010-02-11 14:51:56

In freepascal, downto calculates the High() value and it becomes constant, then the 0 is left.

As apposed to the regular where 0 is constant and High() is calculated every time. Small optimization for when order doesn't really matter. :)

Gu3st...

2010-02-11 14:55:45

From: Nava2
In freepascal, downto calculates the High() value and it becomes constant, then the 0 is left.

As apposed to the regular where 0 is constant and High() is calculated every time. Small optimization for when order doesn't really matter. :)
Oh, wow. I didn't know that :)
Much easier than making a own variable for High() lol

Nava2

2010-02-11 15:40:54

From: Zyt3x
Oh, wow. I didn't know that :)
Much easier than making a own variable for High() lol


I don't know if pascal script is smart enough for that though.