mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-05 15:39:25 +01:00
TAChart: Optimize TDataPointTool.FindNearestPoint
git-svn-id: trunk@38478 -
This commit is contained in:
parent
8e2e2f20a6
commit
d9f0617b68
@ -1412,6 +1412,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDataPointTool.FindNearestPoint(APoint: TPoint);
|
procedure TDataPointTool.FindNearestPoint(APoint: TPoint);
|
||||||
|
|
||||||
|
function InBoundaryBox(ASeries: TCustomChartSeries): Boolean;
|
||||||
|
var
|
||||||
|
r, gr: TDoubleRect;
|
||||||
|
begin
|
||||||
|
r := ASeries.GetGraphBounds;
|
||||||
|
if not RectIntersectsRect(r, FChart.CurrentExtent) then exit(false);
|
||||||
|
case DistanceMode of
|
||||||
|
cdmOnlyX: begin
|
||||||
|
gr.a := DoublePoint(FChart.XImageToGraph(APoint.X - GrabRadius), NegInfinity);
|
||||||
|
gr.b := DoublePoint(FChart.XImageToGraph(APoint.X + GrabRadius), SafeInfinity);
|
||||||
|
end;
|
||||||
|
cdmOnlyY: begin
|
||||||
|
gr.a := DoublePoint(NegInfinity, FChart.YImageToGraph(APoint.Y - GrabRadius));
|
||||||
|
gr.b := DoublePoint(SafeInfinity, FChart.YImageToGraph(APoint.Y + GrabRadius));
|
||||||
|
end;
|
||||||
|
cdmXY: begin
|
||||||
|
gr.a := FChart.ImageToGraph(APoint - Point(GrabRadius, GrabRadius));
|
||||||
|
gr.b := FChart.ImageToGraph(APoint + Point(GrabRadius, GrabRadius));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result := RectIntersectsRect(r, gr);
|
||||||
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
DIST_FUNCS: array [TChartDistanceMode] of TPointDistFunc = (
|
DIST_FUNCS: array [TChartDistanceMode] of TPointDistFunc = (
|
||||||
@PointDist, @PointDistX, @PointDistY);
|
@PointDist, @PointDistX, @PointDistY);
|
||||||
@ -1426,8 +1450,8 @@ begin
|
|||||||
best.FDist := MaxInt;
|
best.FDist := MaxInt;
|
||||||
for s in CustomSeries(FChart, FAffectedSeries.AsBooleans(FChart.SeriesCount)) do
|
for s in CustomSeries(FChart, FAffectedSeries.AsBooleans(FChart.SeriesCount)) do
|
||||||
if
|
if
|
||||||
s.GetNearestPoint(p, cur) and PtInRect(FChart.ClipRect, cur.FImg) and
|
InBoundaryBox(s) and s.GetNearestPoint(p, cur) and
|
||||||
(cur.FDist < best.FDist)
|
PtInRect(FChart.ClipRect, cur.FImg) and (cur.FDist < best.FDist)
|
||||||
then begin
|
then begin
|
||||||
bestS := s;
|
bestS := s;
|
||||||
best := cur;
|
best := cur;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user