[apps] Graph: when setting default range of a function, take

into account the potential periodicity
This commit is contained in:
Émilie Feral
2018-02-13 17:42:52 +01:00
committed by EmilieNumworks
parent 660775903f
commit 05055c387f
6 changed files with 24 additions and 3 deletions

View File

@@ -39,6 +39,19 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) {
m_displayDerivativeInBanner = displayDerivative;
}
float GraphController::interestingXRange() {
float characteristicRange = 0.0f;
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
Function * f = functionStore()->activeFunctionAtIndex(i);
float fRange = f->expression(myApp->localContext())->characteristicXRange(*(myApp->localContext()));
if (!std::isnan(fRange)) {
characteristicRange = fRange > characteristicRange ? fRange : characteristicRange;
}
}
return (characteristicRange > 0.0f ? 1.6f*characteristicRange : 10.0f);
}
void GraphController::selectFunctionWithCursor(int functionIndex) {
FunctionGraphController::selectFunctionWithCursor(functionIndex);
CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor());

View File

@@ -20,6 +20,7 @@ public:
void viewWillAppear() override;
bool displayDerivativeInBanner() const;
void setDisplayDerivativeInBanner(bool displayDerivative);
float interestingXRange() override;
private:
void selectFunctionWithCursor(int functionIndex) override;
BannerView * bannerView() override;

View File

@@ -75,7 +75,8 @@ void CurveViewRange::setTrigonometric() {
}
void CurveViewRange::setDefault() {
m_xMax = 10.0f;
assert(m_delegate);
m_xMax = m_delegate->interestingXRange();
m_xMin = -k_displayLeftMarginRatio*m_xMax;
m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax);
setYAuto(true);

View File

@@ -167,8 +167,9 @@ void InteractiveCurveViewRange::setTrigonometric() {
}
void InteractiveCurveViewRange::setDefault() {
m_xMax = 10.0f;
MemoizedCurveViewRange::setXMin(-10.0f);
assert(m_delegate);
m_xMax = m_delegate->interestingXRange();
MemoizedCurveViewRange::setXMin(-m_xMax);
setYAuto(true);
}

View File

@@ -48,4 +48,8 @@ bool InteractiveCurveViewRangeDelegate::didChangeRange(InteractiveCurveViewRange
return true;
}
float InteractiveCurveViewRangeDelegate::interestingXRange() {
return 10.0f;
}
}

View File

@@ -8,6 +8,7 @@ class InteractiveCurveViewRange;
class InteractiveCurveViewRangeDelegate {
public:
bool didChangeRange(InteractiveCurveViewRange * interactiveCurveViewRange);
virtual float interestingXRange();
protected:
struct Range {
float min;