[poincare/zoom] Change weight function in RangeWithRatioForDisplay

Change-Id: I21520d8220083b40baa2e4928632632f2b73cb9b
This commit is contained in:
Gabriel Ozouf
2020-11-26 12:14:43 +01:00
committed by LeaNumworks
parent b1da6031c6
commit 7f63daa28e
2 changed files with 4 additions and 3 deletions

View File

@@ -266,8 +266,9 @@ void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, f
RefinedYRangeForDisplay(evaluation, center - xRange, center + xRange, &yMinRange, &yMaxRange, context, auxiliary, sampleSize);
float currentRatio = (yMaxRange - yMinRange) / (2 * xRange);
float grade = std::fabs(std::log(currentRatio / yxRatio));
/* When in doubt, favor ranges between [-1, 1] and [-10, 10] */
grade += std::fabs(std::log(xRange / 10.f) * std::log(xRange)) * rangeMagnitudeWeight;
/* The weigth function favors the [-5, 5] range, which will expand into
* the [-10, 10] range */
grade += std::fabs(std::log(xRange / k_largeUnitMantissa)) * rangeMagnitudeWeight;
if (std::fabs(std::log(currentRatio / yxRatio)) < maxMagnitudeDifference && grade < bestGrade) {
bestGrade = grade;
bestUnit = unit;

View File

@@ -143,7 +143,7 @@ void assert_orthonormal_range_is(const char * definition, float targetXMin, floa
QUIZ_CASE(poincare_zoom_range_with_ratio) {
assert_orthonormal_range_is("1", NAN, NAN, NAN, NAN);
assert_orthonormal_range_is("x", -5, 5, -2.21179414, 2.21179414);
assert_orthonormal_range_is("x", -20, 20, -8.84717655, 8.84717655);
assert_orthonormal_range_is("x^2", -2, 2, -0.172234654, 1.59720063);
assert_orthonormal_range_is("x^3", -5, 5, -2.21179414, 2.21179414);
assert_orthonormal_range_is("^x", -5, 5, -0.852653265, 3.57093501);