diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index 3c781c31d..c5b039d7b 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -1,5 +1,6 @@ #include "integral_graph_controller.h" #include "../../shared/text_field_delegate.h" +#include #include #include "../app.h" @@ -46,4 +47,11 @@ Layout IntegralGraphController::createFunctionLayout(ExpiringPointer function, double start, double end, Poincare::Context * context) const { + return Poincare::Integral::Builder(function->expressionReduced(context).clone(), Poincare::Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Integral takes ownership of args + /* TODO: when we approximate integral, we might want to simplify the integral + * here. However, we might want to do it once for all x (to avoid lagging in + * the derivative table. */ +} + } diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h index 6243127d7..7e7257a59 100644 --- a/apps/graph/graph/integral_graph_controller.h +++ b/apps/graph/graph/integral_graph_controller.h @@ -15,6 +15,7 @@ private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; + Poincare::Expression sumBetweenBounds(Shared::ExpiringPointer function, double start, double end, Poincare::Context * context) const override; }; } diff --git a/apps/sequence/graph/term_sum_controller.cpp b/apps/sequence/graph/term_sum_controller.cpp index 71cad17bb..6446926ee 100644 --- a/apps/sequence/graph/term_sum_controller.cpp +++ b/apps/sequence/graph/term_sum_controller.cpp @@ -1,5 +1,6 @@ #include "term_sum_controller.h" #include "../../shared/text_field_delegate.h" +#include #include #include #include @@ -53,4 +54,8 @@ Layout TermSumController::createFunctionLayout(Shared::ExpiringPointernameLayout(); } +Poincare::Expression TermSumController::sumBetweenBounds(Shared::ExpiringPointer function, double start, double end, Poincare::Context * context) const { + return Poincare::Sum::Builder(function->expressionReduced(context).clone(), Poincare::Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Sum takes ownership of args +} + } diff --git a/apps/sequence/graph/term_sum_controller.h b/apps/sequence/graph/term_sum_controller.h index 092c3377c..5c58a602c 100644 --- a/apps/sequence/graph/term_sum_controller.h +++ b/apps/sequence/graph/term_sum_controller.h @@ -18,6 +18,7 @@ private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; Poincare::Layout createFunctionLayout(Shared::ExpiringPointer function) override; + Poincare::Expression sumBetweenBounds(Shared::ExpiringPointer function, double start, double end, Poincare::Context * context) const override; }; } diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 296d0e0dc..fb59b8ca9 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include "../shared/poincare_helpers.h" #include #include @@ -186,11 +185,6 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const { } } -double Sequence::sumBetweenBounds(double start, double end, Context * context) const { - Poincare::Sum sum = Poincare::Sum::Builder(expressionReduced(context).clone(), Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Sum takes ownership of args - return PoincareHelpers::ApproximateToScalar(sum, *context); -} - Sequence::SequenceRecordDataBuffer * Sequence::recordData() const { assert(!isNull()); Ion::Storage::Record::Data d = value(); diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index 794d4bdd6..a3393fe8b 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -64,8 +64,6 @@ public: return templatedApproximateAtAbscissa(x, static_cast(context)); } template T approximateToNextRank(int n, SequenceContext * sqctx) const; - // Integral - double sumBetweenBounds(double start, double end, Poincare::Context * context) const override; constexpr static int k_initialRankNumberOfDigits = 3; // m_initialRank is capped by 999 private: diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index 8e27cdb9e..823b5e8cc 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -2,7 +2,6 @@ #include "expression_model_store.h" #include "poincare_helpers.h" #include -#include #include #include #include @@ -95,15 +94,6 @@ double CartesianFunction::approximateDerivative(double x, Poincare::Context * co return PoincareHelpers::ApproximateToScalar(derivative, context); } -double CartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const { - // TODO: this does not work yet because integral does not understand UnknownX - Poincare::Integral integral = Poincare::Integral::Builder(expressionReduced(context).clone(), Symbol::Builder(UCodePointUnknownX), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Integral takes ownership of args - /* TODO: when we approximate integral, we might want to simplify the integral - * here. However, we might want to do it once for all x (to avoid lagging in - * the derivative table. */ - return PoincareHelpers::ApproximateToScalar(integral, context); -} - void * CartesianFunction::Model::expressionAddress(const Ion::Storage::Record * record) const { return (char *)record->value().buffer+sizeof(CartesianFunctionRecordDataBuffer); } diff --git a/apps/shared/cartesian_function.h b/apps/shared/cartesian_function.h index d45d54f64..2ccea10d5 100644 --- a/apps/shared/cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -28,8 +28,6 @@ public: void setDisplayDerivative(bool display); int derivativeNameWithArgument(char * buffer, size_t bufferSize); double approximateDerivative(double x, Poincare::Context * context) const; - // Integral - double sumBetweenBounds(double start, double end, Poincare::Context * context) const override; private: /* CartesianFunctionRecordDataBuffer is the layout of the data buffer of Record * representing a CartesianFunction. See comment on diff --git a/apps/shared/function.h b/apps/shared/function.h index 207a35796..9baca7094 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -38,7 +38,6 @@ public: // Evaluation virtual float evaluateAtAbscissa(float x, Poincare::Context * context) const = 0; virtual double evaluateAtAbscissa(double x, Poincare::Context * context) const = 0; - virtual double sumBetweenBounds(double start, double end, Poincare::Context * context) const = 0; protected: /* FunctionRecordDataBuffer is the layout of the data buffer of Record * representing a Function. We want to avoid padding which would: diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index 6400e16d0..01b34e940 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -135,7 +135,9 @@ void SumGraphController::reloadBannerView() { FunctionApp * myApp = FunctionApp::app(); assert(!m_record.isNull()); ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); - result = function->sumBetweenBounds(m_startSum, endSum, myApp->localContext()); + Poincare::Context * context = myApp->localContext(); + Poincare::Expression sum = sumBetweenBounds(function, m_startSum, endSum, context); + result = PoincareHelpers::ApproximateToScalar(sum, context); functionLayout = createFunctionLayout(function); } else { m_legendView.setEditableZone(m_cursor->x()); diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index 6a7ba1b86..4da12363a 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -42,6 +42,7 @@ private: virtual I18n::Message legendMessageAtStep(Step step) = 0; virtual double cursorNextStep(double position, int direction) = 0; virtual Poincare::Layout createFunctionLayout(ExpiringPointer function) = 0; + virtual Poincare::Expression sumBetweenBounds(ExpiringPointer function, double start, double end, Poincare::Context * context) const = 0; class LegendView : public View { public: LegendView(SumGraphController * controller, InputEventHandlerDelegate * inputEventHandlerDelegate, CodePoint sumSymbol);