[interactive_curve_view_range] Force equal axes

Added a tolerance when checking orthonormality, so that ranges that are
nearly orthonormal will be made orthonormal.

Change-Id: Ie3bf076086561e3ff6374e7daa9dd1a884c52d5a
This commit is contained in:
Gabriel Ozouf
2020-10-14 11:15:35 +02:00
committed by Émilie Feral
parent 482ca10363
commit 8ce9f363ad
2 changed files with 6 additions and 5 deletions

View File

@@ -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;
}
}

View File

@@ -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.