[apps] Move sumBetweenBounds from Shared::Function to Shared::SumGraphController

This commit is contained in:
Ruben Dashyan
2019-07-03 16:05:36 +02:00
committed by Léa Saviot
parent 1d0668a84c
commit 43d72e082f
11 changed files with 19 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
#include "integral_graph_controller.h"
#include "../../shared/text_field_delegate.h"
#include <poincare/integral.h>
#include <poincare/layout_helper.h>
#include "../app.h"
@@ -46,4 +47,11 @@ Layout IntegralGraphController::createFunctionLayout(ExpiringPointer<Shared::Fun
return LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont);
}
Poincare::Expression IntegralGraphController::sumBetweenBounds(Shared::ExpiringPointer<Shared::Function> function, double start, double end, Poincare::Context * context) const {
return Poincare::Integral::Builder(function->expressionReduced(context).clone(), Poincare::Symbol::Builder(UCodePointUnknownX), Poincare::Float<double>::Builder(start), Poincare::Float<double>::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. */
}
}

View File

@@ -15,6 +15,7 @@ private:
I18n::Message legendMessageAtStep(Step step) override;
double cursorNextStep(double position, int direction) override;
Poincare::Layout createFunctionLayout(Shared::ExpiringPointer<Shared::Function> function) override;
Poincare::Expression sumBetweenBounds(Shared::ExpiringPointer<Shared::Function> function, double start, double end, Poincare::Context * context) const override;
};
}

View File

@@ -1,5 +1,6 @@
#include "term_sum_controller.h"
#include "../../shared/text_field_delegate.h"
#include <poincare/sum.h>
#include <poincare/code_point_layout.h>
#include <poincare/horizontal_layout.h>
#include <poincare/vertical_offset_layout.h>
@@ -53,4 +54,8 @@ Layout TermSumController::createFunctionLayout(Shared::ExpiringPointer<Shared::F
return sequence->nameLayout();
}
Poincare::Expression TermSumController::sumBetweenBounds(Shared::ExpiringPointer<Shared::Function> function, double start, double end, Poincare::Context * context) const {
return Poincare::Sum::Builder(function->expressionReduced(context).clone(), Poincare::Symbol::Builder(UCodePointUnknownX), Poincare::Float<double>::Builder(start), Poincare::Float<double>::Builder(end)); // Sum takes ownership of args
}
}

View File

@@ -18,6 +18,7 @@ private:
I18n::Message legendMessageAtStep(Step step) override;
double cursorNextStep(double position, int direction) override;
Poincare::Layout createFunctionLayout(Shared::ExpiringPointer<Shared::Function> function) override;
Poincare::Expression sumBetweenBounds(Shared::ExpiringPointer<Shared::Function> function, double start, double end, Poincare::Context * context) const override;
};
}

View File

@@ -6,7 +6,6 @@
#include <poincare/code_point_layout.h>
#include <poincare/vertical_offset_layout.h>
#include <poincare/integer.h>
#include <poincare/sum.h>
#include "../shared/poincare_helpers.h"
#include <string.h>
#include <cmath>
@@ -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<double>::Builder(start), Poincare::Float<double>::Builder(end)); // Sum takes ownership of args
return PoincareHelpers::ApproximateToScalar<double>(sum, *context);
}
Sequence::SequenceRecordDataBuffer * Sequence::recordData() const {
assert(!isNull());
Ion::Storage::Record::Data d = value();

View File

@@ -64,8 +64,6 @@ public:
return templatedApproximateAtAbscissa(x, static_cast<SequenceContext *>(context));
}
template<typename T> 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:

View File

@@ -2,7 +2,6 @@
#include "expression_model_store.h"
#include "poincare_helpers.h"
#include <poincare/derivative.h>
#include <poincare/integral.h>
#include <poincare/serialization_helper.h>
#include <escher/palette.h>
#include <ion/unicode/utf8_decoder.h>
@@ -95,15 +94,6 @@ double CartesianFunction::approximateDerivative(double x, Poincare::Context * co
return PoincareHelpers::ApproximateToScalar<double>(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<double>::Builder(start), Poincare::Float<double>::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<double>(integral, context);
}
void * CartesianFunction::Model::expressionAddress(const Ion::Storage::Record * record) const {
return (char *)record->value().buffer+sizeof(CartesianFunctionRecordDataBuffer);
}

View File

@@ -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

View File

@@ -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:

View File

@@ -135,7 +135,9 @@ void SumGraphController::reloadBannerView() {
FunctionApp * myApp = FunctionApp::app();
assert(!m_record.isNull());
ExpiringPointer<Function> 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<double>(sum, context);
functionLayout = createFunctionLayout(function);
} else {
m_legendView.setEditableZone(m_cursor->x());

View File

@@ -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> function) = 0;
virtual Poincare::Expression sumBetweenBounds(ExpiringPointer<Function> function, double start, double end, Poincare::Context * context) const = 0;
class LegendView : public View {
public:
LegendView(SumGraphController * controller, InputEventHandlerDelegate * inputEventHandlerDelegate, CodePoint sumSymbol);