diff --git a/lib/utilities/types/extendedarrays.simba b/lib/utilities/types/extendedarrays.simba index cb3fa61..2875696 100644 --- a/lib/utilities/types/extendedarrays.simba +++ b/lib/utilities/types/extendedarrays.simba @@ -18,7 +18,7 @@ TExtendedArray.addIndex procedure TExtendedArray.addIndex(const ext : Extended; const index : Integer); -Used to add a value to a TExtendedArray at a chosen index larger than the array's lowest index. +Used to add a value to a TExtendedArray at a chosen index. .. note:: @@ -32,19 +32,8 @@ Example: *) procedure TExtendedArray.addIndex(const ext : Extended; const index : Integer); -var - I : Integer; begin - if not inRange(index, low(self), length(self)) then - begin - WriteLn('ERROR: addIndex: index larger than array length.'); - Exit; - end; - - setLength(self, length(self)+1); - for I := high(self)-1 downto index do - self[I+1] := self[I]; - self[index] := ext; + insert(ext, self, index); end; (* @@ -55,7 +44,7 @@ TExtendedArray.deleteIndex procedure TExtendedArray.deleteIndex(const index : Integer); -Used to delete a value of a TExtendedArray at a chosen index larger than the array's lowest index. +Used to delete a value of a TExtendedArray at a chosen index. .. note:: @@ -69,18 +58,14 @@ Example: *) procedure TExtendedArray.deleteIndex(const index : Integer); -var - I : Integer; begin if not inRange(index, low(self), high(self)) then begin - WriteLn('ERROR: deleteIndex: index larger than array length.'); + WriteLn('ERROR: deleteIndex: index out of bounds.'); Exit; end; - for I := index to high(self)-1 do - self[I] := self[I+1]; - setLength(self, length(self)-1); + delete(self, index, 1); end; (* @@ -106,7 +91,7 @@ Example: *) procedure TExtendedArray.append(const ext : Extended); begin - self.addIndex(ext, length(self)); + insert(ext, self, length(self)); end; (* @@ -134,8 +119,8 @@ procedure TExtendedArray.combine(const arr : TExtendedArray); var I : Integer; begin - for I := 0 to high(arr) do - self.append(arr[I]); + for I := high(arr) downto 0 do + insert(arr[I], self); end; (* @@ -166,10 +151,7 @@ begin result := -1; for I := 0 to high(self) do if self[I] = ext then - begin - result := I; - exit; - end; + exit(I); end; (* @@ -223,9 +205,9 @@ function TExtendedArray.include(const arr : TExtendedArray) : TExtendedArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -253,9 +235,9 @@ function TExtendedArray.exclude(const arr : TExtendedArray) : TExtendedArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if not self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -314,9 +296,9 @@ var I : Integer; arr : TExtendedArray; begin - for I := 0 to high(self) do + for I := high(self) downto 0 do if not arr.isInArray(self[I]) then - arr.append(self[I]); + insert(self[I], arr); self := arr; end; @@ -347,7 +329,7 @@ var arr : TExtendedArray; begin for I := high(self) downto 0 do - arr.append(self[I]); + insert(self[I], arr); self := arr; end; diff --git a/lib/utilities/types/integerarrays.simba b/lib/utilities/types/integerarrays.simba index d2ba75a..4d7cfb4 100644 --- a/lib/utilities/types/integerarrays.simba +++ b/lib/utilities/types/integerarrays.simba @@ -18,7 +18,7 @@ TIntegerArray.addIndex procedure TIntegerArray.addIndex(const int : Integer; const index : Integer); -Used to add a value to a TIntegerArray at a chosen index larger than the array's lowest index. +Used to add a value to a TIntegerArray at a chosen index. .. note:: @@ -32,19 +32,8 @@ Example: *) procedure TIntegerArray.addIndex(const int : Integer; const index : Integer); -var - I : Integer; begin - if not inRange(index, low(self), length(self)) then - begin - WriteLn('ERROR: addIndex: index larger than array length.'); - Exit; - end; - - setLength(self, length(self)+1); - for I := high(self)-1 downto index do - self[I+1] := self[I]; - self[index] := int; + insert(int, self, index); end; (* @@ -55,7 +44,7 @@ TIntegerArray.deleteIndex procedure TIntegerArray.deleteIndex(const index : Integer); -Used to delete a value of a TIntegerArray at a chosen index larger than the array's lowest index. +Used to delete a value of a TIntegerArray at a chosen index. .. note:: @@ -74,13 +63,11 @@ var begin if not inRange(index, low(self), high(self)) then begin - WriteLn('ERROR: deleteIndex: index larger than array length.'); + WriteLn('ERROR: deleteIndex: index out of bounds.'); Exit; end; - for I := index to high(self)-1 do - self[I] := self[I+1]; - setLength(self, length(self)-1); + delete(self, index, 1); end; (* @@ -106,7 +93,7 @@ Example: *) procedure TIntegerArray.append(const int : Integer); begin - self.addIndex(int, length(self)); + insert(int, self, length(self)); end; (* @@ -131,8 +118,6 @@ Example: *) procedure TIntegerArray.combine(const arr : TIntegerArray); -var - I : Integer; begin combineIntArrayWrap(self, arr, self); end; @@ -214,9 +199,9 @@ function TIntegerArray.include(const arr : TIntegerArray) : TIntegerArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -244,9 +229,9 @@ function TIntegerArray.exclude(const arr : TIntegerArray) : TIntegerArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if not self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -271,12 +256,8 @@ Example: *) procedure TIntegerArray.swap(var arr : TIntegerArray); -var - arr2 : TIntegerArray; begin - arr2 := self; - self := arr; - arr := arr2; + System.swap(self, arr); end; (* @@ -305,9 +286,9 @@ var I : Integer; arr : TIntegerArray; begin - for I := 0 to high(self) do + for I := high(self) downto 0 do if not arr.isInArray(self[I]) then - arr.append(self[I]); + insert(self[I], arr); self := arr; end; @@ -469,7 +450,7 @@ var begin setLength(result, length(self)); for I := 0 to high(self) do - result[I] := self[I] * 1.0; + result[I] := self[I]; end; (* diff --git a/lib/utilities/types/stringarrays.simba b/lib/utilities/types/stringarrays.simba index 8768c56..bb30c2f 100644 --- a/lib/utilities/types/stringarrays.simba +++ b/lib/utilities/types/stringarrays.simba @@ -18,7 +18,7 @@ TStringArray.addIndex procedure TStringArray.addIndex(const str : String; const index : Integer); -Used to add a value to a TStringArray at a chosen index larger than the array's lowest index. +Used to add a value to a TStringArray at a chosen index. .. note:: @@ -32,19 +32,8 @@ Example: *) procedure TStringArray.addIndex(const str : String; const index : Integer); -var - I : Integer; begin - if not inRange(index, low(self), length(self)) then - begin - WriteLn('ERROR: addIndex: index larger than array length.'); - Exit; - end; - - setLength(self, length(self)+1); - for I := high(self)-1 downto index do - self[I+1] := self[I]; - self[index] := str; + insert(str, self, index); end; (* @@ -55,7 +44,7 @@ TStringArray.deleteIndex procedure TStringArray.deleteIndex(const index : Integer); -Used to delete a value of a TStringArray at a chosen index larger than the array's lowest index. +Used to delete a value of a TStringArray at a chosen index. .. note:: @@ -74,13 +63,11 @@ var begin if not inRange(index, low(self), high(self)) then begin - WriteLn('ERROR: deleteIndex: index larger than array length.'); + WriteLn('ERROR: deleteIndex: index out of bounds.'); Exit; end; - for I := index to high(self)-1 do - self[I] := self[I+1]; - setLength(self, length(self)-1); + delete(self, index, 1); end; (* @@ -106,7 +93,7 @@ Example: *) procedure TStringArray.append(const str : String); begin - self.addIndex(str, length(self)); + insert(str, self, length(self)); end; (* @@ -135,7 +122,7 @@ var I : Integer; begin for I := 0 to high(arr) do - self.append(arr[I]); + insert(arr[I], self, length(self)); end; (* @@ -223,9 +210,9 @@ function TStringArray.include(const arr : TStringArray) : TStringArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -253,9 +240,9 @@ function TStringArray.exclude(const arr : TStringArray) : TStringArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if not self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -314,9 +301,9 @@ var I : Integer; arr : TStringArray; begin - for I := 0 to high(self) do + for I := high(self) downto 0 do if not arr.isInArray(self[I]) then - arr.append(self[I]); + insert(self[I], arr); self := arr; end; @@ -346,8 +333,8 @@ var I : Integer; arr : TStringArray; begin - for I := high(self) downto 0 do - arr.append(self[I]); + for I := 0 to high(self) do + insert(self[I], arr); self := arr; end; diff --git a/lib/utilities/types/tboxarrays.simba b/lib/utilities/types/tboxarrays.simba index 8f198ef..9e2a4f6 100644 --- a/lib/utilities/types/tboxarrays.simba +++ b/lib/utilities/types/tboxarrays.simba @@ -12,18 +12,17 @@ The source for this file can be found `here -1) then - result := true - else - result := false; + result := self.returnInArray(b) > -1; end; (* TBoxArray.include -~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -216,7 +195,6 @@ Returns a TBoxArray which contains values that are present in both arrays. .. note:: - by Zyt3x - - Last Updated: 10 October 2014 by bonsai Example: @@ -229,14 +207,14 @@ function TBoxArray.include(const arr : TBoxArray) : TBoxArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* TBoxArray.exclude -~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -247,7 +225,6 @@ Returns a TBoxArray which contains values that are not present in both arrays. .. note:: - by Zyt3x - - Last Updated: 10 October 2014 by bonsai Example: @@ -260,18 +237,14 @@ function TBoxArray.exclude(const arr : TBoxArray) : TBoxArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if not self.isInArray(arr[I]) then - result.append(arr[I]); - - for I := 0 to high(self) do - if not arr.isInArray(self[I]) then - result.append(self[I]); + insert(arr[I], result); end; (* TBoxArray.swap -~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ .. code-block:: pascal @@ -302,7 +275,7 @@ end; (* TBoxArray.clearEquals -~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -327,15 +300,15 @@ var I : Integer; arr : TBoxArray; begin - for I := 0 to high(self) do + for I := high(self) downto 0 do if not arr.isInArray(self[I]) then - arr.append(self[I]); + insert(self[I], arr); self := arr; end; (* TBoxArray.invert -~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -357,21 +330,17 @@ Example: *) procedure TBoxArray.invert(); var - i, len: integer; - tmp: TBox; + I : integer; + tmp : TBoxArray; begin - len := length(self); - for i := 0 to floor(len/2) do - begin - tmp := self[i]; - self[i] := self[len - 1 - i]; - self[len - 1 - i] := tmp; - end; + for I := high(self) downto 0 do + insert(self[I], tmp); + self := tmp; end; (* TBoxArray.toATPA -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -402,7 +371,7 @@ end; (* TBoxArray.toTPA -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -434,7 +403,7 @@ end; (* TBoxArray.copy -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ .. code-block:: pascal @@ -455,12 +424,8 @@ Example: *) function TBoxArray.copy() : TBoxArray; -var - i : integer; begin - setLength(result, length(self)); - for i := 0 to high(self) do - result[i] := self[i]; + result := System.copy(self); end; (* @@ -512,7 +477,7 @@ end; (* TBoxArray.equals -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -547,7 +512,7 @@ end; (* TBoxArray.offset -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -577,7 +542,7 @@ end; (* TBoxArray.getMiddle -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -606,7 +571,7 @@ end; (* TBoxArray.setLimit -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -636,7 +601,7 @@ end; (* TBoxArray.expand -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -666,7 +631,7 @@ end; (* TBoxArray.shrink -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -696,7 +661,7 @@ end; (* TBoxArray.pixelShiftAverage -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -723,7 +688,7 @@ end; (* TBoxArray.pixelShift -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -750,7 +715,7 @@ end; (* TBoxArray.getColors -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -784,7 +749,7 @@ end; (* TBoxArray.colorExists -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal diff --git a/lib/utilities/types/tpointarrays.simba b/lib/utilities/types/tpointarrays.simba index b033aeb..278026b 100644 --- a/lib/utilities/types/tpointarrays.simba +++ b/lib/utilities/types/tpointarrays.simba @@ -74,7 +74,7 @@ TPointArray.addIndex procedure TPointArray.addIndex(const p : TPoint; const index : Integer); -Used to add a point to a TPointArray at a chosen index larger than the array's lowest index. +Used to add a point to a TPointArray at a chosen index. .. note:: @@ -88,19 +88,8 @@ Example: *) procedure TPointArray.addIndex(const p : TPoint; const index : Integer); -var - I : Integer; begin - if not inRange(index, low(self), length(self)) then - begin - WriteLn('ERROR: addIndex: index larger than array length.'); - Exit; - end; - - setLength(self, length(self)+1); - for I := high(self)-1 downto index do - self[I+1] := self[I]; - self[index] := p; + insert(p, self, index); end; (* @@ -111,7 +100,7 @@ TPointArray.deleteIndex procedure TPointArray.deleteIndex(const index : Integer); -Used to delete a point of a TPointArray at a chosen index larger than the array's lowest index. +Used to delete a point of a TPointArray at a chosen index. .. note:: @@ -125,18 +114,14 @@ Example: *) procedure TPointArray.deleteIndex(const index : Integer); -var - I : Integer; begin if not inRange(index, low(self), length(self)) then begin - WriteLn('ERROR: deleteIndex: index larger than array length.'); + WriteLn('ERROR: deleteIndex: index out of bounds.'); Exit; end; - for I := index to high(self)-1 do - self[I] := self[I+1]; - setLength(self, length(self)-1); + delete(self, index, 1); end; (* @@ -162,7 +147,7 @@ Example: *) procedure TPointArray.append(const p : TPoint); begin - self.addIndex(p, length(self)); + insert(p, self, length(self)); end; (* @@ -192,12 +177,12 @@ begin end; (* -TPointArray.returnInArray -~~~~~~~~~~~~~~~~~~~~~~~~~ +TPointArray.returnPosInArray +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal - function TPointArray.returnInArray(const p : TPoint) : Integer; + function TPointArray.returnPosInArray(const p : TPoint) : Integer; Returns the index of where the point was found in a TPointArray. Returns -1 if not found. @@ -209,7 +194,7 @@ Example: .. code-block:: pascal - writeLn(TPA.returnInArray(point(13, 37))); + writeLn(TPA.returnPosInArray(point(13, 37))); *) function TPointArray.returnPosInArray(const p : TPoint) : Integer; @@ -243,7 +228,7 @@ Example: .. code-block:: pascal - writeLn(TPA.returnInArray(point(13, 37))); + writeLn(TPA.isInArray(point(13, 37))); *) function TPointArray.isInArray(const p : TPoint) : Boolean; @@ -276,9 +261,9 @@ function TPointArray.include(const arr : TPointArray) : TPointArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -306,9 +291,9 @@ function TPointArray.exclude(const arr : TPointArray) : TPointArray; var I : Integer; begin - for I := 0 to high(arr) do + for I := high(arr) downto 0 do if not self.isInArray(arr[I]) then - result.append(arr[I]); + insert(arr[I], result); end; (* @@ -918,12 +903,12 @@ end; (* -TPointArray.findText -~~~~~~~~~~~~~~~~~~~~ +TPointArray.findTextIn +~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal - function TPointArray.findText(const height : Integer; const searchTPA : TPointArray; var matches : TPointArray): Boolean; + function TPointArray.findTextIn(const height : Integer; const searchTPA : TPointArray; var matches : TPointArray): Boolean; Returns True if the text TPA is found within TPointArray. Also returns the matching points in the variable matches. @@ -935,7 +920,7 @@ Example: .. code-block:: pascal - TPA.findText(13.0, 13, sTPA, mTPA); + TPA.findTextIn(13.0, sTPA, mTPA); *) function TPointArray.findTextIn(const height : Integer; const searchTPA : TPointArray; var matches : TPointArray): Boolean; @@ -970,8 +955,8 @@ begin end; (* -TPointArray.split overload -~~~~~~~~~~~~~~~~~~~~~~~~~~ +TPointArray.split; overload +~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -1527,7 +1512,7 @@ end; (* T2DPointArray.deleteIndex -~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: pascal @@ -1551,15 +1536,13 @@ procedure T2DPointArray.deleteIndex(const index: Integer); var i : Integer; begin - if not inRange(index, low(self), length(self)) then + if not inRange(index, low(self), high(self)) then begin - print('T2DPointArray.deleteIndex(): index is larger than the array length', TDebug.ERROR); - Exit; + print('T2DPointArray.deleteIndex(): index is out of bounds', TDebug.ERROR); + exit(); end; - for i := index to high(self)-1 do - self[i] := self[i+1]; - setLength(self, length(self)-1); + delete(self, index, 1); end; (*