MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / rectDistance

Method rectDistance

qcustomplot/qcustomplot.cpp:12417–12441  ·  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

12415 returned values.
12416*/
12417double 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

Callers

nothing calls this directly

Calls 4

distanceSquaredToLineMethod · 0.80
atMethod · 0.80
containsMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected