git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@107 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-10-06 03:40:44 +00:00
parent 1ff3e33a5e
commit b970995a3d
7 changed files with 566 additions and 119 deletions

View File

@ -33,15 +33,15 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="130">
<Units Count="132">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="26" Y="12"/>
<CursorPos X="33" Y="12"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="164"/>
<UsageCount Value="166"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -172,8 +172,8 @@
<UnitName Value="TestUnit"/>
<CursorPos X="10" Y="11"/>
<TopLine Value="1"/>
<EditorIndex Value="12"/>
<UsageCount Value="130"/>
<EditorIndex Value="14"/>
<UsageCount Value="132"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
@ -305,17 +305,17 @@
<CursorPos X="39" Y="8"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="129"/>
<UsageCount Value="131"/>
<Loaded Value="True"/>
</Unit37>
<Unit38>
<Filename Value="../../Units/MMLCore/mufasatypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="MufasaTypes"/>
<CursorPos X="15" Y="44"/>
<TopLine Value="28"/>
<CursorPos X="38" Y="32"/>
<TopLine Value="11"/>
<EditorIndex Value="1"/>
<UsageCount Value="129"/>
<UsageCount Value="131"/>
<Loaded Value="True"/>
</Unit38>
<Unit39>
@ -331,7 +331,7 @@
<UnitName Value="files"/>
<CursorPos X="15" Y="76"/>
<TopLine Value="47"/>
<UsageCount Value="130"/>
<UsageCount Value="132"/>
</Unit40>
<Unit41>
<Filename Value="../../Units/MMLCore/window.pas"/>
@ -339,7 +339,7 @@
<UnitName Value="Window"/>
<CursorPos X="41" Y="243"/>
<TopLine Value="228"/>
<UsageCount Value="129"/>
<UsageCount Value="131"/>
</Unit41>
<Unit42>
<Filename Value="../../../Documents/lazarus/lcl/forms.pp"/>
@ -353,8 +353,8 @@
<UnitName Value="CompTypes"/>
<CursorPos X="35" Y="727"/>
<TopLine Value="712"/>
<EditorIndex Value="7"/>
<UsageCount Value="27"/>
<EditorIndex Value="9"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit43>
<Unit44>
@ -377,7 +377,7 @@
<UnitName Value="finder"/>
<CursorPos X="79" Y="29"/>
<TopLine Value="15"/>
<UsageCount Value="122"/>
<UsageCount Value="124"/>
</Unit46>
<Unit47>
<Filename Value="../../../lazarus/lcl/graphics.pp"/>
@ -392,7 +392,7 @@
<UnitName Value="MMLThread"/>
<CursorPos X="10" Y="62"/>
<TopLine Value="50"/>
<UsageCount Value="120"/>
<UsageCount Value="122"/>
</Unit48>
<Unit49>
<Filename Value="../../../Documents/fpc/rtl/objpas/classes/classesh.inc"/>
@ -404,10 +404,10 @@
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="28" Y="138"/>
<TopLine Value="123"/>
<EditorIndex Value="8"/>
<UsageCount Value="118"/>
<CursorPos X="7" Y="75"/>
<TopLine Value="61"/>
<EditorIndex Value="10"/>
<UsageCount Value="120"/>
<Loaded Value="True"/>
</Unit50>
<Unit51>
@ -515,10 +515,10 @@
</Unit65>
<Unit66>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<CursorPos X="42" Y="25"/>
<TopLine Value="4"/>
<EditorIndex Value="9"/>
<UsageCount Value="33"/>
<CursorPos X="24" Y="25"/>
<TopLine Value="1"/>
<EditorIndex Value="11"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit66>
<Unit67>
@ -539,7 +539,7 @@
<UnitName Value="bitmaps"/>
<CursorPos X="31" Y="430"/>
<TopLine Value="419"/>
<UsageCount Value="108"/>
<UsageCount Value="110"/>
</Unit69>
<Unit70>
<Filename Value="../../../FPC/FPCCheckout/packages/fcl-image/src/fpcanvas.pp"/>
@ -557,9 +557,9 @@
<Unit72>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/bitmap.inc"/>
<IsPartOfProject Value="True"/>
<CursorPos X="30" Y="34"/>
<TopLine Value="22"/>
<UsageCount Value="107"/>
<CursorPos X="11" Y="61"/>
<TopLine Value="65"/>
<UsageCount Value="109"/>
</Unit72>
<Unit73>
<Filename Value="../../../FPC/FPCCheckout/packages/fcl-image/src/fpcanvas.inc"/>
@ -691,7 +691,7 @@
<UnitName Value="colour_conv"/>
<CursorPos X="11" Y="148"/>
<TopLine Value="140"/>
<UsageCount Value="90"/>
<UsageCount Value="92"/>
</Unit92>
<Unit93>
<Filename Value="../../../cogat/Units/CogatUnits/compcolors.pas"/>
@ -750,7 +750,7 @@
<UnitName Value="plugins"/>
<CursorPos X="86" Y="128"/>
<TopLine Value="128"/>
<UsageCount Value="84"/>
<UsageCount Value="86"/>
</Unit101>
<Unit102>
<Filename Value="../../../Compilertje/Units/CogatUnits/compfiles.pas"/>
@ -832,20 +832,20 @@
<Unit114>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<UnitName Value="compDTM"/>
<CursorPos X="1" Y="133"/>
<TopLine Value="118"/>
<EditorIndex Value="5"/>
<UsageCount Value="22"/>
<CursorPos X="9" Y="79"/>
<TopLine Value="61"/>
<EditorIndex Value="6"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit114>
<Unit115>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dtm"/>
<CursorPos X="23" Y="395"/>
<TopLine Value="357"/>
<CursorPos X="1" Y="753"/>
<TopLine Value="498"/>
<EditorIndex Value="3"/>
<UsageCount Value="65"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit115>
<Unit116>
@ -861,8 +861,8 @@
<UnitName Value="colourpicker"/>
<CursorPos X="53" Y="33"/>
<TopLine Value="15"/>
<EditorIndex Value="10"/>
<UsageCount Value="61"/>
<EditorIndex Value="12"/>
<UsageCount Value="63"/>
<Loaded Value="True"/>
</Unit117>
<Unit118>
@ -888,7 +888,7 @@
<UnitName Value="windowselector"/>
<CursorPos X="76" Y="83"/>
<TopLine Value="65"/>
<UsageCount Value="51"/>
<UsageCount Value="53"/>
</Unit120>
<Unit121>
<Filename Value="../../../../../../usr/lib64/fpc/2.2.4/source/rtl/objpas/classes/classesh.inc"/>
@ -922,23 +922,25 @@
<UnitName Value="dtmutil"/>
<CursorPos X="1" Y="13"/>
<TopLine Value="1"/>
<EditorIndex Value="4"/>
<UsageCount Value="38"/>
<EditorIndex Value="5"/>
<UsageCount Value="40"/>
<Loaded Value="True"/>
</Unit125>
<Unit126>
<Filename Value="../../../cogat/Units/CogatUnits/compmaths.pas"/>
<UnitName Value="CompMaths"/>
<CursorPos X="1" Y="226"/>
<TopLine Value="211"/>
<CursorPos X="15" Y="640"/>
<TopLine Value="636"/>
<EditorIndex Value="7"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit126>
<Unit127>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/dtm.inc"/>
<CursorPos X="1" Y="26"/>
<TopLine Value="4"/>
<EditorIndex Value="11"/>
<UsageCount Value="17"/>
<CursorPos X="53" Y="14"/>
<TopLine Value="1"/>
<EditorIndex Value="13"/>
<UsageCount Value="18"/>
<Loaded Value="True"/>
</Unit127>
<Unit128>
@ -953,124 +955,149 @@
<UnitName Value="CompScript"/>
<CursorPos X="1" Y="529"/>
<TopLine Value="508"/>
<EditorIndex Value="6"/>
<UsageCount Value="13"/>
<EditorIndex Value="8"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit129>
<Unit130>
<Filename Value="../../../../Documents/fpc/rtl/objpas/math.pp"/>
<UnitName Value="math"/>
<CursorPos X="40" Y="34"/>
<TopLine Value="19"/>
<UsageCount Value="10"/>
</Unit130>
<Unit131>
<Filename Value="../../Units/MMLCore/mmath.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mmath"/>
<CursorPos X="35" Y="45"/>
<TopLine Value="9"/>
<EditorIndex Value="4"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit131>
</Units>
<JumpHistory Count="28" HistoryIndex="27">
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="196" Column="48" TopLine="196"/>
<Caret Line="8" Column="76" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="69" Column="3" TopLine="54"/>
<Caret Line="105" Column="38" TopLine="90"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="68" Column="1" TopLine="54"/>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="38" Column="12" TopLine="23"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="147" Column="4" TopLine="132"/>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="465" Column="24" TopLine="450"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="16" Column="37" TopLine="2"/>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="472" Column="24" TopLine="450"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="191" Column="14" TopLine="171"/>
<Caret Line="176" Column="20" TopLine="171"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="24" Column="51" TopLine="19"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="2" Column="46" TopLine="1"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="189" Column="1" TopLine="171"/>
<Caret Line="138" Column="22" TopLine="122"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="10" Column="50" TopLine="9"/>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<Caret Line="18" Column="30" TopLine="1"/>
</Position9>
<Position10>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="25" Column="41" TopLine="10"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="61" Column="24" TopLine="41"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="27" Column="47" TopLine="12"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="8" Column="27" TopLine="1"/>
</Position11>
<Position12>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="236" Column="7" TopLine="231"/>
<Caret Line="49" Column="5" TopLine="31"/>
</Position12>
<Position13>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="34" Column="27" TopLine="13"/>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<Caret Line="63" Column="30" TopLine="48"/>
</Position13>
<Position14>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="87" Column="10" TopLine="72"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="672" Column="16" TopLine="306"/>
</Position14>
<Position15>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="28" Column="33" TopLine="13"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="792" Column="34" TopLine="788"/>
</Position15>
<Position16>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="105" Column="37" TopLine="90"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="488" Column="4" TopLine="492"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="156" Column="39" TopLine="141"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="718" Column="4" TopLine="695"/>
</Position17>
<Position18>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="30" Column="49" TopLine="15"/>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="79" Column="9" TopLine="61"/>
</Position18>
<Position19>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="8" Column="76" TopLine="1"/>
<Filename Value="../../../cogat/Units/CogatUnits/compmaths.pas"/>
<Caret Line="17" Column="44" TopLine="1"/>
</Position19>
<Position20>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="105" Column="38" TopLine="90"/>
<Filename Value="../../../cogat/Units/CogatUnits/compmaths.pas"/>
<Caret Line="53" Column="22" TopLine="38"/>
</Position20>
<Position21>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="38" Column="12" TopLine="23"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="629" Column="32" TopLine="594"/>
</Position21>
<Position22>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="465" Column="24" TopLine="450"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="89" Column="25" TopLine="74"/>
</Position22>
<Position23>
<Filename Value="../../../cogat/compscript.pas"/>
<Caret Line="472" Column="24" TopLine="450"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="228" Column="81" TopLine="224"/>
</Position23>
<Position24>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="176" Column="20" TopLine="171"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="80" Column="60" TopLine="74"/>
</Position24>
<Position25>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="2" Column="46" TopLine="1"/>
<Caret Line="8" Column="66" TopLine="1"/>
</Position25>
<Position26>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="138" Column="22" TopLine="122"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="389" Column="16" TopLine="374"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<Caret Line="18" Column="30" TopLine="1"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="21" Column="28" TopLine="21"/>
</Position27>
<Position28>
<Filename Value="../../../cogat/Units/CogatUnits/compdtm.pas"/>
<Caret Line="61" Column="24" TopLine="41"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="26" Column="28" TopLine="21"/>
</Position28>
<Position29>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="32" Column="30" TopLine="21"/>
</Position29>
<Position30>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="37" Column="29" TopLine="21"/>
</Position30>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>

