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

Method getTraverse

qcustomplot/qcustomplot.cpp:22904–22990  ·  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

22902 exit points of region 5. They will become the optimized points for that segment.
22903*/
22904bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const
22905{
22906 // The intersection point interpolation here is done in pixel coordinates, so we don't need to
22907 // differentiate between different axis scale types. Note that the nomenclature
22908 // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be
22909 // different in pixel coordinates (horz/vert key axes, reversed ranges)
22910
22911 QList<QPointF> intersections;
22912 const double valueMinPx = mValueAxis->coordToPixel(valueMin);
22913 const double valueMaxPx = mValueAxis->coordToPixel(valueMax);
22914 const double keyMinPx = mKeyAxis->coordToPixel(keyMin);
22915 const double keyMaxPx = mKeyAxis->coordToPixel(keyMax);
22916 const double keyPx = mKeyAxis->coordToPixel(key);
22917 const double valuePx = mValueAxis->coordToPixel(value);
22918 const double prevKeyPx = mKeyAxis->coordToPixel(prevKey);
22919 const double prevValuePx = mValueAxis->coordToPixel(prevValue);
22920 if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis
22921 {
22922 // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here
22923 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method
22924 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx));
22925 } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis
22926 {
22927 // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here
22928 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method
22929 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx));
22930 } else // line is skewed
22931 {
22932 double gamma;
22933 double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx);
22934 // check top of rect:
22935 gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx;
22936 if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed
22937 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma));
22938 // check bottom of rect:
22939 gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx;
22940 if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed
22941 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma));
22942 const double valuePerKeyPx = 1.0/keyPerValuePx;
22943 // check left of rect:
22944 gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx;
22945 if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed
22946 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx));
22947 // check right of rect:
22948 gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx;
22949 if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed
22950 intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx));
22951 }
22952
22953 // handle cases where found points isn't exactly 2:
22954 if (intersections.size() > 2)
22955 {
22956 // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between:
22957 double distSqrMax = 0;
22958 QPointF pv1, pv2;
22959 for (int i=0; i<intersections.size()-1; ++i)
22960 {
22961 for (int k=i+1; k<intersections.size(); ++k)

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected