You've already forked lazarus-ccr
LazStats: Further refactoring of ResistanceLineUnit. Some rearrangement of units to make MathUnit only dependent on Globals (for easier testing).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7756 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -21,15 +21,6 @@ function AnySelected(AListbox: TListBox): Boolean;
|
||||
procedure ErrorMsg(const AMsg: String);
|
||||
procedure ErrorMsg(const AMsg: String; const AParams: array of const);
|
||||
|
||||
procedure Exchange(var a, b: Double); overload;
|
||||
procedure Exchange(var a, b: Integer); overload;
|
||||
procedure Exchange(var a, b: String); overload;
|
||||
|
||||
procedure SortOnX(X: DblDyneVec; Y: DblDyneVec = nil; Z: DblDyneVec = nil);
|
||||
procedure SortOnX(X: DblDyneVec; Y: DblDyneMat);
|
||||
|
||||
procedure QuickSortOnX(X: DblDyneVec; Y: DblDyneVec = nil; Z: DblDyneVec = nil); // not 100% tested...
|
||||
|
||||
function CenterString(S: String; Width: Integer): String;
|
||||
function IndexOfString(L: StrDyneVec; s: String): Integer;
|
||||
|
||||
@ -107,125 +98,6 @@ begin
|
||||
ErrorMsg(Format(AMsg, AParams));
|
||||
end;
|
||||
|
||||
procedure Exchange(var a, b: Double);
|
||||
var
|
||||
tmp: Double;
|
||||
begin
|
||||
tmp := a;
|
||||
a := b;
|
||||
b := tmp;
|
||||
end;
|
||||
|
||||
procedure Exchange(var a, b: Integer);
|
||||
var
|
||||
tmp: Integer;
|
||||
begin
|
||||
tmp := a;
|
||||
a := b;
|
||||
b := tmp;
|
||||
end;
|
||||
|
||||
procedure Exchange(var a, b: String);
|
||||
var
|
||||
tmp: String;
|
||||
begin
|
||||
tmp := a;
|
||||
a := b;
|
||||
b := tmp;
|
||||
end;
|
||||
|
||||
procedure SortOnX(X: DblDyneVec; Y: DblDyneVec = nil; Z: DblDyneVec = nil);
|
||||
var
|
||||
i, j, N: Integer;
|
||||
begin
|
||||
N := Length(X);
|
||||
if (Y <> nil) and (N <> Length(Y)) then
|
||||
raise Exception.Create('[SortOnX] Arrays must have the same length.');
|
||||
if (Z <> nil) and (N <> Length(Z)) then
|
||||
raise Exception.Create('[SortOnX] Arrays must have the same length.');
|
||||
|
||||
for i := 0 to N - 2 do
|
||||
begin
|
||||
for j := i + 1 to N - 1 do
|
||||
begin
|
||||
if X[i] > X[j] then //swap
|
||||
begin
|
||||
Exchange(X[i], X[j]);
|
||||
if Y <> nil then
|
||||
Exchange(Y[i], Y[j]);
|
||||
if Z <> nil then
|
||||
Exchange(Z[i], Z[j]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// NOTE: The matrix Y is transposed relative to the typical usage in LazStats
|
||||
procedure SortOnX(X: DblDyneVec; Y: DblDyneMat);
|
||||
var
|
||||
i, j, k, N, Ny: Integer;
|
||||
begin
|
||||
N := Length(X);
|
||||
if N <> Length(Y[0]) then
|
||||
raise Exception.Create('[SortOnX] Arrays X and Y (2nd index) must have the same length');
|
||||
Ny := Length(Y);
|
||||
|
||||
for i := 0 to N-2 do
|
||||
begin
|
||||
for j := i+1 to N-1 do
|
||||
if X[i] > X[j] then
|
||||
begin
|
||||
Exchange(X[i], X[j]);
|
||||
for k := 0 to Ny-1 do
|
||||
Exchange(Y[k, i], Y[k, j]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure QuickSortOnX(X: DblDyneVec; Y: DblDyneVec = nil; Z: DblDyneVec = nil);
|
||||
|
||||
procedure DoQuickSort(L, R: Integer);
|
||||
var
|
||||
I,J: Integer;
|
||||
P: Integer;
|
||||
begin
|
||||
repeat
|
||||
I := L;
|
||||
J := R;
|
||||
P := (L+R) div 2;
|
||||
repeat
|
||||
while CompareValue(X[P], X[I]) > 0 do inc(I);
|
||||
while CompareValue(X[P], X[J]) < 0 do dec(J);
|
||||
if I <= J then begin
|
||||
if I <> J then begin
|
||||
Exchange(X[I], X[J]);
|
||||
if Y <> nil then
|
||||
Exchange(Y[I], Y[J]);
|
||||
if Z <> nil then
|
||||
Exchange(Z[I], Z[J]);
|
||||
end;
|
||||
|
||||
if P = I then
|
||||
P := J
|
||||
else if P = J then
|
||||
P := I;
|
||||
|
||||
inc(I);
|
||||
dec(J);
|
||||
end;
|
||||
until I > J;
|
||||
|
||||
if L < J then
|
||||
DoQuickSort(L, J);
|
||||
|
||||
L := I;
|
||||
until I >= R;
|
||||
end;
|
||||
|
||||
begin
|
||||
DoQuickSort(0, High(X));
|
||||
end;
|
||||
|
||||
|
||||
function CenterString(S: String; Width: Integer): String;
|
||||
var
|
||||
|
Reference in New Issue
Block a user