mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-28 11:49:30 +02:00
TAChart: Protect PointDist functions from integer overflow.
This fixes issue #18348 (Reticule doesn't work when zoomed) git-svn-id: trunk@28854 -
This commit is contained in:
parent
3039874a64
commit
c7b1bd7bda
@ -705,17 +705,17 @@ end;
|
||||
|
||||
function PointDist(const A, B: TPoint): Integer;
|
||||
begin
|
||||
Result := Sqr(A.X - B.X) + Sqr(A.Y - B.Y);
|
||||
Result := Min(Sqr(Int64(A.X) - B.X) + Sqr(Int64(A.Y) - B.Y), MaxInt);
|
||||
end;
|
||||
|
||||
function PointDistX(const A, B: TPoint): Integer;
|
||||
begin
|
||||
Result := Abs(A.X - B.X);
|
||||
Result := Min(Abs(Int64(A.X) - B.X), MaxInt);
|
||||
end;
|
||||
|
||||
function PointDistY(const A, B: TPoint): Integer; inline;
|
||||
begin
|
||||
Result := Abs(A.Y - B.Y);
|
||||
Result := Min(Abs(Int64(A.Y) - B.Y), MaxInt);
|
||||
end;
|
||||
|
||||
function PointLineSide(AP, A1, A2: TPoint): TValueSign;
|
||||
|
@ -772,10 +772,13 @@ begin
|
||||
Result := UseReticule and (Count > 0);
|
||||
minDist := MaxInt;
|
||||
for i := 0 to Count - 1 do begin
|
||||
// Since axis transformation may be non-linear, the distance should be
|
||||
// measured in screen coordinates. With high zoom ratios this may lead to
|
||||
// an integer overflow, so ADistFunc should use saturation arithmetics.
|
||||
pt := Point(GetXImgValue(i), GetYImgValue(i));
|
||||
dist := ADistFunc(APoint, pt);
|
||||
if dist >= minDist then
|
||||
Continue;
|
||||
continue;
|
||||
minDist := dist;
|
||||
AIndex := i;
|
||||
AImg := pt;
|
||||
|
Loading…
Reference in New Issue
Block a user