[apps/solver] Remove max variable name size redefinition

This commit is contained in:
Léa Saviot
2018-11-12 15:54:04 +01:00
committed by Émilie Feral
parent 2f98a14de2
commit 07d1aabb56
10 changed files with 12 additions and 16 deletions

View File

@@ -7,7 +7,6 @@ UseEquationModel = "Verwenden Sie ein Gleichungsmodell"
RequireEquation = "Die Eingabe muss eine Gleichung sein"
UndefinedEquation = "Nicht definierte Gleichung"
TooManyVariables = "Es gibt zu viele Unbekannte"
VariableNameTooLong = "Variable Namen konnen nicht 7 Zeichen überschreiten"
NonLinearSystem = "Das System ist nicht linear"
Solution = "Loesung"
ApproximateSolution = "Ungefaehre Loesung"

View File

@@ -7,7 +7,6 @@ UseEquationModel = "Use an equation template"
RequireEquation = "The input must be an equation"
UndefinedEquation = "Undefined equation"
TooManyVariables = "There are too many unknowns"
VariableNameTooLong = "The name of the unknown cannot exceed 7 characters"
NonLinearSystem = "The system is not linear"
Solution = "Solution"
ApproximateSolution = "Approximate solution"

View File

@@ -7,7 +7,6 @@ UseEquationModel = "Usar un modelo de ecuación"
RequireEquation = "La entrada debe ser una ecuación"
UndefinedEquation = "Ecuación indefinida"
TooManyVariables = "Hay demasiadas incógnitas"
VariableNameTooLong = "El nombre de una incógnita no puede tener más de 7 caracteres"
NonLinearSystem = "El sistema no es lineal"
Solution = "Solucion"
ApproximateSolution = "Solución aproximada"

View File

@@ -7,7 +7,6 @@ UseEquationModel = "Utiliser un modèle d'équation"
RequireEquation = "L'entrée doit être une équation"
UndefinedEquation = "Une equation est indéfinie"
TooManyVariables = "Le nombre d'inconnues est trop grand"
VariableNameTooLong = "Le nom d'une inconnue ne peut excéder 7 caractères"
NonLinearSystem = "Le système n'est pas linéaire"
Solution = "Solution"
ApproximateSolution = "Solution approchée"

View File

@@ -7,7 +7,6 @@ UseEquationModel = "Usar um modelo de equação"
RequireEquation = "A entrada deve ser uma equação"
UndefinedEquation = "Equação indefinida"
TooManyVariables = "Existem muitas incógnitas"
VariableNameTooLong = "O nome de uma incógnita não pode ter mais de 7 caracteres"
NonLinearSystem = "O sistema não é linear"
Solution = "Solução"
ApproximateSolution = "Solução aproximada"

View File

@@ -14,7 +14,6 @@ public:
return false;
}
Poincare::Expression standardForm(Poincare::Context * context) const;
constexpr static int k_maxVariableSize = 11;
private:
void tidyStandardForm();
mutable Poincare::Expression m_standardForm;

View File

@@ -107,13 +107,13 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
if (e.isUninitialized() || e.type() == ExpressionNode::Type::Undefined) {
return Error::EquationUndefined;
}
numberOfVariables = e.getVariables(*context, [](const char * symbol) { return true; }, (char *)m_variables, Equation::k_maxVariableSize);
numberOfVariables = e.getVariables(*context, [](const char * symbol) { return true; }, (char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize);
if (numberOfVariables == -1) {
return Error::TooManyVariables;
}
if (numberOfVariables == -2) {
return Error::VariableNameTooLong;
}
/* The equation has been parsed so there should be no
* Error::VariableNameTooLong*/
assert(numberOfVariables >= 0);
}
/* 1- Linear System? */
@@ -124,7 +124,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
bool isLinear = true; // Invalid the linear system if one equation is non-linear
Preferences * preferences = Preferences::sharedPreferences();
for (int i = 0; i < numberOfDefinedModels(); i++) {
isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Equation::k_maxVariableSize, coefficients[i], &constants[i], *context, preferences->angleUnit());
isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], *context, preferences->angleUnit());
if (!isLinear) {
// TODO: should we clean pool allocated memory if the system is not linear
#if 0

View File

@@ -3,6 +3,7 @@
#include "equation.h"
#include "../shared/expression_model_store.h"
#include <poincare/symbol_abstract.h>
#include <stdint.h>
namespace Solver {
@@ -85,7 +86,7 @@ private:
Equation m_equations[k_maxNumberOfEquations];
Type m_type;
char m_variables[Poincare::Expression::k_maxNumberOfVariables][Equation::k_maxVariableSize];
char m_variables[Poincare::Expression::k_maxNumberOfVariables][Poincare::SymbolAbstract::k_maxNameSize];
int m_numberOfSolutions;
Poincare::Layout m_exactSolutionExactLayouts[k_maxNumberOfApproximateSolutions];
Poincare::Layout m_exactSolutionApproximateLayouts[k_maxNumberOfExactSolutions];

View File

@@ -7,6 +7,7 @@
#include <poincare/layout_helper.h>
#include <poincare/char_layout.h>
#include <poincare/horizontal_layout.h>
#include <poincare/symbol_abstract.h>
#include <poincare/vertical_offset_layout.h>
using namespace Poincare;
@@ -155,17 +156,17 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i,
} else {
EvenOddBufferTextCell * symbolCell = static_cast<EvenOddBufferTextCell *>(cell);
symbolCell->setFont(KDFont::LargeFont);
char bufferSymbol[Equation::k_maxVariableSize+1]; // Hold at maximum Delta = b^2-4ac or the variable name + a digit
char bufferSymbol[Poincare::SymbolAbstract::k_maxNameSize+1]; // Hold at maximum Delta = b^2-4ac or the variable name + a digit
switch (m_equationStore->type()) {
case EquationStore::Type::LinearSystem:
/* The system has more than one variable: the cell text is the
* variable name */
strlcpy(bufferSymbol, m_equationStore->variableAtIndex(j), Equation::k_maxVariableSize);
strlcpy(bufferSymbol, m_equationStore->variableAtIndex(j), Poincare::SymbolAbstract::k_maxNameSize);
break;
default:
/* The system has one variable but might have many solutions: the cell
* text is variableX, with X the row index. For instance, x0, x1,...*/
int length = strlcpy(bufferSymbol, m_equationStore->variableAtIndex(0), Equation::k_maxVariableSize);
int length = strlcpy(bufferSymbol, m_equationStore->variableAtIndex(0), Poincare::SymbolAbstract::k_maxNameSize);
bufferSymbol[length++] = j+'0';
bufferSymbol[length] = 0;
break;

View File

@@ -83,7 +83,7 @@ QUIZ_CASE(poincare_characteristic_range) {
void assert_parsed_expression_has_variables(const char * expression, const char * variables[], int trueNumberOfVariables) {
Expression e = parse_expression(expression);
quiz_assert(!e.isUninitialized());
constexpr static int k_maxVariableSize = 10;
constexpr static int k_maxVariableSize = Poincare::SymbolAbstract::k_maxNameSize;
char variableBuffer[Expression::k_maxNumberOfVariables+1][k_maxVariableSize] = {{0}};
Shared::GlobalContext globalContext;
int numberOfVariables = e.getVariables(globalContext, [](const char * symbol) { return true; }, (char *)variableBuffer, k_maxVariableSize);