From 5a172e0023bee8396ab68eedc3bd5e973caee1f2 Mon Sep 17 00:00:00 2001 From: ollydev Date: Tue, 10 May 2022 02:05:07 +0100 Subject: [PATCH] More native methods for lape's internal methods --- .../simba.codetools_arrayhelpers.pas | 1 + Source/generics/simba.generics_array.pas | 268 ++++++++++++++++-- .../wrappers_simba/simba.imports_finder.inc | 4 +- .../wrappers_simba/simba.imports_internal.inc | 30 +- .../wrappers_simba/simba.imports_math.inc | 13 +- .../wrappers_simba/simba.imports_ocr.inc | 1 + .../simba.wrappers_internal.inc | 116 ++++++++ .../wrappers_simba/simba.wrappers_math.inc | 35 +-- .../wrappers_simba/simba.wrappers_ocr.inc | 6 + 9 files changed, 406 insertions(+), 68 deletions(-) diff --git a/Source/codetools/simba.codetools_arrayhelpers.pas b/Source/codetools/simba.codetools_arrayhelpers.pas index 673e06e0e..e523156d2 100644 --- a/Source/codetools/simba.codetools_arrayhelpers.pas +++ b/Source/codetools/simba.codetools_arrayhelpers.pas @@ -99,6 +99,7 @@ implementation 'function .Stddev: Double; external;', 'function .Slice(Start, Stop, Step: Integer): ; external;', 'function .Remove(Value: ): Boolean; external;', + 'function .RemoveAll(Value: ): Integer; external;', 'procedure .Delete(Index, Count: Integer); external;', 'procedure .Delete(Index: Integer; Count: Integer = High(Integer)); external;', 'procedure .Insert(Item: ; Index: Integer); external;', diff --git a/Source/generics/simba.generics_array.pas b/Source/generics/simba.generics_array.pas index a5068ef9c..2268ded87 100644 --- a/Source/generics/simba.generics_array.pas +++ b/Source/generics/simba.generics_array.pas @@ -29,46 +29,70 @@ interface generic procedure Sort<_T>(var Arr: specialize TArray<_T>); generic function Sorted<_T>(const Arr: specialize TArray<_T>): specialize TArray<_T>; -procedure Sort(var Arr: TIntegerArray); +procedure Sort(var Arr: TIntegerArray); overload; +procedure Sort(var Arr: TSingleArray); overload; +procedure Sort(var Arr: TDoubleArray); overload; +procedure Sort(var Arr: TExtendedArray); overload; + procedure Sort(var Arr: TPointArray; var Weights: TIntegerArray; SortUp: Boolean); overload; procedure Sort(var Arr: TPointArray; var Weights: TIntegerArray; Lo, Hi: Integer; SortUp: Boolean); overload; procedure Sort(var Arr: T2DPointArray; var Weights: TIntegerArray; SortUp: Boolean); overload; procedure Sort(var Arr: T2DPointArray; var Weights: TIntegerArray; Lo, Hi: Integer; SortUp: Boolean); overload; -function MinA(const Arr: TIntegerArray): Integer; overload; -function MinA(const Arr: TExtendedArray): Extended; overload; -function MaxA(const Arr: TIntegerArray): Integer; overload; -function MaxA(const Arr: TExtendedArray): Extended; overload; +function Min(const Arr: TIntegerArray): Integer; overload; +function Min(const Arr: TSingleArray): Single; overload; +function Min(const Arr: TDoubleArray): Double; overload; +function Min(const Arr: TExtendedArray): Extended; overload; + +function Max(const Arr: TIntegerArray): Integer; overload; +function Max(const Arr: TSingleArray): Single; overload; +function Max(const Arr: TDoubleArray): Double; overload; +function Max(const Arr: TExtendedArray): Extended; overload; + function Sum(const Arr: TIntegerArray): Int64; overload; +function Sum(const Arr: TSingleArray): Extended; overload; +function Sum(const Arr: TDoubleArray): Extended; overload; function Sum(const Arr: TExtendedArray): Extended; overload; -function Average(const Arr: TIntegerArray): Int64; overload; -function Average(const Arr: TExtendedArray): Extended; overload; +function Sum(const Arr: TPointArray): TPoint; overload; + +function Mean(const Arr: TIntegerArray): Int64; overload; +function Mean(const Arr: TExtendedArray): Extended; overload; + function Mode(const Arr: TIntegerArray): Integer; -procedure Reverse(var Arr: TIntegerArray); -procedure Reverse(var Arr: TPointArray); -procedure Reverse(var Arr: T2DPointArray); -function IndexOf(const Item: Integer; const Arr: TIntegerArray): Integer; -function IndexOf(const Item: String; const Arr: TStringArray): Integer; -function IndexOf(const Item: TPoint; const Arr: TPointArray): Integer; +procedure Reverse(var Arr: TIntegerArray); overload; +procedure Reverse(var Arr: TPointArray); overload; +procedure Reverse(var Arr: T2DPointArray); overload; -function IndicesOf(const Item: Integer; const Arr: TIntegerArray): TIntegerArray; -function IndicesOf(const Item: String; const Arr: TStringArray): TIntegerArray; -function IndicesOf(const Item: TPoint; const Arr: TPointArray): TIntegerArray; +function IndexOf(const Item: Integer; const Arr: TIntegerArray): Integer; overload; +function IndexOf(const Item: String; const Arr: TStringArray): Integer; overload; +function IndexOf(const Item: TPoint; const Arr: TPointArray): Integer; overload; + +function IndicesOf(const Item: Integer; const Arr: TIntegerArray): TIntegerArray; overload; +function IndicesOf(const Item: String; const Arr: TStringArray): TIntegerArray; overload; +function IndicesOf(const Item: TPoint; const Arr: TPointArray): TIntegerArray; overload; // TPoint: Use Matrix -function Unique(const Arr: TPointArray): TPointArray; +function Unique(const Arr: TPointArray): TPointArray; overload; // Integer: Use Hashing -function Unique(const Arr: TIntegerArray): TIntegerArray; +function Unique(const Arr: TIntegerArray): TIntegerArray; overload; // String: Use Hashing -function Unique(const Arr: TStringArray): TStringArray; +function Unique(const Arr: TStringArray): TStringArray; overload; -// Double: Use SameValue -function IndexOf(const Item: Double; const Arr: TDoubleArray): Integer; -function IndicesOf(const Item: Double; const Arr: TDoubleArray): TIntegerArray; -function Unique(const Arr: TDoubleArray): TDoubleArray; +// Floats: Use SameValue +function IndexOf(const Item: Single; const Arr: TSingleArray): Integer; overload; +function IndexOf(const Item: Double; const Arr: TDoubleArray): Integer; overload; +function IndexOf(const Item: Extended; const Arr: TExtendedArray): Integer; overload; + +function IndicesOf(const Item: Single; const Arr: TSingleArray): TIntegerArray; overload; +function IndicesOf(const Item: Double; const Arr: TDoubleArray): TIntegerArray; overload; +function IndicesOf(const Item: Extended; const Arr: TExtendedArray): TIntegerArray; overload; + +function Unique(const Arr: TSingleArray): TSingleArray; overload; +function Unique(const Arr: TDoubleArray): TDoubleArray; overload; +function Unique(const Arr: TExtendedArray): TExtendedArray; overload; implementation @@ -374,25 +398,45 @@ procedure Sort(var Arr: T2DPointArray; var Weights: TIntegerArray; SortUp: Boole procedure Sort(var Arr: T2DPointArray; var Weights: TIntegerArray; Lo, Hi: Integer; SortUp: Boolean); begin - specialize QuickSortWeighted(Arr, Weights, Lo, Hi, SortUp); + specialize QuickSortWeighted(Arr, Weights, Lo, Hi, SortUp); end; -function MinA(const Arr: TIntegerArray): Integer; +function Min(const Arr: TIntegerArray): Integer; begin Result := specialize MinA(Arr); end; -function MinA(const Arr: TExtendedArray): Extended; +function Min(const Arr: TSingleArray): Single; +begin + Result := specialize MinA(Arr); +end; + +function Min(const Arr: TDoubleArray): Double; +begin + Result := specialize MinA(Arr); +end; + +function Min(const Arr: TExtendedArray): Extended; begin Result := specialize MinA(Arr); end; -function MaxA(const Arr: TIntegerArray): Integer; +function Max(const Arr: TIntegerArray): Integer; begin Result := specialize MaxA(Arr); end; -function MaxA(const Arr: TExtendedArray): Extended; +function Max(const Arr: TSingleArray): Single; +begin + Result := specialize MaxA(Arr); +end; + +function Max(const Arr: TDoubleArray): Double; +begin + Result := specialize MaxA(Arr); +end; + +function Max(const Arr: TExtendedArray): Extended; begin Result := specialize MaxA(Arr); end; @@ -402,19 +446,34 @@ function Sum(const Arr: TIntegerArray): Int64; Result := specialize Sum(Arr); end; +function Sum(const Arr: TSingleArray): Extended; +begin + Result := specialize Sum(Arr); +end; + +function Sum(const Arr: TDoubleArray): Extended; +begin + Result := specialize Sum(Arr); +end; + function Sum(const Arr: TExtendedArray): Extended; begin Result := specialize Sum(Arr); end; -function Average(const Arr: TIntegerArray): Int64; +function Sum(const Arr: TPointArray): TPoint; +begin + Result := specialize Sum(Arr); +end; + +function Mean(const Arr: TIntegerArray): Int64; begin Result := Sum(Arr); if (Result <> 0) then Result := Result div Length(Arr); end; -function Average(const Arr: TExtendedArray): Extended; +function Mean(const Arr: TExtendedArray): Extended; begin Result := Sum(Arr); if (Result <> 0) then @@ -431,6 +490,21 @@ procedure Sort(var Arr: TIntegerArray); specialize QuickSort(Arr, Low(Arr), High(Arr)); end; +procedure Sort(var Arr: TSingleArray); +begin + specialize QuickSort(Arr, Low(Arr), High(Arr)); +end; + +procedure Sort(var Arr: TDoubleArray); +begin + specialize QuickSort(Arr, Low(Arr), High(Arr)); +end; + +procedure Sort(var Arr: TExtendedArray); +begin + specialize QuickSort(Arr, Low(Arr), High(Arr)); +end; + procedure Reverse(var Arr: TIntegerArray); begin specialize Reverse(Arr); @@ -587,6 +661,17 @@ function Unique(const Arr: TStringArray): TStringArray; Result := Buffer.Trim(); end; +function IndexOf(const Item: Single; const Arr: TSingleArray): Integer; +var + I: Integer; +begin + for I := 0 to High(Arr) do + if SameValue(Item, Arr[I]) then + Exit(I); + + Result := -1; +end; + function IndexOf(const Item: Double; const Arr: TDoubleArray): Integer; var I: Integer; @@ -598,6 +683,31 @@ function IndexOf(const Item: Double; const Arr: TDoubleArray): Integer; Result := -1; end; +function IndexOf(const Item: Extended; const Arr: TExtendedArray): Integer; +var + I: Integer; +begin + for I := 0 to High(Arr) do + if SameValue(Item, Arr[I]) then + Exit(I); + + Result := -1; +end; + +function IndicesOf(const Item: Single; const Arr: TSingleArray): TIntegerArray; +var + I: Integer; + Buffer: specialize TSimbaOverAllocateArray; +begin + Buffer.Init(4); + + for I := 0 to High(Arr) do + if SameValue(Item, Arr[I]) then + Buffer.Add(I); + + Result := Buffer.Trim(); +end; + function IndicesOf(const Item: Double; const Arr: TDoubleArray): TIntegerArray; var I: Integer; @@ -612,6 +722,62 @@ function IndicesOf(const Item: Double; const Arr: TDoubleArray): TIntegerArray; Result := Buffer.Trim(); end; +function IndicesOf(const Item: Extended; const Arr: TExtendedArray): TIntegerArray; +var + I: Integer; + Buffer: specialize TSimbaOverAllocateArray; +begin + Buffer.Init(4); + + for I := 0 to High(Arr) do + if SameValue(Item, Arr[I]) then + Buffer.Add(I); + + Result := Buffer.Trim(); +end; + +function Unique(const Arr: TSingleArray): TSingleArray; +var + I, J, Size: Integer; + Value: Single; + Table: array of record + Bucket: TSingleArray; + Count: Integer; + end; + Buffer: specialize TSimbaOverAllocateArray; +label + Next; +begin + Buffer.Init(); + + SetLength(Table, NextPower2(Length(Arr))); + Size := High(Table); + + for i := 0 to High(Arr) do + begin + Value := Arr[i]; + + with Table[Round(Value) and Size] do + begin + for J := 0 to Count - 1 do + if SameValue(Value, Bucket[J]) then + goto Next; + + if (Count >= Length(Bucket)) then + SetLength(Bucket, 4 + (Length(Bucket) * 2)); + + Bucket[Count] := Value; + Inc(Count); + + Buffer.Add(Value); + end; + + Next: + end; + + Result := Buffer.Trim(); +end; + function Unique(const Arr: TDoubleArray): TDoubleArray; var I, J, Size: Integer; @@ -654,5 +820,47 @@ function Unique(const Arr: TDoubleArray): TDoubleArray; Result := Buffer.Trim(); end; +function Unique(const Arr: TExtendedArray): TExtendedArray; +var + I, J, Size: Integer; + Value: Extended; + Table: array of record + Bucket: TExtendedArray; + Count: Integer; + end; + Buffer: specialize TSimbaOverAllocateArray; +label + Next; +begin + Buffer.Init(); + + SetLength(Table, NextPower2(Length(Arr))); + Size := High(Table); + + for i := 0 to High(Arr) do + begin + Value := Arr[i]; + + with Table[Round(Value) and Size] do + begin + for J := 0 to Count - 1 do + if SameValue(Value, Bucket[J]) then + goto Next; + + if (Count >= Length(Bucket)) then + SetLength(Bucket, 4 + (Length(Bucket) * 2)); + + Bucket[Count] := Value; + Inc(Count); + + Buffer.Add(Value); + end; + + Next: + end; + + Result := Buffer.Trim(); +end; + end. diff --git a/Source/script/wrappers_simba/simba.imports_finder.inc b/Source/script/wrappers_simba/simba.imports_finder.inc index 4dab02899..656e6cb05 100644 --- a/Source/script/wrappers_simba/simba.imports_finder.inc +++ b/Source/script/wrappers_simba/simba.imports_finder.inc @@ -33,10 +33,10 @@ addGlobalFunc('function FindColorSpiralTolerance(var x, y: Integer; color, xs, y addGlobalFunc('function FindColorsSpiralTolerance(x, y: Integer; var Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer): Boolean', @_LapeFindColorsSpiralTolerance); addGlobalFunc('function FindColoredArea(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea: Integer): Boolean', @_LapeFindColoredArea); addGlobalFunc('function FindColoredAreaTolerance(var x, y: Integer; Color, xs, ys, xe, ye, MinArea, Tol: Integer): Boolean', @_LapeFindColoredAreaTolerance); -addGlobalFunc('function FindDeformedBitmapToleranceIn(bitmap: Integer; var x, y: Integer; xs, ys, xe, ye: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; var accuracy: Extended): Boolean', @_LapeFindDeformedBitmapToleranceIn); +addGlobalFunc('function FindDeformedBitmapToleranceIn(bitmap: TMufasaBitmap; var x, y: Integer; xs, ys, xe, ye: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; var accuracy: Extended): Boolean', @_LapeFindDeformedBitmapToleranceIn); addGlobalFunc('function FindTemplate(Templ: TMufasaBitmap; out x, y: Integer; Formula: ETMFormula; xs,ys,xe,ye: Integer; MinMatch: Extended; DynamicAdjust: Boolean = True): Boolean', @_LapeFindTemplate); addGlobalFunc('function FindTemplateEx(Templ: TMufasaBitmap; out TPA: TPointArray; Formula: ETMFormula; xs,ys,xe,ye: Integer; MinMatch: Extended; DynamicAdjust: Boolean = True): Boolean', @_LapeFindTemplateEx); -addGlobalFunc('function FindTextMatrix(Text, Font: String; constref Matrix: T2DIntegerArray; out Bounds: TBox): Single', @_LapeFindTextMatrix); +addGlobalFunc('function FindTextMatrix(Text, Font: String; const Matrix: T2DIntegerArray; out Bounds: TBox): Single', @_LapeFindTextMatrix); addGlobalFunc('function FindTextColor(Text, Font: String; Color, Tolerance: Integer; X1, Y1, X2, Y2: Integer; out Bounds: TBox): Single; overload', @_LapeFindTextColor); addGlobalFunc('function FindTextColor(Text, Font: String; Color, Tolerance: Integer; X1, Y1, X2, Y2: Integer; MinMatch: Single = 1): Boolean; overload', @_LapeFindTextColorEx); addGlobalFunc('function FindText(Text, Font: String; X1, Y1, X2, Y2: Integer; out Bounds: TBox): Single; overload', @_LapeFindText); diff --git a/Source/script/wrappers_simba/simba.imports_internal.inc b/Source/script/wrappers_simba/simba.imports_internal.inc index adf00c8a3..412444f55 100644 --- a/Source/script/wrappers_simba/simba.imports_internal.inc +++ b/Source/script/wrappers_simba/simba.imports_internal.inc @@ -2,17 +2,43 @@ addGlobalFunc('procedure _Write(S: String); override', @_LapeWrite); addGlobalFunc('procedure _WriteLn; override', @_LapeWriteLn); addGlobalFunc('procedure _Sort(var a: TIntegerArray); overload;', @_LapeSort_IntegerArray); +addGlobalFunc('procedure _Sort(var a: TSingleArray); overload;', @_LapeSort_SingleArray); +addGlobalFunc('procedure _Sort(var a: TDoubleArray); overload;', @_LapeSort_DoubleArray); +addGlobalFunc('procedure _Sort(var a: TExtendedArray); overload;', @_LapeSort_ExtendedArray); addGlobalFunc('function _Unique(const a: TPointArray): TPointArray; overload', @_LapeUnique_PointArray); addGlobalFunc('function _Unique(const a: TIntegerArray): TIntegerArray; overload', @_LapeUnique_IntegerArray); +addGlobalFunc('function _Unique(const a: TSingleArray): TSingleArray; overload', @_LapeUnique_SingleArray); addGlobalFunc('function _Unique(const a: TDoubleArray): TDoubleArray; overload', @_LapeUnique_DoubleArray); +addGlobalFunc('function _Unique(const a: TExtendedArray): TExtendedArray; overload', @_LapeUnique_ExtendedArray); +addGlobalFunc('function _Unique(const a: TStringArray): TStringArray; overload', @_LapeUnique_StringArray); +addGlobalFunc('function _IndicesOf(const Item: String; const a: TStringArray): TIntegerArray; overload', @_LapeIndicesOf_StringArray); addGlobalFunc('function _IndicesOf(const Item: TPoint; const a: TPointArray): TIntegerArray; overload', @_LapeIndicesOf_PointArray); addGlobalFunc('function _IndicesOf(const Item: Integer; const a: TIntegerArray): TIntegerArray; overload', @_LapeIndicesOf_IntegerArray); -addGlobalFunc('function _IndicesOf(const Item: String; const a: TStringArray): TIntegerArray; overload', @_LapeIndicesOf_StringArray); +addGlobalFunc('function _IndicesOf(const Item: Single; const a: TSingleArray): TIntegerArray; overload', @_LapeIndicesOf_SingleArray); addGlobalFunc('function _IndicesOf(const Item: Double; const a: TDoubleArray): TIntegerArray; overload', @_LapeIndicesOf_DoubleArray); +addGlobalFunc('function _IndicesOf(const Item: Extended; const a: TExtendedArray): TIntegerArray; overload', @_LapeIndicesOf_ExtendedArray); +addGlobalFunc('function _IndexOf(const Item: String; const a: TStringArray): Integer; overload', @_LapeIndexOf_StringArray); addGlobalFunc('function _IndexOf(const Item: TPoint; const a: TPointArray): Integer; overload', @_LapeIndexOf_PointArray); addGlobalFunc('function _IndexOf(const Item: Integer; const a: TIntegerArray): Integer; overload', @_LapeIndexOf_IntegerArray); -addGlobalFunc('function _IndexOf(const Item: String; const a: TStringArray): Integer; overload', @_LapeIndexOf_StringArray); +addGlobalFunc('function _IndexOf(const Item: Single; const a: TSingleArray): Integer; overload', @_LapeIndexOf_SingleArray); addGlobalFunc('function _IndexOf(const Item: Double; const a: TDoubleArray): Integer; overload', @_LapeIndexOf_DoubleArray); +addGlobalFunc('function _IndexOf(const Item: Extended; const a: TExtendedArray): Integer; overload', @_LapeIndexOf_ExtendedArray); + +addGlobalFunc('function _ArraySum(const a: TPointArray): TPoint; overload', @_LapeArraySum_PointArray); +addGlobalFunc('function _ArraySum(const a: TIntegerArray): Int64; overload', @_LapeArraySum_IntegerArray); +addGlobalFunc('function _ArraySum(const a: TSingleArray): Extended; overload', @_LapeArraySum_SingleArray); +addGlobalFunc('function _ArraySum(const a: TDoubleArray): Extended; overload', @_LapeArraySum_DoubleArray); +addGlobalFunc('function _ArraySum(const a: TExtendedArray): Extended; overload', @_LapeArraySum_ExtendedArray); + +addGlobalFunc('function _ArrayMin(const a: TIntegerArray): Int64; overload', @_LapeArrayMin_IntegerArray); +addGlobalFunc('function _ArrayMin(const a: TSingleArray): Single; overload', @_LapeArrayMin_SingleArray); +addGlobalFunc('function _ArrayMin(const a: TDoubleArray): Double; overload', @_LapeArrayMin_DoubleArray); +addGlobalFunc('function _ArrayMin(const a: TExtendedArray): Extended; overload', @_LapeArrayMin_ExtendedArray); + +addGlobalFunc('function _ArrayMax(const a: TIntegerArray): Int64; overload', @_LapeArrayMax_IntegerArray); +addGlobalFunc('function _ArrayMax(const a: TSingleArray): Single; overload', @_LapeArrayMax_SingleArray); +addGlobalFunc('function _ArrayMax(const a: TDoubleArray): Double; overload', @_LapeArrayMax_DoubleArray); +addGlobalFunc('function _ArrayMax(const a: TExtendedArray): Extended; overload', @_LapeArrayMax_ExtendedArray); diff --git a/Source/script/wrappers_simba/simba.imports_math.inc b/Source/script/wrappers_simba/simba.imports_math.inc index 4301f0e54..48a3191fa 100644 --- a/Source/script/wrappers_simba/simba.imports_math.inc +++ b/Source/script/wrappers_simba/simba.imports_math.inc @@ -15,22 +15,17 @@ addGlobalFunc('function Log10(f: Extended): Extended', @_LapeLog10); addGlobalFunc('function FixRad(rad: Extended): Extended', @_LapeFixRad); addGlobalFunc('function NextPower2(const n: Integer): Integer', @_LapeNextPower2); -addGlobalFunc('function MinA(const Arr: TIntegerArray): Integer; overload', @_LapeMinA); -addGlobalFunc('function MaxA(const Arr: TIntegerArray): Integer; overload', @_LapeMaxA); - -addGlobalFunc('function MinA(const Arr: TExtendedArray): Extended; overload', @_LapeMinAF); -addGlobalFunc('function MaxA(const Arr: TExtendedArray): Extended; overload', @_LapeMaxAF); +addGlobalFunc('function MinA(const Arr: TIntegerArray): Integer', @_LapeMinA); +addGlobalFunc('function MaxA(const Arr: TIntegerArray): Integer', @_LapeMaxA); addGlobalFunc('function Modulo(const X, Y: Integer): Integer; overload', @_LapeModulo); addGlobalFunc('function Modulo(const X, Y: Extended): Extended; overload', @_LapeModuloF); -addGlobalFunc('function Mode(const Arr: TIntegerArray): Integer', @_LapeMode); - addGlobalFunc('function Sum(const Arr: TIntegerArray): Int64; overload', @_LapeSum); addGlobalFunc('function Sum(const Arr: TExtendedArray): Extended; overload', @_LapeSumF); -addGlobalFunc('function Average(const Arr: TIntegerArray): Int64; overload', @_LapeAverage); -addGlobalFunc('function Average(const Arr: TExtendedArray): Extended; overload', @_LapeAverageF); +addGlobalFunc('function Mean(const Arr: TIntegerArray): Int64; overload', @_LapeMean); +addGlobalFunc('function Mean(const Arr: TExtendedArray): Extended; overload', @_LapeMeanF); popSection(); diff --git a/Source/script/wrappers_simba/simba.imports_ocr.inc b/Source/script/wrappers_simba/simba.imports_ocr.inc index f202af804..9447c9e2d 100644 --- a/Source/script/wrappers_simba/simba.imports_ocr.inc +++ b/Source/script/wrappers_simba/simba.imports_ocr.inc @@ -1,6 +1,7 @@ pushSection('OCR'); addGlobalFunc('function TPAFromText(Text, Font: String; var W, H: Int32): TPointArray', @_LapeTPAFromText); +addGlobalFunc('function BitmapFromText(Text, Font: String): TMufasaBitmap', @_LapeBitmapFromText); addGlobalFunc('function GetTextATPA(const ATPA: T2DPointArray; const maxvspacing: integer; const font: string): String', @_LapeGetTextATPA); addGlobalFunc('function GetTextAt(const atX, atY, minvspacing, maxvspacing, hspacing, color, tol, len: integer; const font: string): String', @_LapeGetTextAt); addGlobalFunc('function GetTextAtEx(const xs,ys,xe,ye, minvspacing, maxvspacing, hspacing, color, tol: integer; const font: string): String', @_LapeGetTextAtEx); diff --git a/Source/script/wrappers_simba/simba.wrappers_internal.inc b/Source/script/wrappers_simba/simba.wrappers_internal.inc index f56d21867..fec07b40b 100644 --- a/Source/script/wrappers_simba/simba.wrappers_internal.inc +++ b/Source/script/wrappers_simba/simba.wrappers_internal.inc @@ -14,6 +14,21 @@ begin Sort(PIntegerArray(Params^[0])^); end; +procedure _LapeSort_SingleArray(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + Sort(PSingleArray(Params^[0])^); +end; + +procedure _LapeSort_DoubleArray(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + Sort(PDoubleArray(Params^[0])^); +end; + +procedure _LapeSort_ExtendedArray(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + Sort(PExtendedArray(Params^[0])^); +end; + // Unique procedure _LapeUnique_PointArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin @@ -25,11 +40,21 @@ begin PIntegerArray(Result)^ := Unique(PIntegerArray(Params^[0])^); end; +procedure _LapeUnique_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PSingleArray(Result)^ := Unique(PSingleArray(Params^[0])^); +end; + procedure _LapeUnique_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin PDoubleArray(Result)^ := Unique(PDoubleArray(Params^[0])^); end; +procedure _LapeUnique_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtendedArray(Result)^ := Unique(PExtendedArray(Params^[0])^); +end; + procedure _LapeUnique_StringArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin PStringArray(Result)^ := Unique(PStringArray(Params^[0])^); @@ -51,11 +76,21 @@ begin PIntegerArray(Result)^ := IndicesOf(PString(Params^[0])^, PStringArray(Params^[1])^); end; +procedure _LapeIndicesOf_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PIntegerArray(Result)^ := IndicesOf(PSingle(Params^[0])^, PSingleArray(Params^[1])^); +end; + procedure _LapeIndicesOf_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin PIntegerArray(Result)^ := IndicesOf(PDouble(Params^[0])^, PDoubleArray(Params^[1])^); end; +procedure _LapeIndicesOf_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PIntegerArray(Result)^ := IndicesOf(PExtended(Params^[0])^, PExtendedArray(Params^[1])^); +end; + // IndexOf procedure _LapeIndexOf_PointArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin @@ -72,7 +107,88 @@ begin PInteger(Result)^ := IndexOf(PString(Params^[0])^, PStringArray(Params^[1])^); end; +procedure _LapeIndexOf_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PInteger(Result)^ := IndexOf(PSingle(Params^[0])^, PSingleArray(Params^[1])^); +end; + procedure _LapeIndexOf_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin PInteger(Result)^ := IndexOf(PDouble(Params^[0])^, PDoubleArray(Params^[1])^); end; + +procedure _LapeIndexOf_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PInteger(Result)^ := IndexOf(PExtended(Params^[0])^, PExtendedArray(Params^[1])^); +end; + +// Sum +procedure _LapeArraySum_PointArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PPoint(Result)^ := Sum(PPointArray(Params^[0])^); +end; + +procedure _LapeArraySum_IntegerArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PInt64(Result)^ := Sum(PIntegerArray(Params^[0])^); +end; + +procedure _LapeArraySum_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtended(Result)^ := Sum(PSingleArray(Params^[0])^); +end; + +procedure _LapeArraySum_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtended(Result)^ := Sum(PDoubleArray(Params^[0])^); +end; + +procedure _LapeArraySum_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtended(Result)^ := Sum(PExtendedArray(Params^[0])^); +end; + +// Min +procedure _LapeArrayMin_IntegerArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PInteger(Result)^ := Min(PIntegerArray(Params^[0])^); +end; + +procedure _LapeArrayMin_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PSingle(Result)^ := Min(PSingleArray(Params^[0])^); +end; + +procedure _LapeArrayMin_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PDouble(Result)^ := Min(PDoubleArray(Params^[0])^); +end; + +procedure _LapeArrayMin_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtended(Result)^ := Min(PExtendedArray(Params^[0])^); +end; + +// Max +procedure _LapeArrayMax_IntegerArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PInteger(Result)^ := Max(PIntegerArray(Params^[0])^); +end; + +procedure _LapeArrayMax_SingleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PSingle(Result)^ := Max(PSingleArray(Params^[0])^); +end; + +procedure _LapeArrayMax_DoubleArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PDouble(Result)^ := Max(PDoubleArray(Params^[0])^); +end; + +procedure _LapeArrayMax_ExtendedArray(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + PExtended(Result)^ := Max(PExtendedArray(Params^[0])^); +end; + + + diff --git a/Source/script/wrappers_simba/simba.wrappers_math.inc b/Source/script/wrappers_simba/simba.wrappers_math.inc index 7a6fc42d2..8294b23d0 100644 --- a/Source/script/wrappers_simba/simba.wrappers_math.inc +++ b/Source/script/wrappers_simba/simba.wrappers_math.inc @@ -1,6 +1,6 @@ procedure _LapeGaussMatrix(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - P2DExtendedArray(Result)^ := GaussMatrix(PInteger(Params^[0])^, PExtended(Params^[1])^); + PExtendedMatrix(Result)^ := GaussMatrix(PInteger(Params^[0])^, PExtended(Params^[1])^); end; procedure _LapeDistance(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} @@ -30,17 +30,17 @@ end; procedure _LapeSar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - Plongint(Result)^ := SarLongint(Plongint(Params^[0])^, Pbyte(Params^[1])^); + Plongint(Result)^ := SarLongint(Plongint(Params^[0])^, PByte(Params^[1])^); end; procedure _LapeRor(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PLongWord(Result)^ := RorDWord(Plongword(Params^[0])^, Pbyte(Params^[1])^); + PLongWord(Result)^ := RorDWord(Plongword(Params^[0])^, PByte(Params^[1])^); end; procedure _LapeRol(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PLongWord(Result)^ := RolDWord(Plongword(Params^[0])^, Pbyte(Params^[1])^); + PLongWord(Result)^ := RolDWord(Plongword(Params^[0])^, PByte(Params^[1])^); end; procedure _LapeRadians(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} @@ -60,22 +60,12 @@ end; procedure _LapeMaxA(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PInteger(Result)^ := MaxA(PIntegerArray(Params^[0])^); + PInteger(Result)^ := Max(PIntegerArray(Params^[0])^); end; procedure _LapeMinA(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PInteger(Result)^ := MinA(PIntegerArray(Params^[0])^); -end; - -procedure _LapeMaxAF(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} -begin - PExtended(Result)^ := MaxA(PExtendedArray(Params^[0])^); -end; - -procedure _LapeMinAF(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} -begin - PExtended(Result)^ := MinA(PExtendedArray(Params^[0])^); + PInteger(Result)^ := Min(PIntegerArray(Params^[0])^); end; procedure _LapeFixRad(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} @@ -98,11 +88,6 @@ begin PExtended(Result)^ := Modulo(PExtended(Params^[0])^, PExtended(Params^[1])^); end; -procedure _LapeMode(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} -begin - PInteger(Result)^ := Mode(PIntegerArray(Params^[0])^); -end; - procedure _LapeSum(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin PInt64(Result)^ := Sum(PIntegerArray(Params^[0])^); @@ -113,13 +98,13 @@ begin PExtended(Result)^ := Sum(PExtendedArray(Params^[0])^); end; -procedure _LapeAverage(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +procedure _LapeMean(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PInt64(Result)^ := Average(PIntegerArray(Params^[0])^); + PInt64(Result)^ := Mean(PIntegerArray(Params^[0])^); end; -procedure _LapeAverageF(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +procedure _LapeMeanF(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin - PExtended(Result)^ := Average(PExtendedArray(Params^[0])^); + PExtended(Result)^ := Mean(PExtendedArray(Params^[0])^); end; diff --git a/Source/script/wrappers_simba/simba.wrappers_ocr.inc b/Source/script/wrappers_simba/simba.wrappers_ocr.inc index 6ddc37293..868c6191a 100644 --- a/Source/script/wrappers_simba/simba.wrappers_ocr.inc +++ b/Source/script/wrappers_simba/simba.wrappers_ocr.inc @@ -4,6 +4,12 @@ begin PPointArray(Result)^ := MOCR.TextToFontTPA(PString(Params^[0])^, PString(Params^[1])^, PInt32(Params^[2])^, PInt32(Params^[3])^); end; +procedure _LapeBitmapFromText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} +begin + with SimbaScriptThread.Script.Client do + PMufasaBitmap(Result)^ := MOCR.TextToFontBitmap(PString(Params^[0])^, PString(Params^[1])^); +end; + procedure _LapeGetTextATPA(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF} begin with SimbaScriptThread.Script.Client do