SRL Archive - SRL Archives

AdjustableRadialStartWalk


bbri06

2009-12-23 18:32:00

Made this for my Catherby Yew Cutter that I'm currently making(almost done :) ). Not sure if there is already something like this or not. I kind of hope there isn't because then I made it all for no reason lol.


//Trys to Radial walk from the RadialStart and RadialEnd then if it fails,
//adjusts the RadialStart by 2 until your MaxRadialAdj(Maximum radial to
//adjust to) is reached.

//Direction = true to Adj radial start counterclockwise, false to Adj radial start
//clockwise
//By Bbri06

Function AdjustableRadialStartWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod, MaxRadialAdj: integer; Direction: boolean): boolean;
var
RadialAdj: integer;
begin
if(RadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod))then
begin
result := true;
end else
begin
RadialAdj := 2;
repeat
if(RadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod))then
begin
result := true;
break;
end else
begin
if(Direction)then
begin
RadialStart := RadialStart - RadialAdj;
end else
RadialStart := RadialStart + RadialAdj;
end;
RadialAdj := RadialAdj + 2;
until(RadialAdj > MaxRadialAdj)
end;
if(RadialAdj > MaxRadialAdj)then
result := false;
end;

It's opposite

//Trys to Radial walk from the RadialStart and RadialEnd then if it fails,
//adjusts the RadialEnd by 2 until your MaxRadialAdj(Maximum radial to
//adjust to) is reached.

//Direction = true to Adj RadialEnd clockwise, false to Adj RadialEnd
//counterclockwise
//By Bbri06

Function AdjustableRadialEndWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod, MaxRadialAdj: integer; Direction: boolean): boolean;
var
RadialAdj: integer;
begin
if(RadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod))then
begin
result := true;
end else
begin
RadialAdj := 2;
repeat
if(RadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod))then
begin
result := true;
break;
end else
begin
if(Direction)then
begin
RadialEnd := RadialEnd + RadialAdj;
end else
RadialEnd := RadialEnd - RadialAdj;
end;
RadialAdj := RadialAdj + 2;
until(RadialAdj > MaxRadialAdj)
end;
if(RadialAdj > MaxRadialAdj)then
result := false;
end;

mixster

2009-12-24 05:49:47

As I'm assuming they're very similar, this is just based on the first one.
First of all, allowing the user to set the size of the steps would be much nicer as a lot of people use a variety of different amounts for walking. Likewise, allowing a custom number of steps would also be nice rather than a specific amount to increase it by. Moreover, using a bit of thinking through, rather than trying to radial walk in a larger area, you could just try to walk in the new, small area created by expanding the area. Also, combining both into 1 function doesn't seem too hard - which would be especially useful if you wanted it to be able to expand in both directions at the same time, ie lowering beginning and increasing ending. Lastly, it's a bit silly to have it able to expand in both ways (as in clockwise and counterclockwise for the beginning or ending) as it's less likely to find it if you make the search area smaller (ie, increase start or decrease end so they come close together).

Overall, I think it would work better as something more like:
const // for ExpandIn var
EX_CW = 0;
EX_CCW = 1;
EX_BOTH = 2;
function AdjustableRadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod, StepSize, NumOfSteps, ExpandIn: Integer): Boolean;
var
i: Integer;
begin
Result := RadialWalk(Color, RadialStart, RadialEnd, Radius, Xmod, Ymod);
if Result then
exit;
for i := 1 to NumOfSteps do
begin
if (ExpandIn = EX_CW) or (ExpandIn = EX_BOTH) then
begin
Result := RadialWalk(Color, RadialEnd + (StepSize * (i - 1)), RadialEnd + (StepSize * i), Radius, Xmod, Ymod);
if Result then
exit;
end;
if (ExpandIn = EX_CCW) or (ExpandIn = EX_BOTH) then
begin
Result := RadialWalk(Color, RadialStart - (StepSize * i), RadialStart - (StepSize * (i - 1)), Radius, Xmod, Ymod);
if Result then
exit;
end;
end;
end;

I could still play with it a bit, but I think this still has some readability and has all the improvements I mentioned above.

bbri06

2009-12-24 06:25:59

Looks really good to me, nicely done. I'm going to use it in my yew cutter if you have no objections.

marpis

2009-12-24 07:02:38

Just use LinearWalk :rolleyes: See what it does and you'll see that it's basically the same thing that you do.
It's like RadialWalk with a 100 degree angle. StartAngle := YourDirection -50, EndAngle := YourDirection + 50. It scans the sector for the colors we are looking for and sorts them from the original optimal direction. So it does not only look for colors in 1 pixel line, it does search in a wider area.

bbri06

2009-12-24 07:16:49

Oh, that's interesting. Thanks Marpis, I'll try it out.