View File

@ -9,7 +9,7 @@ uses
Interfaces, // this includes the LCL widgetset
Forms, LResources, Window, files, MufasaTypes, Client, TestUnit, finder,
MMLThread, mmlpsthread, bitmaps, colour_conv, plugins, DTM, colourpicker,
windowselector, dtmutil;
windowselector, dtmutil, mmath;
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

View File

@ -9,27 +9,28 @@ const
var
ppdtm: pdtm;
w,h,x,y,dtm: integer;
w,h,x,y,dtm,i: integer;
p,pp: TPointArray;
c,t,asz,ash: TIntegerArray;
begin
p := [Point(0,0), Point(1,1)];
c := [clWhite, clWhite];
t := [0, 0];
asz := [0, 0];
ash := [dtm_Rectangle, dtm_Rectangle];
setlength(ppdtm.p,2);
setlength(ppdtm.c,2);
setlength(ppdtm.t,2);
setlength(ppdtm.asz,2);
setlength(ppdtm.ash,2);
ppdtm.p[0].x := 0;
ppdtm.p[0].y := 0;
ppdtm.c[0] := 16777215;
ppdtm.t[0] := 0;
ppdtm.asz[0] := 0;
ppdtm.asz[0] := dtm_Rectangle;
ppdtm.p[1].x := 1;
ppdtm.p[1].y := 1;
ppdtm.c[1] := 16777215;
ppdtm.t[1] := 0;
ppdtm.asz[1] := 0;
ppdtm.asz[1] := dtm_Rectangle;
ppdtm.p := p;
ppdtm.c := c;
ppdtm.t := t;
ppdtm.asz := asz;
ppdtm.ash := ash;
dtm := AddpDTM(ppdtm);
@ -40,4 +41,10 @@ begin
movemouse(x,y);
end;
if FindDTMs(dtm, p, 0, 0, w-1, h-1) then
begin
writeln('Found ' + inttostr(length(p)) + ' DTM(s). First one at ' +
inttostr(p[0].x) + ', ' + inttostr(p[0].y));
movemouse(p[0].x,p[0].y);
end;
end.

