From fd49bc20b8bf83cd0d8eac17a95fab1e6ffbf051 Mon Sep 17 00:00:00 2001 From: ask Date: Tue, 11 Sep 2012 16:18:21 +0000 Subject: [PATCH] TAChart: Fix GetNearestPoint returning true with no points found inside radius, issue #22854 git-svn-id: trunk@38617 - --- components/tachart/tacustomseries.pas | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/tachart/tacustomseries.pas b/components/tachart/tacustomseries.pas index e851a3dcce..2ac5c0b318 100644 --- a/components/tachart/tacustomseries.pas +++ b/components/tachart/tacustomseries.pas @@ -1014,8 +1014,8 @@ var pt: TPoint; sp: TDoublePoint; begin - Result := Count > 0; - AResults.FDist := MaxInt; + AResults.FDist := Sqr(AParams.FRadius) + 1; + AResults.FIndex := -1; for i := 0 to Count - 1 do begin sp := Source[i]^.Point; if IsNan(sp) then continue; @@ -1024,12 +1024,13 @@ begin // an integer overflow, so ADistFunc should use saturation arithmetics. pt := ParentChart.GraphToImage(AxisToGraph(sp)); dist := AParams.FDistFunc(AParams.FPoint, pt); - if (dist >= AResults.FDist) or (dist > Sqr(AParams.FRadius)) then continue; + if dist >= AResults.FDist then continue; AResults.FDist := dist; AResults.FIndex := i; AResults.FImg := pt; - AResults.FValue := DoublePoint(GetXValue(i), GetYValue(i)); + AResults.FValue := sp; end; + Result := AResults.FIndex >= 0; end; function TBasicPointSeries.GetXRange(AX: Double; AIndex: Integer): Double;