TAChart: Fix TCustomChartSource.FindBounds for XCount = 0. Add test cases.

git-svn-id: trunk@61016 -
This commit is contained in:
wp 2019-04-18 13:49:58 +00:00
parent f88bcbfd2d
commit 81f4762dba
2 changed files with 32 additions and 6 deletions

View File

@ -1039,7 +1039,7 @@ begin
end;
// ALB -> leftmost item where X >= AXMin, or Count if no such item
// ALB -> rightmost item where X <= AXMax, or -1 if no such item
// AUB -> rightmost item where X <= AXMax, or -1 if no such item
// If the source is sorted by X in the ascending order, performs
// binary search. Otherwise, skips NaNs.
procedure TCustomChartSource.FindBounds(
@ -1072,8 +1072,12 @@ procedure TCustomChartSource.FindBounds(
begin
EnsureOrder(AXMin, AXMax);
if (XCount = 0) then begin
ALB := trunc(AXMin);
AUB := ceil(AXMax);
if AXMin > Count-1 then ALB := Count
else if AXMin < 0 then ALB := 0
else ALB := ceil(AXMin);
if AXMax > Count-1 then AUB := Count - 1
else if AXMax < 0 then AUB := -1
else AUB := trunc(AXMax);
end else
if IsSortedByXAsc then begin
ALB := FindLB(AXMin, 0, Count - 1);

View File

@ -297,15 +297,32 @@ procedure TListSourceTest.Bounds;
procedure CheckAll;
begin
Check2(1, 2, 2, 3);
Check2(1, 2, 1.9, 3.1);
Check2(2, 1, 2.1, 2.9);
Check(1, 1, 2);
Check(1, 0, 1.9);
Check(0, -1, 0.9);
Check(5, 4, 5.1);
Check(4, 3, 4.9);
Check(0, -1, 0.9); // below left-most point
Check(5, 4, 5.1); // above right-most point
Check(4, 3, 4.9); // just below right-most point
Check2(2, 4, 3, 1e100);
Check2(0, 1, -1e100, 2);
end;
procedure CheckAll_XCount0;
begin
Check2(2, 3, 2, 3);
Check2(2, 3, 1.9, 3.1);
Check2(3, 2, 2.1, 2.9);
Check(2, 2, 2);
Check(2, 1, 1.9);
Check(0, -1, -0.1); // below left-most point
Check(5, 4, 4.1); // above right-most point
Check(4, 3, 3.9); // just below right-most point
Check2(2, 4, 2, 1e100);
Check2(0, 1, -1e100, 1);
end;
begin
FSource.Clear;
FSource.Add(1, 2);
@ -317,6 +334,11 @@ begin
CheckAll;
FSource.Sorted := false;
CheckAll;
FSource.XCount := 0;
CheckAll_XCount0;
FSource.XCount := 1;
FSource.SetXValue(1, SafeNan);
Check(2, 0, 2);
FSource.SetXValue(0, SafeNan);