MCPcopy Create free account
hub / github.com/cutechess/cutechess / getTraverse

Method getTraverse

projects/gui/3rdparty/qcustomplot/qcustomplot.cpp:23696–23782  ·  view source on GitHub ↗

! \internal This function is part of the curve optimization algorithm of \ref getCurveLines. This method assumes that the \ref mayTraverse test has returned true, so there is a chance the segment defined by (\a prevKey, \a prevValue) and (\a key, \a value) goes through the visible region 5. The return value of this method indicates whether the segment actually traverses region 5

Source from the content-addressed store, hash-verified

23694 exit points of region 5. They will become the optimized points for that segment.
23695*/
23696bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const
23697{
23698 // The intersection point interpolation here is done in pixel coordinates, so we don't need to
23699 // differentiate between different axis scale types. Note that the nomenclature
23700 // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be
23701 // different in pixel coordinates (horz/vert key axes, reversed ranges)
23702
23703 QList<QPointF> intersections;
23704 const double valueMinPx = mValueAxis->coordToPixel(valueMin);
23705 const double valueMaxPx = mValueAxis->coordToPixel(valueMax);
23706 const double keyMinPx = mKeyAxis->coordToPixel(keyMin);
23707 const double keyMaxPx = mKeyAxis->coordToPixel(keyMax);
23708 const double keyPx = mKeyAxis->coordToPixel(key);
23709 const double valuePx = mValueAxis->coordToPixel(value);
23710 const double prevKeyPx = mKeyAxis->coordToPixel(prevKey);
23711 const double prevValuePx = mValueAxis->coordToPixel(prevValue);
23712 if (qFuzzyIsNull(keyPx-prevKeyPx)) // line is parallel to value axis
23713 {
23714 // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here
23715 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method
23716 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx));
23717 } else if (qFuzzyIsNull(valuePx-prevValuePx)) // line is parallel to key axis
23718 {
23719 // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here
23720 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method
23721 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx));
23722 } else // line is skewed
23723 {
23724 double gamma;
23725 double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx);
23726 // check top of rect:
23727 gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx;
23728 if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed
23729 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma));
23730 // check bottom of rect:
23731 gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx;
23732 if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed
23733 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma));
23734 const double valuePerKeyPx = 1.0/keyPerValuePx;
23735 // check left of rect:
23736 gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx;
23737 if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed
23738 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx));
23739 // check right of rect:
23740 gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx;
23741 if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed
23742 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx));
23743 }
23744
23745 // handle cases where found points isn't exactly 2:
23746 if (intersections.size() > 2)
23747 {
23748 // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between:
23749 double distSqrMax = 0;
23750 QPointF pv1, pv2;
23751 for (int i=0; i<intersections.size()-1; ++i)
23752 {
23753 for (int k=i+1; k<intersections.size(); ++k)

Callers

nothing calls this directly

Calls 5

coordToPixelMethod · 0.80
appendMethod · 0.80
atMethod · 0.80
sizeMethod · 0.45
moveMethod · 0.45

Tested by

no test coverage detected