1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-16 14:25:02 -05:00

FindRotatedDTM now has Alternating or Start-End search routines.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@570 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-02-28 19:21:15 +00:00
parent f336a20625
commit a2df7c159b
4 changed files with 63 additions and 15 deletions

View File

@ -44,7 +44,7 @@ uses
ColorBox , about, framefunctionlist, ocr, updateform, simbasettings; ColorBox , about, framefunctionlist, ocr, updateform, simbasettings;
const const
SimbaVersion = 569; SimbaVersion = 570;
type type

View File

@ -48,14 +48,14 @@ begin
end; end;
end; end;
function ps_FindDTMRotated(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: function ps_FindDTMRotatedAlternating(DTM: Integer; out x, y: Integer; x1, y1, x2, y2:
Integer; sAngle, eAngle, aStep: Extended; Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean; extdecl; out aFound: Extended): Boolean; extdecl;
var var
temp: pDTM; temp: pDTM;
begin begin
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMRotated(temp, x, y, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound) Result := CurrThread.Client.MFinder.FindDTMRotated(temp, x, y, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound,true)
else else
begin begin
x := 0; x := 0;
@ -64,13 +64,40 @@ begin
end; end;
end; end;
function ps_FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean; extdecl; function ps_FindDTMRotatedSE(DTM: Integer; out x, y: Integer; x1, y1, x2, y2:
Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean; extdecl;
var
temp: pDTM;
begin
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMRotated(temp, x, y, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound,false)
else
begin
x := 0;
y := 0;
Result := False;
end;
end;
function ps_FindDTMsRotatedAlternating(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean; extdecl;
var var
temp: pDTM; temp: pDTM;
begin begin
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMsRotated(temp, Points, x1, y1, x2, y2, Result := CurrThread.Client.MFinder.FindDTMsRotated(temp, Points, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound, 0) sAngle, eAngle, aStep, aFound, 0,true)
else
Result := False;
end;
function ps_FindDTMsRotatedSE(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean; extdecl;
var
temp: pDTM;
begin
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMsRotated(temp, Points, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound, 0,false)
else else
Result := False; Result := False;
end; end;

View File

@ -35,8 +35,10 @@ AddFunction(@ps_DTMFromString, 'function DTMFromString(DTMString: String): Integ
AddFunction(@ps_FreeDTM, 'procedure FreeDTM(DTM: Integer);'); AddFunction(@ps_FreeDTM, 'procedure FreeDTM(DTM: Integer);');
AddFunction(@ps_FindDTM, 'function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;'); AddFunction(@ps_FindDTM, 'function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;');
AddFunction(@ps_FindDTMs, 'function FindDTMs(DTM: Integer; var p: TPointArray; x1, y1, x2, y2: Integer): Boolean;'); AddFunction(@ps_FindDTMs, 'function FindDTMs(DTM: Integer; var p: TPointArray; x1, y1, x2, y2: Integer): Boolean;');
AddFunction(@ps_FindDTMRotated, 'function FindDTMRotated(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;'); AddFunction(@ps_FindDTMRotatedSE, 'function FindDTMRotatedSE(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;');
AddFunction(@ps_FindDTMsRotated, 'function FindDTMsRotated(DTM: Integer; var Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray) : Boolean;'); AddFunction(@ps_FindDTMRotatedAlternating, 'function FindDTMRotatedAlternating(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;');
AddFunction(@ps_FindDTMsRotatedSE, 'function FindDTMsRotatedSE(DTM: Integer; var Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray) : Boolean;');
AddFunction(@ps_FindDTMsRotatedAlternating, 'function FindDTMsRotatedAlternating(DTM: Integer; var Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray) : Boolean;');
AddFunction(@ps_addDTM, 'function AddDTM(d: TDTM): Integer;'); AddFunction(@ps_addDTM, 'function AddDTM(d: TDTM): Integer;');
AddFunction(@ps_addpDTM, 'function AddpDTM(d: pDTM): Integer;'); AddFunction(@ps_addpDTM, 'function AddpDTM(d: pDTM): Integer;');

View File

@ -84,8 +84,8 @@ type
function FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean; function FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
function FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean; function FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
function FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean; function FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
function FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer): Boolean; function FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
//Donno //Donno
function GetColors(Coords: TPointArray): TIntegerArray; function GetColors(Coords: TPointArray): TIntegerArray;
// tol speeds // tol speeds
@ -2048,13 +2048,13 @@ begin
Result := (pc > 0); Result := (pc > 0);
end; end;
function TMFinder.FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean; function TMFinder.FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended; Alternating : boolean): Boolean;
var var
P: TPointArray; P: TPointArray;
F: T2DExtendedArray; F: T2DExtendedArray;
begin begin
FindDTMsRotated(dtm, P, x1, y1, x2, y2, sAngle, eAngle, aStep, F, 1); FindDTMsRotated(dtm, P, x1, y1, x2, y2, sAngle, eAngle, aStep, F, 1,Alternating);
if Length(P) = 0 then if Length(P) = 0 then
exit(false); exit(false);
aFound := F[0][0]; aFound := F[0][0];
@ -2063,7 +2063,7 @@ begin
Exit(True); Exit(True);
end; end;
function TMFinder.FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer): Boolean; function TMFinder.FindDTMsRotated(_DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray; maxToFind: Integer; Alternating : boolean): Boolean;
var var
DTM: pDTM; DTM: pDTM;
// Colours of DTMs // Colours of DTMs
@ -2093,6 +2093,12 @@ var
PtrData: TRetData; PtrData: TRetData;
//If we search alternating, we start in the middle and then +,-,+,- the angle step outwars
MiddleAngle : extended;
//Count the amount of anglesteps, mod 2 determines whether it's a + or a - search, and div 2 determines the amount of steps
//you have to take.
AngleSteps : integer;
// point count // point count
pc: Integer = 0; pc: Integer = 0;
ac: Integer = 0; ac: Integer = 0;
@ -2155,7 +2161,12 @@ begin
cd := CalculateRowPtrs(PtrData, h + 1); cd := CalculateRowPtrs(PtrData, h + 1);
SetLength(aFound, 0); SetLength(aFound, 0);
SetLength(Points, 0); SetLength(Points, 0);
if Alternating then
begin
MiddleAngle := (sAngle + eAngle) / 2.0;
s := MiddleAngle; //Start in the middle!
AngleSteps := 0;
end else
s := sAngle; s := sAngle;
while s < eAngle do while s < eAngle do
begin begin
@ -2222,8 +2233,16 @@ begin
goto theEnd; goto theEnd;
AnotherLoopEnd: AnotherLoopEnd:
end; end;
s := s + aStep;
ac := 0; ac := 0;
if Alternating then
begin
if AngleSteps mod 2 = 0 then //This means it's an even number, thus we must add a positive step
s := MiddleAngle + (aStep * (anglesteps div 2 + 1)) //Angle steps starts at 0, so we must add 1.
else
s := MiddleAngle - (aStep * (anglesteps div 2 + 1)); //We must search in the negative direction
inc(AngleSteps);
end else
s := s + aStep;
end; end;
TheEnd: TheEnd:
TClient(Client).IOManager.FreeReturnData; TClient(Client).IOManager.FreeReturnData;