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

Method getChannelFillPolygon

src/qt/qcustomplot.cpp:21398–21495  ·  view source on GitHub ↗

! \internal Returns the polygon needed for drawing (partial) channel fills between this graph and the graph specified by \ref setChannelFillGraph. The data points of this graph are passed as pixel coordinates via \a thisData, the data of the other graph as \a otherData. The returned polygon will be calculated for the specified data segments \a thisSegment and \a otherSegment, perta

Source from the content-addressed store, hash-verified

21396 \see drawFill, getOverlappingSegments, getNonNanSegments
21397*/
21398const QPolygonF QCPGraph::getChannelFillPolygon(const QVector<QPointF> *thisData, QCPDataRange thisSegment, const QVector<QPointF> *otherData, QCPDataRange otherSegment) const
21399{
21400 if (!mChannelFillGraph)
21401 return QPolygonF();
21402
21403 QCPAxis *keyAxis = mKeyAxis.data();
21404 QCPAxis *valueAxis = mValueAxis.data();
21405 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); }
21406 if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); }
21407
21408 if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation())
21409 return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis)
21410
21411 if (thisData->isEmpty()) return QPolygonF();
21412 QVector<QPointF> thisSegmentData(thisSegment.size());
21413 QVector<QPointF> otherSegmentData(otherSegment.size());
21414 std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin());
21415 std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin());
21416 // pointers to be able to swap them, depending which data range needs cropping:
21417 QVector<QPointF> *staticData = &thisSegmentData;
21418 QVector<QPointF> *croppedData = &otherSegmentData;
21419
21420 // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType):
21421 if (keyAxis->orientation() == Qt::Horizontal)
21422 {
21423 // x is key
21424 // crop lower bound:
21425 if (staticData->first().x() < croppedData->first().x()) // other one must be cropped
21426 qSwap(staticData, croppedData);
21427 const int lowBound = findIndexBelowX(croppedData, staticData->first().x());
21428 if (lowBound == -1) return QPolygonF(); // key ranges have no overlap
21429 croppedData->remove(0, lowBound);
21430 // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation:
21431 if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
21432 double slope;
21433 if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x()))
21434 slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x());
21435 else
21436 slope = 0;
21437 (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x()));
21438 (*croppedData)[0].setX(staticData->first().x());
21439
21440 // crop upper bound:
21441 if (staticData->last().x() > croppedData->last().x()) // other one must be cropped
21442 qSwap(staticData, croppedData);
21443 int highBound = findIndexAboveX(croppedData, staticData->last().x());
21444 if (highBound == -1) return QPolygonF(); // key ranges have no overlap
21445 croppedData->remove(highBound+1, croppedData->size()-(highBound+1));
21446 // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation:
21447 if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
21448 const int li = croppedData->size()-1; // last index
21449 if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x()))
21450 slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x());
21451 else
21452 slope = 0;
21453 (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x()));
21454 (*croppedData)[li].setX(staticData->last().x());
21455 } else // mKeyAxis->orientation() == Qt::Vertical

Callers

nothing calls this directly

Calls 8

constBeginMethod · 0.80
dataMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
removeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected