MCPcopy Create free account
hub / github.com/LUX-Core/lux / rectDistance

Method rectDistance

src/qt/qcustomplot.cpp:12406–12430  ·  view source on GitHub ↗

! \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.

Source from the content-addressed store, hash-verified

12404 returned values.
12405*/
12406double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const
12407{
12408 double result = -1;
12409
12410 // distance to border:
12411 QList<QLineF> lines;
12412 lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight())
12413 << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight());
12414 double minDistSqr = std::numeric_limits<double>::max();
12415 for (int i=0; i<lines.size(); ++i)
12416 {
12417 double distSqr = QCPVector2D(pos).distanceSquaredToLine(lines.at(i).p1(), lines.at(i).p2());
12418 if (distSqr < minDistSqr)
12419 minDistSqr = distSqr;
12420 }
12421 result = qSqrt(minDistSqr);
12422
12423 // filled rect, allow click inside to count as hit:
12424 if (filledRect && result > mParentPlot->selectionTolerance()*0.99)
12425 {
12426 if (rect.contains(pos))
12427 result = mParentPlot->selectionTolerance()*0.99;
12428 }
12429 return result;
12430}
12431
12432/*! \internal
12433

Callers

nothing calls this directly

Calls 5

maxFunction · 0.85
distanceSquaredToLineMethod · 0.80
sizeMethod · 0.45
atMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected