mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[apps/calculation] Do no display the factor expression if it is
undefined in Integer additional outputs
This commit is contained in:
@@ -29,7 +29,7 @@ protected:
|
||||
constexpr static int k_maxNumberOfCells = 4;
|
||||
Poincare::Expression m_expression;
|
||||
// Memoization of layouts
|
||||
Poincare::Layout m_layouts[k_maxNumberOfCells];
|
||||
mutable Poincare::Layout m_layouts[k_maxNumberOfCells];
|
||||
private:
|
||||
Poincare::Layout layoutAtIndex(int index);
|
||||
virtual void computeLayoutAtIndex(int index) = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "integer_list_controller.h"
|
||||
#include <poincare/based_integer.h>
|
||||
#include <poincare/integer.h>
|
||||
#include <poincare/empty_layout.h>
|
||||
#include <poincare/factor.h>
|
||||
#include "../app.h"
|
||||
#include "../../shared/poincare_helpers.h"
|
||||
@@ -11,7 +12,7 @@ using namespace Shared;
|
||||
namespace Calculation {
|
||||
|
||||
int IntegerListController::numberOfRows() const {
|
||||
return 4;
|
||||
return 3 + factorExpressionIsComputable();
|
||||
}
|
||||
|
||||
Integer::Base baseAtIndex(int index) {
|
||||
@@ -27,14 +28,12 @@ Integer::Base baseAtIndex(int index) {
|
||||
}
|
||||
|
||||
void IntegerListController::computeLayoutAtIndex(int index) {
|
||||
assert(m_expression.type() == ExpressionNode::Type::BasedInteger);
|
||||
Poincare::Context * context = App::app()->localContext();
|
||||
if (index == 3) {
|
||||
Expression factor = Factor::Builder(m_expression.clone());
|
||||
PoincareHelpers::Simplify(&factor, context, ExpressionNode::ReductionTarget::User);
|
||||
m_layouts[index] = PoincareHelpers::CreateLayout(factor);
|
||||
if (!m_layouts[index].isUninitialized()) {
|
||||
return;
|
||||
}
|
||||
assert(m_expression.type() == ExpressionNode::Type::BasedInteger);
|
||||
// For index = k_indexOfFactorExpression, the layout is assumed to be alreday memoized because it is needed to compute the numberOfRows
|
||||
assert(index < k_indexOfFactorExpression);
|
||||
Integer i = static_cast<BasedInteger &>(m_expression).integer();
|
||||
m_layouts[index] = i.createLayout(baseAtIndex(index));
|
||||
}
|
||||
@@ -52,4 +51,20 @@ I18n::Message IntegerListController::messageAtIndex(int index) {
|
||||
}
|
||||
}
|
||||
|
||||
bool IntegerListController::factorExpressionIsComputable() const {
|
||||
if (!m_layouts[k_indexOfFactorExpression].isUninitialized()) {
|
||||
// The factor expression is already memoized
|
||||
return !m_layouts[k_indexOfFactorExpression].isEmpty();
|
||||
}
|
||||
Poincare::Context * context = App::app()->localContext();
|
||||
Expression factor = Factor::Builder(m_expression.clone());
|
||||
PoincareHelpers::Simplify(&factor, context, ExpressionNode::ReductionTarget::User);
|
||||
if (!factor.isUndefined()) {
|
||||
m_layouts[k_indexOfFactorExpression] = PoincareHelpers::CreateLayout(factor);
|
||||
return true;
|
||||
}
|
||||
m_layouts[k_indexOfFactorExpression] = EmptyLayout::Builder();
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ public:
|
||||
//ListViewDataSource
|
||||
int numberOfRows() const override;
|
||||
private:
|
||||
static constexpr int k_indexOfFactorExpression = 3;
|
||||
void computeLayoutAtIndex(int index) override;
|
||||
I18n::Message messageAtIndex(int index) override;
|
||||
bool factorExpressionIsComputable() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user