mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 01:19:16 +02:00
TAChart: Centralize Infinity handling in SafeInfinity function
git-svn-id: trunk@28774 -
This commit is contained in:
parent
2cd2c885ed
commit
5e5be1fbb4
@ -260,6 +260,7 @@ function RotatePoint(const APoint: TDoublePoint; AAngle: Double): TDoublePoint;
|
|||||||
function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint; overload;
|
function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint; overload;
|
||||||
function RoundChecked(A: Double): Integer; inline;
|
function RoundChecked(A: Double): Integer; inline;
|
||||||
|
|
||||||
|
function SafeInfinity: Double; inline;
|
||||||
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
|
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
|
||||||
|
|
||||||
// Call this to silence 'parameter is unused' hint
|
// Call this to silence 'parameter is unused' hint
|
||||||
@ -785,7 +786,14 @@ begin
|
|||||||
Result := Round(EnsureRange(A, -MaxInt, MaxInt));
|
Result := Round(EnsureRange(A, -MaxInt, MaxInt));
|
||||||
end;
|
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;
|
function SafeInRange(AValue, ABound1, ABound2: Double): Boolean;
|
||||||
begin
|
begin
|
||||||
@ -793,6 +801,7 @@ begin
|
|||||||
Result := InRange(AValue, ABound1, ABound2);
|
Result := InRange(AValue, ABound1, ABound2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$HINTS OFF}
|
||||||
procedure Unused(const A1);
|
procedure Unused(const A1);
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
@ -135,9 +135,6 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math, SysUtils, TAGraph;
|
Math, SysUtils, TAGraph;
|
||||||
|
|
||||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
|
|
||||||
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
|
|
||||||
|
|
||||||
{ TBasicFuncSeries }
|
{ TBasicFuncSeries }
|
||||||
|
|
||||||
procedure TBasicFuncSeries.AfterAdd;
|
procedure TBasicFuncSeries.AfterAdd;
|
||||||
@ -288,9 +285,7 @@ var
|
|||||||
v1, v2: Double;
|
v1, v2: Double;
|
||||||
begin
|
begin
|
||||||
if ColorSource = nil then exit(clTAColor);
|
if ColorSource = nil then exit(clTAColor);
|
||||||
{$R-}{$Q-}
|
ColorSource.FindBounds(AValue, SafeInfinity, lb, ub);
|
||||||
ColorSource.FindBounds(AValue, Infinity, lb, ub);
|
|
||||||
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
|
||||||
if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin
|
if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin
|
||||||
with ColorSource[lb - 1]^ do begin
|
with ColorSource[lb - 1]^ do begin
|
||||||
v1 := X;
|
v1 := X;
|
||||||
@ -327,8 +322,7 @@ end;
|
|||||||
procedure TColorMapSeries.Draw(ACanvas: TCanvas);
|
procedure TColorMapSeries.Draw(ACanvas: TCanvas);
|
||||||
var
|
var
|
||||||
ext: TDoubleRect;
|
ext: TDoubleRect;
|
||||||
bounds: TDoubleRect =
|
bounds: TDoubleRect;
|
||||||
(coords: (Infinity, Infinity, NegInfinity, NegInfinity));
|
|
||||||
r: TRect;
|
r: TRect;
|
||||||
pt, next, offset: TPoint;
|
pt, next, offset: TPoint;
|
||||||
gp: TDoublePoint;
|
gp: TDoublePoint;
|
||||||
@ -337,6 +331,7 @@ begin
|
|||||||
if IsEmpty then exit;
|
if IsEmpty then exit;
|
||||||
|
|
||||||
ext := ParentChart.CurrentExtent;
|
ext := ParentChart.CurrentExtent;
|
||||||
|
bounds := EmptyExtent;
|
||||||
GetBounds(bounds);
|
GetBounds(bounds);
|
||||||
bounds.a := AxisToGraph(bounds.a);
|
bounds.a := AxisToGraph(bounds.a);
|
||||||
bounds.b := AxisToGraph(bounds.b);
|
bounds.b := AxisToGraph(bounds.b);
|
||||||
|
@ -330,9 +330,6 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Clipbrd, GraphMath, LCLProc, Math, Types, TADrawUtils;
|
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;
|
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
|
||||||
begin
|
begin
|
||||||
Result :=
|
Result :=
|
||||||
@ -1031,8 +1028,7 @@ function TChart.GetFullExtent: TDoubleRect;
|
|||||||
begin
|
begin
|
||||||
if AUseMin then ALo := AMin;
|
if AUseMin then ALo := AMin;
|
||||||
if AUseMax then AHi := AMax;
|
if AUseMax then AHi := AMax;
|
||||||
{$R-}{$Q-}
|
case CASE_OF_TWO[IsInfinite(ALo), IsInfinite(AHi)] of
|
||||||
case CASE_OF_TWO[ALo = Infinity, AHi = NegInfinity] of
|
|
||||||
cotNone: begin // Both high and low boundary defined
|
cotNone: begin // Both high and low boundary defined
|
||||||
if ALo = AHi then begin
|
if ALo = AHi then begin
|
||||||
ALo -= DEFAULT_WIDTH / 2;
|
ALo -= DEFAULT_WIDTH / 2;
|
||||||
@ -1051,7 +1047,6 @@ function TChart.GetFullExtent: TDoubleRect;
|
|||||||
AHi := DEFAULT_WIDTH / 2;
|
AHi := DEFAULT_WIDTH / 2;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
|
@ -314,9 +314,6 @@ implementation
|
|||||||
uses
|
uses
|
||||||
DateUtils, Math, StrUtils;
|
DateUtils, Math, StrUtils;
|
||||||
|
|
||||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
|
|
||||||
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TListChartSourceStrings }
|
{ TListChartSourceStrings }
|
||||||
@ -840,9 +837,7 @@ begin
|
|||||||
FExtent.b.X := Max(FExtent.b.X, Item[i]^.X);
|
FExtent.b.X := Max(FExtent.b.X, Item[i]^.X);
|
||||||
end;
|
end;
|
||||||
if oldX = FExtent.a.X then begin
|
if oldX = FExtent.a.X then begin
|
||||||
{$R-}{$Q-}
|
FExtent.a.X := SafeInfinity;
|
||||||
FExtent.a.X := Infinity;
|
|
||||||
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
|
|
||||||
for i := 0 to Count - 1 do
|
for i := 0 to Count - 1 do
|
||||||
FExtent.a.X := Min(FExtent.a.X, Item[i]^.X);
|
FExtent.a.X := Min(FExtent.a.X, Item[i]^.X);
|
||||||
end;
|
end;
|
||||||
@ -901,9 +896,7 @@ begin
|
|||||||
FExtent.b.Y := Max(FExtent.b.Y, Item[i]^.Y);
|
FExtent.b.Y := Max(FExtent.b.Y, Item[i]^.Y);
|
||||||
end;
|
end;
|
||||||
if oldY = FExtent.a.Y then begin
|
if oldY = FExtent.a.Y then begin
|
||||||
{$R-}{$Q-}
|
FExtent.a.Y := SafeInfinity;
|
||||||
FExtent.a.Y := Infinity;
|
|
||||||
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
|
|
||||||
for i := 0 to Count - 1 do
|
for i := 0 to Count - 1 do
|
||||||
FExtent.a.Y := Min(FExtent.a.Y, Item[i]^.Y);
|
FExtent.a.Y := Min(FExtent.a.Y, Item[i]^.Y);
|
||||||
end;
|
end;
|
||||||
|
@ -286,9 +286,6 @@ uses
|
|||||||
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
|
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
|
||||||
TACustomSeries, TADrawUtils, TASubcomponentsEditor;
|
TACustomSeries, TADrawUtils, TASubcomponentsEditor;
|
||||||
|
|
||||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
|
|
||||||
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
|
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TToolsComponentEditor }
|
{ TToolsComponentEditor }
|
||||||
|
|
||||||
@ -807,8 +804,7 @@ var
|
|||||||
df: TPointDistFunc;
|
df: TPointDistFunc;
|
||||||
begin
|
begin
|
||||||
if FChart.ReticuleMode = rmNone then exit;
|
if FChart.ReticuleMode = rmNone then exit;
|
||||||
{$R-}{$Q-}
|
minDist := SafeInfinity;
|
||||||
minDist := Infinity;
|
|
||||||
df := DIST_FUNCS[FChart.ReticuleMode];
|
df := DIST_FUNCS[FChart.ReticuleMode];
|
||||||
for i := 0 to FChart.SeriesCount - 1 do
|
for i := 0 to FChart.SeriesCount - 1 do
|
||||||
if
|
if
|
||||||
@ -824,12 +820,11 @@ begin
|
|||||||
minDist := d;
|
minDist := d;
|
||||||
end;
|
end;
|
||||||
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;
|
FChart.ReticulePos := best.retPos;
|
||||||
if Assigned(FChart.OnDrawReticule) then
|
if Assigned(FChart.OnDrawReticule) then
|
||||||
FChart.OnDrawReticule(FChart, bestSeries, best.pointIndex, best.value);
|
FChart.OnDrawReticule(FChart, bestSeries, best.pointIndex, best.value);
|
||||||
end;
|
end;
|
||||||
{$ifdef OverflowChecking}{$Q+}{$endif}{$ifdef RangeChecking}{$R+}{$endif}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TZoomClickTool }
|
{ TZoomClickTool }
|
||||||
|
@ -171,9 +171,6 @@ resourcestring
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$IFOPT R+}{$DEFINE RangeChecking}{$ELSE}{$UNDEF RangeChecking}{$ENDIF}
|
|
||||||
{$IFOPT Q+}{$DEFINE OverflowChecking}{$ELSE}{$UNDEF OverflowChecking}{$ENDIF}
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
ComponentEditors, Forms, Math, PropEdits,
|
ComponentEditors, Forms, Math, PropEdits,
|
||||||
TASubcomponentsEditor;
|
TASubcomponentsEditor;
|
||||||
@ -583,12 +580,10 @@ end;
|
|||||||
|
|
||||||
function TLogarithmAxisTransform.AxisToGraph(AX: Double): Double;
|
function TLogarithmAxisTransform.AxisToGraph(AX: Double): Double;
|
||||||
begin
|
begin
|
||||||
{$R-}{$Q-}
|
|
||||||
if AX > 0 then
|
if AX > 0 then
|
||||||
Result := LogN(Base, AX)
|
Result := LogN(Base, AX)
|
||||||
else
|
else
|
||||||
Result := NegInfinity;
|
Result := NegInfinity;
|
||||||
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TLogarithmAxisTransform.Create(AOwner: TComponent);
|
constructor TLogarithmAxisTransform.Create(AOwner: TComponent);
|
||||||
@ -630,13 +625,11 @@ end;
|
|||||||
procedure TAutoScaleAxisTransform.ClearBounds;
|
procedure TAutoScaleAxisTransform.ClearBounds;
|
||||||
begin
|
begin
|
||||||
inherited ClearBounds;
|
inherited ClearBounds;
|
||||||
{$R-}{$Q-}
|
|
||||||
with TAutoScaleTransformData(FDrawData) do begin
|
with TAutoScaleTransformData(FDrawData) do begin
|
||||||
FMin := Infinity;
|
FMin := SafeInfinity;
|
||||||
FMax := NegInfinity;
|
FMax := NegInfinity;
|
||||||
FScale := 1.0;
|
FScale := 1.0;
|
||||||
end;
|
end;
|
||||||
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TAutoScaleAxisTransform.Create(AOwner: TComponent);
|
constructor TAutoScaleAxisTransform.Create(AOwner: TComponent);
|
||||||
@ -682,7 +675,6 @@ end;
|
|||||||
|
|
||||||
procedure TAutoScaleAxisTransform.UpdateBounds(var AMin, AMax: Double);
|
procedure TAutoScaleAxisTransform.UpdateBounds(var AMin, AMax: Double);
|
||||||
begin
|
begin
|
||||||
{$R-}{$Q-}
|
|
||||||
with TAutoScaleTransformData(FDrawData) do begin
|
with TAutoScaleTransformData(FDrawData) do begin
|
||||||
UpdateMinMax(AMin, FMin, FMax);
|
UpdateMinMax(AMin, FMin, FMax);
|
||||||
UpdateMinMax(AMax, FMin, FMax);
|
UpdateMinMax(AMax, FMin, FMax);
|
||||||
@ -692,7 +684,6 @@ begin
|
|||||||
FScale := (MaxValue - MinValue) / (FMax - FMin);
|
FScale := (MaxValue - MinValue) / (FMax - FMin);
|
||||||
FOffset := MinValue - FMin * FScale;
|
FOffset := MinValue - FMin * FScale;
|
||||||
end;
|
end;
|
||||||
{$IFDEF OverflowChecking}{$Q+}{$ENDIF}{$IFDEF RangeChecking}{$R+}{$ENDIF}
|
|
||||||
if not IsInfinite(AMin) then
|
if not IsInfinite(AMin) then
|
||||||
AMin := MinValue;
|
AMin := MinValue;
|
||||||
if not IsInfinite(AMax) then
|
if not IsInfinite(AMax) then
|
||||||
|
Loading…
Reference in New Issue
Block a user