mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-20 14:20:39 +01:00
58 lines
2.3 KiB
C++
58 lines
2.3 KiB
C++
#include "integral_graph_controller.h"
|
|
#include "../../shared/text_field_delegate.h"
|
|
#include <poincare/integral.h>
|
|
#include <poincare/layout_helper.h>
|
|
#include "../app.h"
|
|
|
|
#include <assert.h>
|
|
#include <cmath>
|
|
#include <stdlib.h>
|
|
|
|
using namespace Shared;
|
|
using namespace Poincare;
|
|
|
|
namespace Graph {
|
|
|
|
IntegralGraphController::IntegralGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, GraphView * graphView, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) :
|
|
SumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, UCodePointIntegral)
|
|
{
|
|
}
|
|
|
|
const char * IntegralGraphController::title() {
|
|
return I18n::translate(I18n::Message::Integral);
|
|
}
|
|
|
|
I18n::Message IntegralGraphController::legendMessageAtStep(Step step) {
|
|
switch(step) {
|
|
case Step::FirstParameter:
|
|
return I18n::Message::SelectLowerBound;
|
|
case Step::SecondParameter:
|
|
return I18n::Message::SelectUpperBound;
|
|
default:
|
|
return I18n::Message::Default;
|
|
}
|
|
}
|
|
|
|
double IntegralGraphController::cursorNextStep(double x, int direction) {
|
|
return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit);
|
|
}
|
|
|
|
Layout IntegralGraphController::createFunctionLayout(ExpiringPointer<Shared::Function> function) {
|
|
constexpr size_t bufferSize = SymbolAbstract::k_maxNameSize+5; // f(x)dx
|
|
char buffer[bufferSize];
|
|
const char * dx = "dx";
|
|
int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx));
|
|
assert(numberOfChars <= bufferSize);
|
|
strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars);
|
|
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. */
|
|
}
|
|
|
|
}
|