mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/graph] Round x before evaluating graph cursor on scroll
Change-Id: I13500669963eb8130e188a898bed0bf63655add6
This commit is contained in:
committed by
Émilie Feral
parent
bd2609bcba
commit
9e12b61849
@@ -7,6 +7,12 @@ using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
constexpr int k_precision = Preferences::MediumNumberOfSignificantDigits;
|
||||
|
||||
int convertDoubleToText(double t, char * buffer, int bufferSize) {
|
||||
return PoincareHelpers::ConvertFloatToText<double>(t, buffer, bufferSize, k_precision);
|
||||
}
|
||||
|
||||
void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Ion::Storage::Record record, FunctionStore * functionStore, Poincare::Context * context) {
|
||||
ExpiringPointer<Function> function = functionStore->modelForRecord(record);
|
||||
constexpr int bufferSize = k_maxNumberOfCharacters+PrintFloat::charSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits);
|
||||
@@ -18,9 +24,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
|
||||
strlcpy(buffer + numberOfChar, "=", bufferSize - numberOfChar);
|
||||
bannerView()->abscissaSymbol()->setText(buffer);
|
||||
|
||||
constexpr int precision = Preferences::MediumNumberOfSignificantDigits;
|
||||
|
||||
numberOfChar = PoincareHelpers::ConvertFloatToText<double>(cursor->t(), buffer, bufferSize, precision);
|
||||
numberOfChar = convertDoubleToText(cursor->t(), buffer, bufferSize);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
|
||||
bannerView()->abscissaValue()->setText(buffer);
|
||||
@@ -28,7 +32,7 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
|
||||
numberOfChar = function->nameWithArgument(buffer, bufferSize);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
numberOfChar += strlcpy(buffer+numberOfChar, "=", bufferSize-numberOfChar);
|
||||
numberOfChar += function->printValue(cursor->t(), cursor->x(),cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, precision, context);
|
||||
numberOfChar += function->printValue(cursor->t(), cursor->x(),cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, k_precision, context);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar);
|
||||
bannerView()->ordinateView()->setText(buffer);
|
||||
@@ -36,4 +40,22 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
|
||||
bannerView()->reload();
|
||||
}
|
||||
|
||||
double FunctionBannerDelegate::getValueDisplayedOnBanner(double t, Poincare::Context * context, double deltaThreshold, bool roundToZero) {
|
||||
if (roundToZero && std::fabs(t) < deltaThreshold) {
|
||||
// Round to 0 to avoid rounding to unnecessary low non-zero value.
|
||||
return 0.0;
|
||||
}
|
||||
// Convert float to text
|
||||
constexpr int bufferSize = k_maxNumberOfCharacters+PrintFloat::charSizeForFloatsWithPrecision(k_precision);
|
||||
char buffer[bufferSize];
|
||||
int numberOfChar = convertDoubleToText(t, buffer, bufferSize);
|
||||
assert(numberOfChar <= bufferSize);
|
||||
// Silence compiler warnings
|
||||
(void) numberOfChar;
|
||||
// Extract displayed value
|
||||
double displayedValue = PoincareHelpers::ApproximateToScalar<double>(buffer, context);
|
||||
// Return displayed value if difference from t is under deltaThreshold
|
||||
return std::fabs(displayedValue-t) < deltaThreshold ? displayedValue : t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user