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

Method getOverlappingSegments

qcustomplot/qcustomplot.cpp:21267–21314  ·  view source on GitHub ↗

! \internal This method takes two segment lists (e.g. created by \ref getNonNanSegments) \a thisSegments and \a otherSegments, and their associated point data \a thisData and \a otherData. It returns all pairs of segments (the first from \a thisSegments, the second from \a otherSegments), which overlap in plot coordinates. This method is useful in the case of a channel fill betwe

Source from the content-addressed store, hash-verified

21265 \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon
21266*/
21267QVector<QPair<QCPDataRange, QCPDataRange> > QCPGraph::getOverlappingSegments(QVector<QCPDataRange> thisSegments, const QVector<QPointF> *thisData, QVector<QCPDataRange> otherSegments, const QVector<QPointF> *otherData) const
21268{
21269 QVector<QPair<QCPDataRange, QCPDataRange> > result;
21270 if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty())
21271 return result;
21272
21273 int thisIndex = 0;
21274 int otherIndex = 0;
21275 const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical;
21276 while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size())
21277 {
21278 if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow
21279 {
21280 ++thisIndex;
21281 continue;
21282 }
21283 if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow
21284 {
21285 ++otherIndex;
21286 continue;
21287 }
21288 double thisLower, thisUpper, otherLower, otherUpper;
21289 if (!verticalKey)
21290 {
21291 thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x();
21292 thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x();
21293 otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x();
21294 otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x();
21295 } else
21296 {
21297 thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y();
21298 thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y();
21299 otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y();
21300 otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y();
21301 }
21302
21303 int bPrecedence;
21304 if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence))
21305 result.append(QPair<QCPDataRange, QCPDataRange>(thisSegments.at(thisIndex), otherSegments.at(otherIndex)));
21306
21307 if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment
21308 ++otherIndex;
21309 else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment
21310 ++thisIndex;
21311 }
21312
21313 return result;
21314}
21315
21316/*! \internal
21317

Callers

nothing calls this directly

Calls 6

atMethod · 0.80
endMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected