C++ (Qt)double Near( const Key & k1, const Key & k2 ) { return fabs(k1 - k2); }
C++ (Qt)double Near( const QPointF & k1, const QPointF & k2 ) { QPointF delta = k1 - k2; return delta.x() * delta.x() + delta.y() * delta.y(); }
C++ (Qt)int index = std::distance(pt.begin(), std::lower_bound(pt.begin(), pt.end(), CompareX));int minIndex = index;double minD = Near(cntr, pt[index]);for (int i = index + 1; i < pt.size(); ++i) { double dx = pt[i].x() - cntr.x(); if (dx * dx > minD) break; double d = Near(cntr, pt[i]); if (d > minD) continue; minD = d; minIndex = i;}