diff --git a/src/qcustomplot.cpp b/src/qcustomplot.cpp index 2ba5151..2330c70 100644 --- a/src/qcustomplot.cpp +++ b/src/qcustomplot.cpp @@ -24536,7 +24536,12 @@ double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer: { // line displayed, calculate distance to line segments: QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); // don't limit data range further since with sharp data spikes, line segments may be closer to test point than segments with closer key coordinate + // 中文注释:曲线点击命中测试原先会为每一条曲线生成整段可见折线,数据量和曲线数较大时单次选中会明显卡顿。 + // 这里复用上面已经按鼠标选择容差换算出的 key 区间,并依赖 findBegin/findEnd 的 expandedRange 保留边界相邻点; + // 这样仍能覆盖穿过鼠标附近的线段,同时把一次命中测试的计算量限制在光标附近的数据窗口内。 + const int beginIndex = int(begin - mDataContainer->constBegin()); + const int endIndex = int(end - mDataContainer->constBegin()); + getLines(&lineData, QCPDataRange(beginIndex, endIndex)); QCPVector2D p(pixelPoint); const int step = mLineStyle == lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected for (int i = 0; i < lineData.size() - 1; i += step)