Skip to content

Commit

Permalink
move TQuad to unit
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 22, 2023
1 parent f368231 commit 4153b16
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 100 deletions.
6 changes: 5 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="146">
<Units Count="147">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -1006,6 +1006,10 @@
<Filename Value="script/imports/simba/simba.import_circle.pas"/>
<IsPartOfProject Value="True"/>
</Unit145>
<Unit146>
<Filename Value="simba.quad.pas"/>
<IsPartOfProject Value="True"/>
</Unit146>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2 changes: 1 addition & 1 deletion Source/matchtemplate/simba.matchtemplate_helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function DoFFT2(const Matrix: TSingleMatrix; const outW, outH: Integer): TComple
H := Matrix.Height - 1;
for Y := 0 to H do
for X := 0 to W do
Spec[Y, X].Re := Matrix[Y, X]; // WTF!!
Spec[Y, X].Re := Matrix[Y, X];

Result := FFTPACK.FFT2(Spec);
end;
Expand Down
30 changes: 30 additions & 0 deletions Source/matchtemplate/simba.matchtemplate_matrix.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ interface
simba.mufasatypes;

type
TComplex = record
Re, Im: Single;
end;
TComplexArray = array of TComplex;
TComplexMatrix = array of TComplexArray;

TComplexMatrixHelper = type helper for TComplexMatrix
function Width: Integer;
function Height: Integer;
procedure SetSize(AWidth, AHeight: Integer);
end;

TRGBComplexMatrix = record
Width: Integer;
Height: Integer;
Expand Down Expand Up @@ -417,6 +429,24 @@ function Norm(const Matrix: TRGBMatrix): Double;
Result[Y, X] := Left[Y, X] / Right[Y, X];
end;

function TComplexMatrixHelper.Width: Integer;
begin
if (Length(Self) > 0) then
Result := Length(Self[0])
else
Result := 0;
end;

function TComplexMatrixHelper.Height: Integer;
begin
Result := Length(Self);
end;

procedure TComplexMatrixHelper.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self, AHeight, AWidth);
end;

procedure TRGBMatrix.SetSize(AWidth, AHeight: Integer);
begin
SetLength(Self.R, AHeight, AWidth);
Expand Down
4 changes: 2 additions & 2 deletions Source/package/simba.package_autoupdater.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ implementation

uses
simba.mufasatypes, simba.package, simba.package_installer,
simba.main, simba.outputform, simba.package_menubuilder;
simba.main, simba.outputform, simba.package_menubuilder, simba.threading;

type
TPackageUpdater = class(TThread)
Expand All @@ -35,7 +35,7 @@ TPackageUpdater = class(TThread)

procedure TPackageUpdater.DoTerminateOnMainThread(Sender: TObject);
begin
AssertMainThread('TPackageUpdater');
CheckMainThread('TPackageUpdater');

// Update main menu
BuildPackageMenus(FPackages, SimbaForm.MenuBar);
Expand Down
3 changes: 2 additions & 1 deletion Source/script/imports/simba/simba.import_quad.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ procedure ImportQuad(Compiler: TSimbaScript_Compiler);
implementation

uses
lptypes;
lptypes,
simba.quad;

(*
TQuad
Expand Down
10 changes: 3 additions & 7 deletions Source/simba.atpa.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
}
unit simba.atpa;

{$DEFINE SIMBA_MAX_OPTIMIZATION}
{$i simba.inc}

{$IFOPT D-}
{$OPTIMIZATION LEVEL4}
{$ENDIF}

interface

uses
Classes, SysUtils,
Classes, SysUtils, Math,
simba.mufasatypes;

type
Expand Down Expand Up @@ -66,8 +63,7 @@ interface
implementation

uses
math,
simba.tpa, simba.algo_sort, simba.overallocatearray, simba.integermatrix;
simba.tpa, simba.algo_sort, simba.overallocatearray, simba.integermatrix, simba.quad;

function T2DPointArrayHelper.Sort(Weights: TIntegerArray; LowToHigh: Boolean): T2DPointArray;
var
Expand Down
9 changes: 0 additions & 9 deletions Source/simba.circle.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ interface
simba.mufasatypes;

type
PCircle = ^TCircle;
TCircle = record
X: Integer;
Y: Integer;
Radius: Integer;
end;
PCircleArray = ^TCircleArray;
TCircleArray = array of TCircle;

TCircleHelper = type helper for TCircle
public const
ZERO: TCircle = (X: 0; Y: 0; Radius: 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/simba.image.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface
Classes, SysUtils, Graphics,
simba.baseclass, simba.mufasatypes, simba.image_textdrawer,
simba.colormath, simba.colormath_distance, simba.matchtemplate,
simba.circle;
simba.circle, simba.quad;

type
{$PUSH}
Expand Down
44 changes: 20 additions & 24 deletions Source/simba.mufasatypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
interface

uses
Classes, SysUtils, Graphics, fpjson;
Classes, SysUtils, Graphics,
fpjson;

{$PUSH}
{$SCOPEDENUMS ON}
Expand Down Expand Up @@ -316,24 +317,32 @@ TBox = record
PBoxArray = ^TBoxArray;
TBoxArray = array of TBox;

TComplex = record
Re, Im: Single;
PQuad = ^TQuad;
TQuad = record
Top: TPoint;
Right: TPoint;
Bottom: TPoint;
Left: TPoint;
end;
TComplexArray = array of TComplex;
TComplexMatrix = array of TComplexArray;
TQuadArray = array of TQuad;
PQuadArray = ^TQuadArray;

PCircle = ^TCircle;
TCircle = record
X: Integer;
Y: Integer;
Radius: Integer;
end;
PCircleArray = ^TCircleArray;
TCircleArray = array of TCircle;

{$DEFINE HEADER}
{$i generics.inc}
{$i quad.inc}
{$i box.inc}
{$i boxarray.inc}
{$i point.inc}
{$i string.inc}

{$DEFINE MACRO_HELPER_NAME := TComplexMatrixBaseHelper}
{$DEFINE MACRO_MATRIX_NAME := TComplexMatrix}
{$i matrix.inc}

{$DEFINE MACRO_HELPER_NAME := TByteMatrixBaseHelper}
{$DEFINE MACRO_MATRIX_NAME := TByteMatrix}
{$i matrix.inc}
Expand Down Expand Up @@ -408,8 +417,6 @@ ESimbaException = class(Exception);
procedure SimbaException(Message: String; Args: array of const); overload;
procedure SimbaException(Message: String); overload;

procedure AssertMainThread(const Method: String);

// Writable const
const
SimbaProcessType: ESimbaProcessType = ESimbaProcessType.UNKNOWN;
Expand All @@ -419,20 +426,15 @@ implementation
uses
math, forms, uregexpr, strutils, jsonparser, jsonscanner,
simba.math, simba.overallocatearray, simba.geometry,
simba.algo_sort, simba.tpa, simba.random;
simba.algo_sort, simba.random;

{$DEFINE BODY}
{$i generics.inc}
{$i quad.inc}
{$i box.inc}
{$i boxarray.inc}
{$i point.inc}
{$i string.inc}

{$DEFINE MACRO_HELPER_NAME := TComplexMatrixBaseHelper}
{$DEFINE MACRO_MATRIX_NAME := TComplexMatrix}
{$i matrix.inc}

{$DEFINE MACRO_HELPER_NAME := TByteMatrixBaseHelper}
{$DEFINE MACRO_MATRIX_NAME := TByteMatrix}
{$i matrix.inc}
Expand Down Expand Up @@ -495,12 +497,6 @@ procedure SimbaException(Message: String);
raise ESimbaException.Create(Message);
end;

procedure AssertMainThread(const Method: String);
begin
if (GetCurrentThreadID() <> MainThreadID) then
SimbaException('Not called on main thread: ' + Method);
end;

procedure SimbaDebugLn(const Msg: String);
begin
DebugLn(Msg);
Expand Down
Loading

0 comments on commit 4153b16

Please sign in to comment.