MCPcopy Create free account
hub / github.com/collin80/SavvyCAN / getChannelFillPolygon

Method getChannelFillPolygon

qcustomplot.cpp:21453–21550  ·  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

21451 \see drawFill, getOverlappingSegments, getNonNanSegments
21452*/
21453const QPolygonF QCPGraph::getChannelFillPolygon(const QVector<QPointF> *thisData, QCPDataRange thisSegment, const QVector<QPointF> *otherData, QCPDataRange otherSegment) const
21454{
21455 if (!mChannelFillGraph)
21456 return QPolygonF();
21457
21458 QCPAxis *keyAxis = mKeyAxis.data();
21459 QCPAxis *valueAxis = mValueAxis.data();
21460 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); }
21461 if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); }
21462
21463 if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation())
21464 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)
21465
21466 if (thisData->isEmpty()) return QPolygonF();
21467 QVector<QPointF> thisSegmentData(thisSegment.size());
21468 QVector<QPointF> otherSegmentData(otherSegment.size());
21469 std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin());
21470 std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin());
21471 // pointers to be able to swap them, depending which data range needs cropping:
21472 QVector<QPointF> *staticData = &thisSegmentData;
21473 QVector<QPointF> *croppedData = &otherSegmentData;
21474
21475 // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType):
21476 if (keyAxis->orientation() == Qt::Horizontal)
21477 {
21478 // x is key
21479 // crop lower bound:
21480 if (staticData->first().x() < croppedData->first().x()) // other one must be cropped
21481 qSwap(staticData, croppedData);
21482 const int lowBound = findIndexBelowX(croppedData, staticData->first().x());
21483 if (lowBound == -1) return QPolygonF(); // key ranges have no overlap
21484 croppedData->remove(0, lowBound);
21485 // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation:
21486 if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
21487 double slope;
21488 if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x()))
21489 slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x());
21490 else
21491 slope = 0;
21492 (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x()));
21493 (*croppedData)[0].setX(staticData->first().x());
21494
21495 // crop upper bound:
21496 if (staticData->last().x() > croppedData->last().x()) // other one must be cropped
21497 qSwap(staticData, croppedData);
21498 int highBound = findIndexAboveX(croppedData, staticData->last().x());
21499 if (highBound == -1) return QPolygonF(); // key ranges have no overlap
21500 croppedData->remove(highBound+1, croppedData->size()-(highBound+1));
21501 // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation:
21502 if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
21503 const int li = croppedData->size()-1; // last index
21504 if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x()))
21505 slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x());
21506 else
21507 slope = 0;
21508 (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x()));
21509 (*croppedData)[li].setX(staticData->last().x());
21510 } else // mKeyAxis->orientation() == Qt::Vertical

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected