[sequence/curve_view_range] Fix normalize

Change-Id: I1e4aa49dd84f12fe4e0f2ab59912fc68fe00b2fa
This commit is contained in:
Gabriel Ozouf
2020-10-15 16:43:28 +02:00
committed by Émilie Feral
parent 6f8d80f8ae
commit 91e1154bb8

View File

@@ -16,33 +16,13 @@ CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) :
}
void CurveViewRange::normalize() {
float xMean = xCenter();
float yMean = yCenter();
Shared::InteractiveCurveViewRange::normalize();
const float unit = std::max(xGridUnit(), yGridUnit());
// Compute the X
const float newXHalfRange = NormalizedXHalfRange(unit);
float newXMin = xMean - newXHalfRange;
float newXMax = xMean + newXHalfRange;
/* The X axis is not supposed to go into the negatives, save for a small margin. However, after normalizing, it could be the case. We thus shift the X range rightward to the origin. */
float interestingXMin = m_delegate->interestingXMin();
if (newXMin < interestingXMin) {
newXMin = interestingXMin -k_displayLeftMarginRatio*2.0f*newXHalfRange;
newXMax = newXMin + 2.0f*newXHalfRange;
}
if (!std::isnan(newXMin) && !std::isnan(newXMax)) {
m_xRange.setMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
}
// Compute the Y
const float newYHalfRange = NormalizedYHalfRange(unit);
float newYMin = yMean - newYHalfRange;
float newYMax = clipped(yMean + newYHalfRange, true);
if (!std::isnan(newYMin) && !std::isnan(newYMax)) {
m_yRange.setMax(newYMax, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetYMin(newYMin, k_lowerMaxFloat, k_upperMaxFloat);
}
float xRange = xMax() - xMin();
m_xRange.setMin(interestingXMin - k_displayLeftMarginRatio * xRange);
setXMax(xMin() + xRange);
}
}