diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index a0c91610d..90b35fa0e 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -115,7 +115,7 @@ void InteractiveCurveViewRange::setDefault() { // Compute the interesting range m_delegate->interestingRanges(this); - bool revertToNormalized = isOrthonormal(); + bool revertToNormalized = isOrthonormal(k_orthonormalTolerance); // Add margins float xRange = xMax() - xMin(); @@ -198,8 +198,8 @@ void InteractiveCurveViewRange::checkForNormalizedRange() { } bool InteractiveCurveViewRange::isOrthonormal(float tolerance) const { - float pixelHeight = std::round(Ion::Display::Height * (NormalizedYHalfRange(100.f) / Ion::Display::HeightInTenthOfMillimeter)); - float pixelWidth = std::round(Ion::Display::Width * (NormalizedXHalfRange(100.f) / Ion::Display::WidthInTenthOfMillimeter)); - return std::fabs(std::round(pixelHeight * (xMax() - xMin())) - std::round(pixelWidth * (yMax() - yMin()))) <= tolerance; + float ratio = (yMax() - yMin()) / (xMax() - xMin()); + float ratioDifference = std::fabs(std::log(ratio / NormalYXRatio())); + return ratioDifference <= tolerance; } } diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index b0c8d38c9..f9c933e85 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -19,7 +19,7 @@ public: {} static constexpr float NormalYXRatio() { return NormalizedYHalfRange(1.f) / NormalizedXHalfRange(1.f); } - bool isOrthonormal(float tolerance = 0.f) const; + bool isOrthonormal(float tolerance = 2 * FLT_EPSILON) const; void setDelegate(InteractiveCurveViewRangeDelegate * delegate) { m_delegate = delegate; } uint32_t rangeChecksum() override; @@ -52,6 +52,7 @@ protected: constexpr static float k_upperMaxFloat = 1E+8f; constexpr static float k_lowerMaxFloat = 9E+7f; constexpr static float k_maxRatioPositionRange = 1E5f; + constexpr static float k_orthonormalTolerance = 0.2f; static float clipped(float x, bool isMax) { return Range1D::clipped(x, isMax, k_lowerMaxFloat, k_upperMaxFloat); } /* In normalized settings, we put each axis so that 1cm = 2 units. For now, * the screen has size 43.2mm * 57.6mm.