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

Method getOptimizedPoint

qcustomplot/qcustomplot.cpp:22521–22617  ·  view source on GitHub ↗

! \internal This function is part of the curve optimization algorithm of \ref getCurveLines. This method is used in case the current segment passes from inside the visible rect (region 5, see \ref getRegion) to any of the outer regions (\a otherRegion). The current segment is given by the line connecting (\a key, \a value) with (\a otherKey, \a otherValue). It returns the inters

Source from the content-addressed store, hash-verified

22519 equal to 5.
22520*/
22521QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const
22522{
22523 // The intersection point interpolation here is done in pixel coordinates, so we don't need to
22524 // differentiate between different axis scale types. Note that the nomenclature
22525 // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be
22526 // different in pixel coordinates (horz/vert key axes, reversed ranges)
22527
22528 const double keyMinPx = mKeyAxis->coordToPixel(keyMin);
22529 const double keyMaxPx = mKeyAxis->coordToPixel(keyMax);
22530 const double valueMinPx = mValueAxis->coordToPixel(valueMin);
22531 const double valueMaxPx = mValueAxis->coordToPixel(valueMax);
22532 const double otherValuePx = mValueAxis->coordToPixel(otherValue);
22533 const double valuePx = mValueAxis->coordToPixel(value);
22534 const double otherKeyPx = mKeyAxis->coordToPixel(otherKey);
22535 const double keyPx = mKeyAxis->coordToPixel(key);
22536 double intersectKeyPx = keyMinPx; // initial key just a fail-safe
22537 double intersectValuePx = valueMinPx; // initial value just a fail-safe
22538 switch (otherRegion)
22539 {
22540 case 1: // top and left edge
22541 {
22542 intersectValuePx = valueMaxPx;
22543 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
22544 if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed)
22545 {
22546 intersectKeyPx = keyMinPx;
22547 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
22548 }
22549 break;
22550 }
22551 case 2: // left edge
22552 {
22553 intersectKeyPx = keyMinPx;
22554 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
22555 break;
22556 }
22557 case 3: // bottom and left edge
22558 {
22559 intersectValuePx = valueMinPx;
22560 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
22561 if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed)
22562 {
22563 intersectKeyPx = keyMinPx;
22564 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
22565 }
22566 break;
22567 }
22568 case 4: // top edge
22569 {
22570 intersectValuePx = valueMaxPx;
22571 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
22572 break;
22573 }
22574 case 5:
22575 {
22576 break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table
22577 }
22578 case 6: // bottom edge

Callers

nothing calls this directly

Calls 1

coordToPixelMethod · 0.80

Tested by

no test coverage detected