TAChart: Centralize Infinity handling in SafeInfinity function

git-svn-id: trunk@28774 -
This commit is contained in:
ask 2010-12-20 04:09:42 +00:00
parent 2cd2c885ed
commit 5e5be1fbb4
6 changed files with 19 additions and 41 deletions

View File

@ -260,6 +260,7 @@ function RotatePoint(const APoint: TDoublePoint; AAngle: Double): TDoublePoint;
function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint; overload;
function RoundChecked(A: Double): Integer; inline;
function SafeInfinity: Double; inline;
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
// Call this to silence 'parameter is unused' hint
@ -785,7 +786,14 @@ begin
Result := Round(EnsureRange(A, -MaxInt, MaxInt));
end;
{$HINTS OFF}
function SafeInfinity: Double;
begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
{$R-}{$Q-}
Result := Infinity;
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
end;
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
begin
@ -793,6 +801,7 @@ begin
Result := InRange(AValue, ABound1, ABound2);
end;
{$HINTS OFF}
procedure Unused(const A1);
begin
end;

View File

@ -135,9 +135,6 @@ implementation
uses
Math, SysUtils, TAGraph;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
{ TBasicFuncSeries }
procedure TBasicFuncSeries.AfterAdd;
@ -288,9 +285,7 @@ var
v1, v2: Double;
begin
if ColorSource = nil then exit(clTAColor);
{$R-}{$Q-}
ColorSource.FindBounds(AValue, Infinity, lb, ub);
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
ColorSource.FindBounds(AValue, SafeInfinity, lb, ub);
if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin
with ColorSource[lb - 1]^ do begin
v1 := X;
@ -327,8 +322,7 @@ end;
procedure TColorMapSeries.Draw(ACanvas: TCanvas);
var
ext: TDoubleRect;
bounds: TDoubleRect =
(coords: (Infinity, Infinity, NegInfinity, NegInfinity));
bounds: TDoubleRect;
r: TRect;
pt, next, offset: TPoint;
gp: TDoublePoint;
@ -337,6 +331,7 @@ begin
if IsEmpty then exit;
ext := ParentChart.CurrentExtent;
bounds := EmptyExtent;
GetBounds(bounds);
bounds.a := AxisToGraph(bounds.a);
bounds.b := AxisToGraph(bounds.b);

View File

@ -330,9 +330,6 @@ implementation
uses
Clipbrd, GraphMath, LCLProc, Math, Types, TADrawUtils;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
begin
Result :=
@ -1031,8 +1028,7 @@ function TChart.GetFullExtent: TDoubleRect;
begin
if AUseMin then ALo := AMin;
if AUseMax then AHi := AMax;
{$R-}{$Q-}
case CASE_OF_TWO[ALo = Infinity, AHi = NegInfinity] of
case CASE_OF_TWO[IsInfinite(ALo), IsInfinite(AHi)] of
cotNone: begin // Both high and low boundary defined
if ALo = AHi then begin
ALo -= DEFAULT_WIDTH / 2;
@ -1051,7 +1047,6 @@ function TChart.GetFullExtent: TDoubleRect;
AHi := DEFAULT_WIDTH / 2;
end;
end;
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
end;
var

View File

@ -314,9 +314,6 @@ implementation
uses
DateUtils, Math, StrUtils;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
type
{ TListChartSourceStrings }
@ -840,9 +837,7 @@ begin
FExtent.b.X := Max(FExtent.b.X, Item[i]^.X);
end;
if oldX = FExtent.a.X then begin
{$R-}{$Q-}
FExtent.a.X := Infinity;
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
FExtent.a.X := SafeInfinity;
for i := 0 to Count - 1 do
FExtent.a.X := Min(FExtent.a.X, Item[i]^.X);
end;
@ -901,9 +896,7 @@ begin
FExtent.b.Y := Max(FExtent.b.Y, Item[i]^.Y);
end;
if oldY = FExtent.a.Y then begin
{$R-}{$Q-}
FExtent.a.Y := Infinity;
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
FExtent.a.Y := SafeInfinity;
for i := 0 to Count - 1 do
FExtent.a.Y := Min(FExtent.a.Y, Item[i]^.Y);
end;

View File

@ -286,9 +286,6 @@ uses
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
TACustomSeries, TADrawUtils, TASubcomponentsEditor;
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
type
{ TToolsComponentEditor }
@ -807,8 +804,7 @@ var
df: TPointDistFunc;
begin
if FChart.ReticuleMode = rmNone then exit;
{$R-}{$Q-}
minDist := Infinity;
minDist := SafeInfinity;
df := DIST_FUNCS[FChart.ReticuleMode];
for i := 0 to FChart.SeriesCount - 1 do
if
@ -824,12 +820,11 @@ begin
minDist := d;
end;
end;
if (minDist < Infinity) and (best.retPos <> FChart.ReticulePos) then begin
if not IsInfinite(minDist) and (best.retPos <> FChart.ReticulePos) then begin
FChart.ReticulePos := best.retPos;
if Assigned(FChart.OnDrawReticule) then
FChart.OnDrawReticule(FChart, bestSeries, best.pointIndex, best.value);
end;
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
end;
{ TZoomClickTool }

View File

@ -171,9 +171,6 @@ resourcestring
implementation
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
uses
ComponentEditors, Forms, Math, PropEdits,
TASubcomponentsEditor;
@ -583,12 +580,10 @@ end;
function TLogarithmAxisTransform.AxisToGraph(AX: Double): Double;
begin
{$R-}{$Q-}
if AX > 0 then
Result := LogN(Base, AX)
else
Result := NegInfinity;
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
end;
constructor TLogarithmAxisTransform.Create(AOwner: TComponent);
@ -630,13 +625,11 @@ end;
procedure TAutoScaleAxisTransform.ClearBounds;
begin
inherited ClearBounds;
{$R-}{$Q-}
with TAutoScaleTransformData(FDrawData) do begin
FMin := Infinity;
FMin := SafeInfinity;
FMax := NegInfinity;
FScale := 1.0;
end;
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
end;
constructor TAutoScaleAxisTransform.Create(AOwner: TComponent);
@ -682,7 +675,6 @@ end;
procedure TAutoScaleAxisTransform.UpdateBounds(var AMin, AMax: Double);
begin
{$R-}{$Q-}
with TAutoScaleTransformData(FDrawData) do begin
UpdateMinMax(AMin, FMin, FMax);
UpdateMinMax(AMax, FMin, FMax);
@ -692,7 +684,6 @@ begin
FScale := (MaxValue - MinValue) / (FMax - FMin);
FOffset := MinValue - FMin * FScale;
end;
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
if not IsInfinite(AMin) then
AMin := MinValue;
if not IsInfinite(AMax) then