MCPcopy Create free account
hub / github.com/cutechess/cutechess / getOptimizedPoint

Method getOptimizedPoint

projects/gui/3rdparty/qcustomplot/qcustomplot.cpp:23313–23409  ·  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

23311 equal to 5.
23312*/
23313QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const
23314{
23315 // The intersection point interpolation here is done in pixel coordinates, so we don't need to
23316 // differentiate between different axis scale types. Note that the nomenclature
23317 // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be
23318 // different in pixel coordinates (horz/vert key axes, reversed ranges)
23319
23320 const double keyMinPx = mKeyAxis->coordToPixel(keyMin);
23321 const double keyMaxPx = mKeyAxis->coordToPixel(keyMax);
23322 const double valueMinPx = mValueAxis->coordToPixel(valueMin);
23323 const double valueMaxPx = mValueAxis->coordToPixel(valueMax);
23324 const double otherValuePx = mValueAxis->coordToPixel(otherValue);
23325 const double valuePx = mValueAxis->coordToPixel(value);
23326 const double otherKeyPx = mKeyAxis->coordToPixel(otherKey);
23327 const double keyPx = mKeyAxis->coordToPixel(key);
23328 double intersectKeyPx = keyMinPx; // initial key just a fail-safe
23329 double intersectValuePx = valueMinPx; // initial value just a fail-safe
23330 switch (otherRegion)
23331 {
23332 case 1: // top and left edge
23333 {
23334 intersectValuePx = valueMaxPx;
23335 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
23336 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)
23337 {
23338 intersectKeyPx = keyMinPx;
23339 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
23340 }
23341 break;
23342 }
23343 case 2: // left edge
23344 {
23345 intersectKeyPx = keyMinPx;
23346 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
23347 break;
23348 }
23349 case 3: // bottom and left edge
23350 {
23351 intersectValuePx = valueMinPx;
23352 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
23353 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)
23354 {
23355 intersectKeyPx = keyMinPx;
23356 intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx);
23357 }
23358 break;
23359 }
23360 case 4: // top edge
23361 {
23362 intersectValuePx = valueMaxPx;
23363 intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx);
23364 break;
23365 }
23366 case 5:
23367 {
23368 break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table
23369 }
23370 case 6: // bottom edge

Callers

nothing calls this directly

Calls 1

coordToPixelMethod · 0.80

Tested by

no test coverage detected