View File

@ -3,6 +3,13 @@ begin
Result := CurrThread.Client.MDTM.FindDTM(DTM, x, y, x1, y1, x2, y2);
end;
function ps_FindDTMs(DTM: Integer; var p: TPointArray; x1, y1, x2, y2: Integer): Boolean;
begin
Result := CurrThread.Client.MDTM.FindDTMs(DTM, p, x1, y1, x2, y2);
end;
function ps_DTMFromString(DTMString: String): Integer;
var
dtm: pDTM;

View File

@ -22,6 +22,7 @@ Sender.AddFunction(@tDTMTopDTM, 'Function tDTMTopDTM(Const DTM: TDTM): pDTM;');
Sender.AddFunction(@ps_DTMFromString, 'function DTMFromString(DTMString: String): Integer;');
Sender.AddFunction(@ps_FreeDTM, 'procedure FreeDTM(DTM: Integer);');
Sender.AddFunction(@ps_FindDTM, 'function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer): Boolean;');
Sender.AddFunction(@ps_FindDTMs, 'function FindDTMs(DTM: Integer; var p: TPointArray; x1, y1, x2, y2: Integer): Boolean;');
Sender.AddFunction(@ps_addDTM, 'function AddDTM(d: TDTM): Integer;');
Sender.AddFunction(@ps_addpDTM, 'function AddpDTM(d: pDTM): Integer;');
@ -30,6 +31,7 @@ sender.AddFunction(@power,'function pow(base,exponent : extended) : extended');
Sender.AddFunction(@max,'function Max(a, b: Integer): Integer;');
Sender.AddFunction(@min,'function Min(a, b: Integer): Integer;');
Sender.AddFunction(@pssqr,'function Sqr(e : extended) : extended;');
Sender.AddFunction(@point,'function Point(x,y:integer) : TPoint;');
Sender.AddFunction(@Freeze, 'function freeze:boolean;');
Sender.AddFunction(@Unfreeze, 'function unfreeze: boolean;');

View File

@ -18,7 +18,7 @@ type
function FindDTM(DTM: Integer; var x, y: Integer; x1, y1, x2,
y2: Integer): Boolean;
{ function FindDTMs(DTM: Integer; var Points: TPointArray; x1, y1, x2,
function FindDTMs(DTM: Integer; var Points: TPointArray; x1, y1, x2,
y2: Integer): Boolean;
function FindDTMRotated(DTM: Integer; var x, y: Integer; x1, y1, x2,
y2: Integer; sAngle, eAngle, aStep: Extended;
@ -26,9 +26,18 @@ type
function FindDTMsRotated(DTM: Integer; var Points: TPointArray; x1,
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; var aFound: T2DExtendedArray)
: Boolean; }
: Boolean;
function pFindDTM(DTM: pDTM; var x, y: Integer; x1, y1, x2, y2:
Integer): Boolean;
function pFindDTMs(DTM: pDTM; var Points: TPointArray; x1, y1, x2,
y2: Integer): Boolean;
function pFindDTMRotated(DTM: pDTM; var x, y: Integer; x1, y1, x2,
y2: Integer; sAngle, eAngle, aStep: Extended;
var aFound: Extended): Boolean;
function pFindDTMsRotated(DTM: pDTM; var Points: TPointArray; x1,
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; var aFound: T2DExtendedArray)
: Boolean;
constructor Create(Owner: TObject);
destructor Destroy; override;
@ -43,6 +52,7 @@ type
DTMList: Array Of pDTM;
FreeSpots: Array Of Integer;
end;
const
dtm_Rectangle = 0;
dtm_Cross = 1;
@ -215,6 +225,31 @@ Begin
Result := False;
End;
function RotatePoints(P: TPointArray; A, cx, cy: Extended): TPointArray; inline;
var
I, L: Integer;
begin
L := High(P);
SetLength(Result, L + 1);
for I := 0 to L do
begin
Result[I].X := Round(cx + cos(A) * (p[i].x - cx) - sin(A) * (p[i].y - cy));
Result[I].Y := Round(cy + sin(A) * (p[i].x - cx) + cos(A) * (p[i].y - cy));
end;
end;
{/\
Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
/\}
function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint; inline;
begin
Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
end;
function HexToInt(HexNum: string): LongInt;inline;
begin
@ -390,8 +425,8 @@ begin
MaxSubPointDist.Y := Max(DTM.p[I].y, MaxSubPointDist.Y);
end;
X2 := X2 - MaxSubPointDist.X;
Y2 := Y2 - MaxSubPointDist.Y;
X2 := X2 - MaxSubPointDist.X - 1;
Y2 := Y2 - MaxSubPointDist.Y - 1;
X1 := X1 + MaxSubPointDist.X;
Y1 := Y1 + MaxSubPointDist.Y;
{If X2 > X1 then
@ -442,5 +477,369 @@ begin
Result := False;
end;
{/\
Tries to find the given DTM (index). Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
/\}
function TMDTM.FindDTMs(DTM: Integer; Var Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
Var
temp: pDTM;
Begin
If GetDTM(DTM, temp) Then
Result := pFindDTMs(temp, Points, x1, y1, x2, y2)
Else
Begin
SetLength(Points, 0);
Result := False;
End;
End;
{/\
Tries to find the given pDTM. Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
/\}
Function TMDTM.pFindDTMs(DTM: pDTM; Var Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
Var
mP: TPointArray;
I, J, H, dH: Integer;
Found: Boolean;
TempTP: TPoint;
MaxSubPointDist: TPoint;
Begin
Result := False;
MaxSubPointDist := Point(0,0);
SetLength(Points, 0);
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
X2 := X2 - MaxSubPointDist.X - 1;
Y2 := Y2 - MaxSubPointDist.Y - 1;
X1 := X1 + MaxSubPointDist.X;
Y1 := Y1 + MaxSubPointDist.Y;
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
For I := 0 To H Do
Begin
Found := True;
For J := 1 To dH Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
Found := False;
Break;
End;
End;
If Found Then
Begin
Result := True;
SetLength(Points, Length(Points) + 1);
Points[High(Points)] := mP[I];
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := Length(Points) > 0;
End;
{/\
Tries to find the given DTM (index). If found will put the point the dtm has
been found at in x, y and result to true.
Will rotate the DTM starting at sAngle, increasing by aStep until eAngle has been reached, or when the DTM has been found.
Returns all Angles in an Extended array.
/\}
Function TMDTM.FindDTMRotated(DTM: Integer; Var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; Var aFound: Extended): Boolean;
Var
temp: pDTM;
Begin
If GetDTM(DTM, temp) Then
Result := pFindDTMRotated(temp, x, y, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound)
Else
Begin
x := 0;
y := 0;
aFound := 0.0;
Result := False;
End;
End;
{/\
Tries to find the given pDTM. If found will put the point the dtm has
been found at in x, y and result to true.
Will rotate the DTM starting at sAngle, increasing by aStep until eAngle has been reached, or when the DTM has been found.
Returns all Angles in an Extended array.
/\}
Function TMDTM.pFindDTMRotated(DTM: pDTM; Var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; Var aFound: Extended): Boolean;
Var
mP: TPointArray;
I, J, H, dH, R, W: Integer;
Angle: Array Of Extended;
tAngle: Extended;
Found: Boolean;
TempTP: TPoint;
MaxSubPointDist: TPoint;
Begin
MaxSubPointDist := Point(0,0);
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
X2 := X2 - MaxSubPointDist.X - 1;
Y2 := Y2 - MaxSubPointDist.Y - 1;
X1 := X1 + MaxSubPointDist.X;
Y1 := Y1 + MaxSubPointDist.Y;
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
For I := 0 To H Do
Begin
// Use MainPoint's AreaSize and Shape.
// For Loop on mP, depending on the AreaShape. Then on all the code beneath
// this point, use the var that is retrieved from the for loop.
Found := True;
SetLength(Angle, 0);
Found := True;
For J := 1 To dH Do
Begin
If Length(Angle) = 0 Then
Begin
tAngle := sAngle;
While tAngle <= eAngle Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, tAngle, mP[I].X, mP[I].Y);
If AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
SetLength(Angle, Length(Angle) + 1);
Angle[High(Angle)] := tAngle;
Found := True;
End;
tAngle := tAngle + aStep;
End;
End;
Found := Length(Angle) > 0;
For R := 0 To High(Angle) Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, Angle[R], mP[I].X, mP[I].Y);
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
For W := R To High(Angle) - 1 Do
Angle[W] := Angle[W + 1];
SetLength(Angle, Length(Angle) - 1);
If Length(Angle) = 0 Then
Begin
Found := False;
Break;
End;
End;
End;
If Not Found Then
Break;
End;
If Found Then
Begin
Result := True;
x := mP[I].X;
y := mP[I].Y;
aFound := Angle[0];
TClient(Client).MWindow.UnFreeze();
Exit;
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := False;
End;
{/\
Tries to find the given DTM (index). Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
Will rotate the DTM starting at sAngle, increasing by aStep until eAngle has been reached.
Does not stop rotating when one occurance of a DTM has been found.
Returns all Angles in a Two Dimensional Extended array.
/\}
Function TMDTM.FindDTMsRotated(DTM: Integer; Var Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; Var aFound: T2DExtendedArray): Boolean;
Var
temp: pDTM;
Begin
If GetDTM(DTM, temp) Then
Result := pFindDTMsRotated(temp, Points, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound)
Else
Begin
SetLength(Points, 0);
SetLength(aFound, 0);
Result := False;
End;
End;
{/\
Tries to find the given pDTM. Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
Will rotate the DTM starting at sAngle, increasing by aStep until eAngle has been reached.
Does not stop rotating when one occurance of a DTM has been found.
Returns all Angles in a Two Dimensional Extended array.
/\}
Function TMDTM.pFindDTMsRotated(DTM: pDTM; Var Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; Var aFound: T2DExtendedArray): Boolean;
Var
mP: TPointArray;
I, J, H, dH, R, W, PCount: Integer;
Angle: TExtendedArray;
tAngle: Extended;
Found: Boolean;
TempTP: TPoint;
MaxSubPointDist: TPoint;
Begin
MaxSubPointDist := Point(0,0);
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
X2 := X2 - MaxSubPointDist.X - 1;
Y2 := Y2 - MaxSubPointDist.Y - 1;
X1 := X1 + MaxSubPointDist.X;
Y1 := Y1 + MaxSubPointDist.Y;
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
PCount := 0;
For I := 0 To H Do
Begin
//WriteLn('I: ' + IntToStr(I));
// Use MainPoint's AreaSize and Shape.
// For Loop on mP, depending on the AreaShape. Then on all the code beneath
// this point, use the var that is retrieved from the for loop.
//Found := True;
SetLength(Angle, 0);
Found := True;
For J := 1 To dH Do
Begin
If Length(Angle) = 0 Then
Begin
tAngle := sAngle;
While tAngle <= eAngle Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, tAngle, mP[I].X, mP[I].Y);
If AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
SetLength(Angle, Length(Angle) + 1);
Angle[High(Angle)] := tAngle;
Found := True;
End;
tAngle := tAngle + aStep;
End;
End;
Found := Length(Angle) > 0;
{If Found Then
WriteLn('Angle length after first search: ' + IntToStr(Length(Angle))); }
For R := 0 To High(Angle) Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, Angle[R], mP[I].X, mP[I].Y);
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
For W := R To High(Angle) - 1 Do
Angle[W] := Angle[W + 1];
SetLength(Angle, Length(Angle) - 1);
If Length(Angle) = 0 Then
Begin
Found := False;
Break;
End;
End;
End;
If Not Found Then
Break;
End;
If Found Then
Begin
SetLength(Points, PCount + 1);
Points[PCount] := mP[I];
PCount := PCount + 1;
SetLength(aFound, Length(aFound) + 1);
aFound[High(aFound)] := Angle;
Continue;
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := Length(Points) > 0;
End;
end.

View File

@ -29,9 +29,14 @@ type
TVariantArray = Array of Variant;
TIntegerArray = Array of Integer;
TExtendedArray = Array of Extended;
T2DExtendedArray = Array of Array of Extended;
{ DTM Types }
{
Possibly add .name too?
Then one could give DTM names, which would be easy for debugging.
}
pDTM = record
p: TPointArray;
c, t, asz, ash: TIntegerArray;