[apps/graph] If only cartesians, use domains range if < default range

The default range is [-10;10], but if all the functions are cartesian
and defined in a smaller range (for instance [-0.1,0.1]), use that
smaller range.
This commit is contained in:
Léa Saviot
2019-09-25 18:10:00 +02:00
committed by EmilieNumworks
parent ff6eb7525f
commit aa8b0964b3

View File

@@ -120,14 +120,32 @@ float GraphController::interestingXHalfRange() const {
Poincare::Context * context = textFieldDelegateApp()->localContext();
ContinuousFunctionStore * store = functionStore();
int nbActiveFunctions = store->numberOfActiveFunctions();
double tMin = INFINITY;
double tMax = -INFINITY;
for (int i = 0; i < nbActiveFunctions; i++) {
ExpiringPointer<ContinuousFunction> f = store->modelForRecord(store->activeRecordAtIndex(i));
float fRange = f->expressionReduced(context).characteristicXRange(context, Poincare::Preferences::sharedPreferences()->angleUnit());
if (!std::isnan(fRange)) {
characteristicRange = maxFloat(fRange, characteristicRange);
}
// Compute the combined range of the functions
assert(f->plotType() == ContinuousFunction::PlotType::Cartesian); // So that tMin tMax represents xMin xMax
tMin = minDouble(tMin, f->tMin());
tMax = maxDouble(tMax, f->tMax());
}
return (characteristicRange > 0.0f ? 1.6f*characteristicRange : InteractiveCurveViewRangeDelegate::interestingXHalfRange());
constexpr float rangeMultiplicator = 1.6f;
if (characteristicRange > 0.0f ) {
return rangeMultiplicator * characteristicRange;
}
float defaultXHalfRange = InteractiveCurveViewRangeDelegate::interestingXHalfRange();
assert(tMin <= tMax);
if (tMin >= -defaultXHalfRange && tMax <= defaultXHalfRange) {
/* If the combined Range of the functions is smaller than the default range,
* use it. */
float f = rangeMultiplicator * (float)maxDouble(std::fabs(tMin), std::fabs(tMax));
return (std::isnan(f) || std::isinf(f)) ? defaultXHalfRange : f;
}
return defaultXHalfRange;
}
void GraphController::selectFunctionWithCursor(int functionIndex) {