TAChart: Fix TCustomPieSeries.FindContainingSlice if one of the pies has size 0. Issue #36332, based on patch by TK.

git-svn-id: trunk@62282 -
This commit is contained in:
wp 2019-11-22 10:22:39 +00:00
parent a1cbba291f
commit 09c0c58381

View File

@ -661,11 +661,19 @@ begin
end;
function TCustomPieSeries.FindContainingSlice(const APoint: TPoint): Integer;
const
Neighbors: array[0..7] of TPoint = (
(x:-1; y:-1), (x:0; y:-1), (x:1; y:-1),
(x:-1; y:0), (x:1; y:0),
(x:-1; y:1), (x:0; y:1), (x:1; y:1)
);
var
c: TPoint;
pointAngle: Double;
minAngle, maxAngle: Double;
ps: TPieSlice;
innerRadius: Integer;
neighbor: TPoint;
begin
innerRadius := CalcInnerRadius;
for ps in FSlices do begin
@ -680,7 +688,18 @@ begin
if not InRange(sqr(c.X) + sqr(c.Y), sqr(innerRadius), sqr(FRadius)) then
continue;
pointAngle := NormalizeAngle(ArcTan2(-c.Y, c.X));
if ps.FNextAngle <= ps.FPrevAngle then begin
if ps.FNextAngle = ps.FPrevAngle then begin
minAngle := pointAngle;
maxAngle := pointAngle;
for neighbor in Neighbors do begin
pointAngle := NormalizeAngle(ArcTan2(-c.Y + neighbor.Y, c.X + neighbor.X));
minAngle := Min(minAngle, pointAngle);
maxAngle := Max(maxAngle, pointAngle);
end;
if InRange(ps.FPrevAngle, minAngle, maxAngle) then
exit(ps.FOrigIndex);
end else
if ps.FNextAngle < ps.FPrevAngle then begin
if InRange(pointAngle, ps.FPrevAngle - TWO_PI, ps.FNextAngle) or
InRange(pointAngle, ps.FPrevAngle, ps.FNextAngle + TWO_PI)
then