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

Method getCurveLines

src/qt/qcustomplot.cpp:22214–22295  ·  view source on GitHub ↗

! \internal Called by \ref draw to generate points in pixel coordinates which represent the line of the curve. Line segments that aren't visible in the current axis rect are handled in an optimized way. They are projected onto a rectangle slightly larger than the visible axis rect and simplified regarding point count. The algorithm makes sure to preserve appearance of lines and fills i

Source from the content-addressed store, hash-verified

22212 \see drawCurveLine, drawScatterPlot
22213*/
22214void QCPCurve::getCurveLines(QVector<QPointF> *lines, const QCPDataRange &dataRange, double penWidth) const
22215{
22216 if (!lines) return;
22217 lines->clear();
22218 QCPAxis *keyAxis = mKeyAxis.data();
22219 QCPAxis *valueAxis = mValueAxis.data();
22220 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; }
22221
22222 // add margins to rect to compensate for stroke width
22223 const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety
22224 const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation());
22225 const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation());
22226 const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation());
22227 const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation());
22228 QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin();
22229 QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd();
22230 mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange);
22231 if (itBegin == itEnd)
22232 return;
22233 QCPCurveDataContainer::const_iterator it = itBegin;
22234 QCPCurveDataContainer::const_iterator prevIt = itEnd-1;
22235 int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin);
22236 QVector<QPointF> trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right)
22237 while (it != itEnd)
22238 {
22239 const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin);
22240 if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R
22241 {
22242 if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal
22243 {
22244 QPointF crossA, crossB;
22245 if (prevRegion == 5) // we're coming from R, so add this point optimized
22246 {
22247 lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin));
22248 // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point
22249 *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin);
22250 } else if (mayTraverse(prevRegion, currentRegion) &&
22251 getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB))
22252 {
22253 // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point:
22254 QVector<QPointF> beforeTraverseCornerPoints, afterTraverseCornerPoints;
22255 getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints);
22256 if (it != itBegin)
22257 {
22258 *lines << beforeTraverseCornerPoints;
22259 lines->append(crossA);
22260 lines->append(crossB);
22261 *lines << afterTraverseCornerPoints;
22262 } else
22263 {
22264 lines->append(crossB);
22265 *lines << afterTraverseCornerPoints;
22266 trailingPoints << beforeTraverseCornerPoints << crossA ;
22267 }
22268 } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s)
22269 {
22270 *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin);
22271 }

Callers

nothing calls this directly

Calls 9

pixelToCoordMethod · 0.80
coordToPixelMethod · 0.80
rangeMethod · 0.80
constBeginMethod · 0.80
constEndMethod · 0.80
clearMethod · 0.45
dataMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected