From bcb4b3095bd3b97ef0d5acd2169eb9f1d6841856 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Mon, 12 Oct 2020 10:11:27 +0200 Subject: [PATCH] [function_graph_controller] Fix Y range expansion The method FunctionGraphController::yRangeForCursorFirstMove expands the Y range to include the values of the first cursor moves on the left and the right of the center. It has been modified to preserve orthonormality. Change-Id: I898ab9721e45e2acde261f8b94b80cab81b39a92 --- apps/shared/function_graph_controller.cpp | 6 ++++++ apps/shared/interactive_curve_view_range.cpp | 4 ++++ apps/shared/interactive_curve_view_range.h | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index eb5547827..df603d777 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -165,6 +165,8 @@ void FunctionGraphController::yRangeForCursorFirstMove(InteractiveCurveViewRange float cursorStep = range->xGridUnit() / k_numberOfCursorStepsInGradUnit; float yN, yP; + bool normalized = range->isOrthonormal(); + for (int i = 0; i < functionsCount; i++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); yN = f->evaluateXYAtParameter(range->xCenter() - cursorStep, context).x2(); @@ -172,6 +174,10 @@ void FunctionGraphController::yRangeForCursorFirstMove(InteractiveCurveViewRange range->setYMin(std::min(range->yMin(), std::min(yN, yP))); range->setYMax(std::max(range->yMax(), std::max(yN, yP))); } + + if (normalized) { + range->normalize(); + } } } diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 8a4d11033..0c3a7fdab 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -109,6 +109,10 @@ void InteractiveCurveViewRange::setDefault() { return; } + /* If m_zoomNormalize was left active, xGridUnit() would return the value of + * yGridUnit, even if the ranger were not truly normalized. */ + m_zoomNormalize = false; + // Compute the interesting range m_delegate->interestingRanges(this); bool revertToNormalized = isOrthonormal(); diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 447f746ad..b0c8d38c9 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -19,6 +19,7 @@ public: {} static constexpr float NormalYXRatio() { return NormalizedYHalfRange(1.f) / NormalizedXHalfRange(1.f); } + bool isOrthonormal(float tolerance = 0.f) const; void setDelegate(InteractiveCurveViewRangeDelegate * delegate) { m_delegate = delegate; } uint32_t rangeChecksum() override; @@ -68,8 +69,6 @@ protected: constexpr static float NormalizedYHalfRange(float unit) { return 3.06f * unit; } InteractiveCurveViewRangeDelegate * m_delegate; private: - bool isOrthonormal(float tolerance = 0.f) const; - bool m_zoomAuto; bool m_zoomNormalize; };