mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
#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>
|
|
|
|
#include <cmath>
|
|
|
|
extern "C" {
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
}
|
|
|
|
using namespace Shared;
|
|
using namespace Poincare;
|
|
|
|
namespace Sequence {
|
|
|
|
TermSumController::TermSumController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, GraphView * graphView, CurveViewRange * graphRange, CurveViewCursor * cursor) :
|
|
SumGraphController(parentResponder, inputEventHandlerDelegate, graphView, graphRange, cursor, UCodePointNArySummation)
|
|
{
|
|
}
|
|
|
|
const char * TermSumController::title() {
|
|
return I18n::translate(I18n::Message::TermSum);
|
|
}
|
|
|
|
bool TermSumController::moveCursorHorizontallyToPosition(double position) {
|
|
if (position < 0.0) {
|
|
return false;
|
|
}
|
|
return SumGraphController::moveCursorHorizontallyToPosition(std::round(position));
|
|
}
|
|
|
|
I18n::Message TermSumController::legendMessageAtStep(Step step) {
|
|
switch(step) {
|
|
case Step::FirstParameter:
|
|
return I18n::Message::SelectFirstTerm;
|
|
case Step::SecondParameter:
|
|
return I18n::Message::SelectLastTerm;
|
|
default:
|
|
return I18n::Message::Default;
|
|
}
|
|
}
|
|
|
|
double TermSumController::cursorNextStep(double x, int direction) {
|
|
double delta = direction > 0 ? 1.0 : -1.0;
|
|
return std::round(m_cursor->x()+delta);
|
|
}
|
|
|
|
Layout TermSumController::createFunctionLayout(Shared::ExpiringPointer<Shared::Function> function) {
|
|
Sequence * sequence = static_cast<Sequence *>(function.pointer());
|
|
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
|
|
}
|
|
|
|
}
|