Some more performance tweaking

This commit is contained in:
ronaldhordijk 2005-01-29 11:10:33 +00:00
parent 10b8ac3c6b
commit 1700c89380

View File

@ -9,6 +9,17 @@ const
type type
TCalcMethod = procedure of object; TCalcMethod = procedure of object;
type
TCPpoint = record
x, y, c: double;
end;
PCPpoint = ^TCPpoint;
TXYpoint = record
x, y: double;
end;
PXYpoint = ^TXYpoint;
type type
TXForm = class TXForm = class
private private
@ -18,9 +29,12 @@ type
FTx, FTy: double; FTx, FTy: double;
FPx, FPy: double; FPx, FPy: double;
FAngle: double; FAngle: double;
FSinA: double;
FCosA: double;
FLength: double; FLength: double;
CalculateAngle: boolean; CalculateAngle: boolean;
CalculateLength: boolean; CalculateLength: boolean;
CalculateSinCos: boolean;
procedure Linear; // var[0] procedure Linear; // var[0]
procedure Sinusoidal; // var[1] procedure Sinusoidal; // var[1]
@ -51,6 +65,7 @@ type
c: array[0..2, 0..1] of double; // the coefs to the affine part of the function c: array[0..2, 0..1] of double; // the coefs to the affine part of the function
density: double; // prob is this function is chosen. 0 - 1 density: double; // prob is this function is chosen. 0 - 1
color: double; // color coord for this function. 0 - 1 color: double; // color coord for this function. 0 - 1
color2: double; // Second color coord for this function. 0 - 1
symmetry: double; symmetry: double;
c00, c01, c10, c11, c20, c21: double; c00, c01, c10, c11, c20, c21: double;
@ -62,7 +77,11 @@ type
procedure Prepare; procedure Prepare;
procedure NextPoint(var px, py, pc: double); overload; procedure NextPoint(var px, py, pc: double); overload;
procedure NextPoint(var CPpoint: TCPpoint); overload;
procedure NextPoint(var px, py, pz, pc: double); overload; procedure NextPoint(var px, py, pz, pc: double); overload;
procedure NextPointXY(var px, py: double);
procedure NextPoint2C(var px, py, pc1, pc2: double);
end; end;
implementation implementation
@ -216,43 +235,14 @@ begin
end; end;
CalculateAngle := (vars[5] <> 0.0) or (vars[6] <> 0.0) or (vars[7] <> 0.0) or (vars[8] <> 0.0) or CalculateAngle := (vars[5] <> 0.0) or (vars[6] <> 0.0) or (vars[7] <> 0.0) or (vars[8] <> 0.0) or
(vars[9] <> 0.0) or (vars[10] <> 0.0) or (vars[11] <> 0.0) or (vars[12] <> 0.0) or (vars[12] <> 0.0) or (vars[13] <> 0.0);
(vars[13] <> 0.0) or (vars[19] <> 0.0) or (vars[21] <> 0.0);
CalculateLength := False; CalculateLength := False;
CalculateSinCos := (vars[4] <> 0.0) or (vars[9] <> 0.0) or (vars[10] <> 0.0) or
(vars[11] <> 0.0) or (vars[16] <> 0.0) or (vars[19] <> 0.0) or
(vars[21] <> 0.0);
end; end;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPoint(var px,py,pc: double);
var
i: Integer;
begin
// first compute the color coord
pc := (pc + color) * 0.5 * (1 - symmetry) + symmetry * pc;
FTx := c00 * px + c10 * py + c20;
FTy := c01 * px + c11 * py + c21;
if CalculateAngle then begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
FAngle := arctan2(FTx, FTy)
else
FAngle := 0.0;
end;
// if CalculateLength then begin
// FLength := sqrt(FTx * FTx + FTy * FTy);
// end;
Fpx := 0;
Fpy := 0;
for i:= 0 to FNrFunctions-1 do
FFunctionList[i];
px := FPx;
py := FPy;
end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Linear; procedure TXForm.Linear;
begin begin
@ -291,17 +281,17 @@ end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Horseshoe; procedure TXForm.Horseshoe;
var //var
a, c1, c2: double; // a, c1, c2: double;
begin begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then // if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
a := arctan2(FTx, FTy) // a := arctan2(FTx, FTy)
else // else
a := 0.0; // a := 0.0;
c1 := sin(a); // c1 := sin(FAngle);
c2 := cos(a); // c2 := cos(FAngle);
FPx := FPx + vars[4] * (c1 * FTx - c2 * FTy); FPx := FPx + vars[4] * (FSinA * FTx - FCosA * FTy);
FPy := FPy + vars[4] * (c2 * FTx + c1 * FTy); FPy := FPy + vars[4] * (FCosA* FTx + FSinA * FTy);
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -354,9 +344,10 @@ procedure TXForm.Spiral;
var var
r: double; r: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy) + 1E-6; // r := sqrt(FTx * FTx + FTy * FTy) + 1E-6;
FPx := FPx + vars[9] * (cos(FAngle) + sin(r)) / r; r := Flength + 1E-6;
FPy := FPy + vars[9] * (sin(FAngle) - cos(r)) / r; FPx := FPx + vars[9] * (FCosA + sin(r)) / r;
FPy := FPy + vars[9] * (FsinA - cos(r)) / r;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -364,19 +355,20 @@ procedure TXForm.hyperbolic;
var var
r: double; r: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy) + 1E-6; // r := sqrt(FTx * FTx + FTy * FTy) + 1E-6;
FPx := FPx + vars[10] * sin(FAngle) / r; r := Flength + 1E-6;
FPy := FPy + vars[10] * cos(FAngle) * r; FPx := FPx + vars[10] * FSinA / r;
FPy := FPy + vars[10] * FCosA * r;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Square; procedure TXForm.Square;
var //var
r: double; // r: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); // r := sqrt(FTx * FTx + FTy * FTy);
FPx := FPx + vars[11] * sin(FAngle) * cos(r); FPx := FPx + vars[11] * FSinA * cos(Flength);
FPy := FPy + vars[11] * cos(FAngle) * sin(r); FPy := FPy + vars[11] * FCosA * sin(Flength);
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -436,13 +428,14 @@ end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Fisheye; procedure TXForm.Fisheye;
var var
a, r: double; { a,} r: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); // r := sqrt(FTx * FTx + FTy * FTy);
a := arctan2(FTx, FTy); // a := arctan2(FTx, FTy);
r := 2 * r / (r + 1); // r := 2 * r / (r + 1);
FPx := FPx + vars[16] * r * cos(a); r := 2 * Flength / (Flength + 1);
FPy := FPy + vars[16] * r * sin(a); FPx := FPx + vars[16] * r * FCosA;
FPy := FPy + vars[16] * r * FSinA;
end; end;
@ -478,16 +471,16 @@ end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Power; procedure TXForm.Power;
var var
r,sa: double; r: double;
nx, ny: double; // nx, ny: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); // r := sqrt(FTx * FTx + FTy * FTy);
sa := sin(FAngle); // sa := sin(FAngle);
r := Math.power(r, sa); r := Math.Power(FLength, FSinA);
nx := r * cos(FAngle); // nx := r * FCosA;
ny := r * sa; // ny := r * FSinA;
FPx := FPx + vars[19] * nx; FPx := FPx + vars[19] * r * FCosA;
FPy := FPy + vars[19] * ny; FPy := FPy + vars[19] * r * FSinA;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -495,8 +488,8 @@ procedure TXForm.Cosine;
var var
nx, ny: double; nx, ny: double;
begin begin
nx := cos(Ftx * PI) * cosh(Fty); nx := cos(FTx * PI) * cosh(FTy);
ny := -sin(Ftx * PI) * sinh(Fty); ny := -sin(FTx * PI) * sinh(FTy);
FPx := FPx + vars[20] * nx; FPx := FPx + vars[20] * nx;
FPy := FPy + vars[20] * ny; FPy := FPy + vars[20] * ny;
end; end;
@ -505,20 +498,107 @@ end;
procedure TXForm.SawTooth; procedure TXForm.SawTooth;
var var
r: double; r: double;
nx, ny: double; // nx, ny: double;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); // r := sqrt(FTx * FTx + FTy * FTy);
// r := fmod(r + 1.0, 2.0) - 1.0; // r := fmod(r + 1.0, 2.0) - 1.0;
r := r + 1; r := FLength + 1;
r := r - System.Int(r/2) * 2.0 - 1; r := r - System.Int(r/2) * 2.0 - 1;
nx := cos(FAngle) * r; // nx := cos(FAngle) * r;
ny := sin(FAngle) * r; // ny := sin(FAngle) * r;
FPx := FPx + vars[21] * nx; FPx := FPx + vars[21] * r * FCosA;
FPy := FPy + vars[21] * ny; FPy := FPy + vars[21] * r * FSinA;
end; end;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPoint(var px,py,pc: double);
var
i: Integer;
begin
// first compute the color coord
pc := (pc + color) * 0.5 * (1 - symmetry) + symmetry * pc;
FTx := c00 * px + c10 * py + c20;
FTy := c01 * px + c11 * py + c21;
if CalculateAngle then begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
FAngle := arctan2(FTx, FTy)
else
FAngle := 0.0;
end;
if CalculateSinCos then begin
Flength := sqrt(FTx * FTx + FTy * FTy);
if FLength = 0 then begin
FSinA := 0;
FCosA := 0;
end else begin
FSinA := FTx/FLength;
FCosA := FTy/FLength;
end;
end;
// if CalculateLength then begin
// FLength := sqrt(FTx * FTx + FTy * FTy);
// end;
Fpx := 0;
Fpy := 0;
for i := 0 to FNrFunctions - 1 do
FFunctionList[i];
px := FPx;
py := FPy;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPoint(var CPpoint: TCPpoint);
var
i: Integer;
begin
// first compute the color coord
CPpoint.c := (CPpoint.c + color) * 0.5 * (1 - symmetry) + symmetry * CPpoint.c;
FTx := c00 * CPpoint.x + c10 * CPpoint.y + c20;
FTy := c01 * CPpoint.x + c11 * CPpoint.y + c21;
if CalculateAngle then begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
FAngle := arctan2(FTx, FTy)
else
FAngle := 0.0;
end;
if CalculateSinCos then begin
Flength := sqrt(FTx * FTx + FTy * FTy);
if FLength = 0 then begin
FSinA := 0;
FCosA := 1;
end else begin
FSinA := FTx/FLength;
FCosA := FTy/FLength;
end;
end;
// if CalculateLength then begin
// FLength := sqrt(FTx * FTx + FTy * FTy);
// end;
Fpx := 0;
Fpy := 0;
for i:= 0 to FNrFunctions-1 do
FFunctionList[i];
CPpoint.x := FPx;
CPpoint.y := FPy;
end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPoint(var px, py, pz, pc: double); procedure TXForm.NextPoint(var px, py, pz, pc: double);
var var
@ -581,4 +661,71 @@ begin
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPoint2C(var px, py, pc1, pc2: double);
var
i: Integer;
begin
// first compute the color coord
pc1 := (pc1 + color) * 0.5 * (1 - symmetry) + symmetry * pc1;
pc2 := (pc2 + color) * 0.5 * (1 - symmetry) + symmetry * pc2;
FTx := c00 * px + c10 * py + c20;
FTy := c01 * px + c11 * py + c21;
if CalculateAngle then begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
FAngle := arctan2(FTx, FTy)
else
FAngle := 0.0;
end;
// if CalculateLength then begin
// FLength := sqrt(FTx * FTx + FTy * FTy);
// end;
Fpx := 0;
Fpy := 0;
for i:= 0 to FNrFunctions-1 do
FFunctionList[i];
px := FPx;
py := FPy;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TXForm.NextPointXY(var px, py: double);
var
i: integer;
begin
FTx := c00 * px + c10 * py + c20;
FTy := c01 * px + c11 * py + c21;
if CalculateAngle then begin
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
FAngle := arctan2(FTx, FTy)
else
FAngle := 0.0;
end;
if CalculateSinCos then begin
Flength := sqrt(FTx * FTx + FTy * FTy);
if FLength = 0 then begin
FSinA := 0;
FCosA := 0;
end else begin
FSinA := FTx/FLength;
FCosA := FTy/FLength;
end;
end;
Fpx := 0;
Fpy := 0;
for i:= 0 to FNrFunctions-1 do
FFunctionList[i];
px := FPx;
py := FPy;
end;
end. end.