! \internal A convenience function which returns the selectTest value for a specified \a rect and a specified click position \a pos. \a filledRect defines whether a click inside the rect should also be considered a hit or whether only the rect border is sensitive to hits. This function may be used to help with the implementation of the \ref selectTest function for specific items.
| 12415 | returned values. |
| 12416 | */ |
| 12417 | double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const |
| 12418 | { |
| 12419 | double result = -1; |
| 12420 | |
| 12421 | // distance to border: |
| 12422 | QList<QLineF> lines; |
| 12423 | lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) |
| 12424 | << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); |
| 12425 | double minDistSqr = (std::numeric_limits<double>::max)(); |
| 12426 | for (int i=0; i<lines.size(); ++i) |
| 12427 | { |
| 12428 | double distSqr = QCPVector2D(pos).distanceSquaredToLine(lines.at(i).p1(), lines.at(i).p2()); |
| 12429 | if (distSqr < minDistSqr) |
| 12430 | minDistSqr = distSqr; |
| 12431 | } |
| 12432 | result = qSqrt(minDistSqr); |
| 12433 | |
| 12434 | // filled rect, allow click inside to count as hit: |
| 12435 | if (filledRect && result > mParentPlot->selectionTolerance()*0.99) |
| 12436 | { |
| 12437 | if (rect.contains(pos)) |
| 12438 | result = mParentPlot->selectionTolerance()*0.99; |
| 12439 | } |
| 12440 | return result; |
| 12441 | } |
| 12442 | |
| 12443 | /*! \internal |
| 12444 |
nothing calls this directly
no test coverage detected