[apps/interactive_curve_view_range] Clean panToMakePointVisible

This commit is contained in:
Léa Saviot
2020-05-14 10:56:08 +02:00
committed by EmilieNumworks
parent 456cd3c73a
commit ee78948cf8

View File

@@ -199,30 +199,38 @@ void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) {
}
}
void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation) {
float xRange = xMax() - xMin();
float yRange = yMax() - yMin();
if (x < xMin() + leftMarginRation*xRange && !std::isinf(x) && !std::isnan(x)) {
m_yAuto = false;
float newXMin = x - leftMarginRation*xRange;
m_xRange.setMax(newXMin + xRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRatio, float leftMarginRatio) {
if (!std::isinf(x) && !std::isnan(x)) {
const float xRange = xMax() - xMin();
const float leftMargin = leftMarginRatio * xRange;
if (x < xMin() + leftMargin) {
m_yAuto = false;
const float newXMin = x - leftMargin;
m_xRange.setMax(newXMin + xRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
}
const float rightMargin = rightMarginRatio * xRange;
if (x > xMax() - rightMargin) {
m_yAuto = false;
m_xRange.setMax(x + rightMargin, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMin(xMax() - xRange, k_lowerMaxFloat, k_upperMaxFloat);
}
}
if (x > xMax() - rightMarginRatio*xRange && !std::isinf(x) && !std::isnan(x)) {
m_yAuto = false;
m_xRange.setMax(x + rightMarginRatio*xRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetXMin(xMax() - xRange, k_lowerMaxFloat, k_upperMaxFloat);
}
if (y < yMin() + bottomMarginRation*yRange && !std::isinf(y) && !std::isnan(y)) {
m_yAuto = false;
float newYMin = y - bottomMarginRation*yRange;
m_yRange.setMax(newYMin + yRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetYMin(newYMin, k_lowerMaxFloat, k_upperMaxFloat);
}
if (y > yMax() - topMarginRatio*yRange && !std::isinf(y) && !std::isnan(y)) {
m_yAuto = false;
m_yRange.setMax(y + topMarginRatio*yRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetYMin(yMax() - yRange, k_lowerMaxFloat, k_upperMaxFloat);
if (!std::isinf(y) && !std::isnan(y)) {
const float yRange = yMax() - yMin();
const float bottomMargin = bottomMarginRatio * yRange;
if (y < yMin() + bottomMargin) {
m_yAuto = false;
const float newYMin = y - bottomMargin;
m_yRange.setMax(newYMin + yRange, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetYMin(newYMin, k_lowerMaxFloat, k_upperMaxFloat);
}
const float topMargin = topMarginRatio * yRange;
if (y > yMax() - topMargin) {
m_yAuto = false;
m_yRange.setMax(y + topMargin, k_lowerMaxFloat, k_upperMaxFloat);
MemoizedCurveViewRange::protectedSetYMin(yMax() - yRange, k_lowerMaxFloat, k_upperMaxFloat);
}
}
}