TAChart: Extract WeightedAverage utility function

git-svn-id: trunk@29748 -
This commit is contained in:
ask 2011-03-08 09:17:56 +00:00
parent bb74af971c
commit d378e66c95
2 changed files with 10 additions and 5 deletions

View File

@ -283,6 +283,8 @@ procedure Unused(const A1, A2);
procedure UpdateMinMax(AValue: Double; var AMin, AMax: Double); overload;
procedure UpdateMinMax(AValue: Integer; var AMin, AMax: Integer); overload;
function WeightedAverage(AX1, AX2, ACoeff: Double): Double; inline;
operator +(const A: TPoint; B: TSize): TPoint; overload; inline;
operator +(const A, B: TPoint): TPoint; overload; inline;
operator +(const A, B: TDoublePoint): TDoublePoint; overload; inline;
@ -859,6 +861,11 @@ begin
AMax := AValue;
end;
function WeightedAverage(AX1, AX2, ACoeff: Double): Double;
begin
Result := AX1 * (1 - ACoeff) + AX2 * ACoeff;
end;
operator + (const A: TPoint; B: TSize): TPoint;
begin
Result.X := A.X + B.cx;

View File

@ -761,7 +761,7 @@ procedure TBasicZoomTool.OnTimer(ASender: TObject);
var
ext: TDoubleRect;
t: Double;
r, r1: TDoublePoint;
i: Integer;
begin
Unused(ASender);
FCurrentStep += 1;
@ -770,10 +770,8 @@ begin
FChart.ZoomFull
else begin
t := FCurrentStep / AnimationSteps;
r := DoublePoint(t, t);
r1 := DoublePoint(1 - t, 1 - t);
ext.a := FExtSrc.a * r1 + FExtDst.a * r;
ext.b := FExtSrc.b * r1 + FExtDst.b * r;
for i := Low(ext.coords) to High(ext.coords) do
ext.coords[i] := WeightedAverage(FExtSrc.coords[i], FExtDst.coords[i], t);
NormalizeRect(ext);
FChart.LogicalExtent := ext;
end;