diff --git a/apps/solver/base.de.i18n b/apps/solver/base.de.i18n index b57115d60..7e5b250b1 100644 --- a/apps/solver/base.de.i18n +++ b/apps/solver/base.de.i18n @@ -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" diff --git a/apps/solver/base.en.i18n b/apps/solver/base.en.i18n index 970fd4d41..0aaa4efe4 100644 --- a/apps/solver/base.en.i18n +++ b/apps/solver/base.en.i18n @@ -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" diff --git a/apps/solver/base.es.i18n b/apps/solver/base.es.i18n index fc1014028..7611eb06f 100644 --- a/apps/solver/base.es.i18n +++ b/apps/solver/base.es.i18n @@ -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" diff --git a/apps/solver/base.fr.i18n b/apps/solver/base.fr.i18n index 9c5b3e809..f8d408d11 100644 --- a/apps/solver/base.fr.i18n +++ b/apps/solver/base.fr.i18n @@ -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" diff --git a/apps/solver/base.pt.i18n b/apps/solver/base.pt.i18n index 6c47727bb..96a97debf 100644 --- a/apps/solver/base.pt.i18n +++ b/apps/solver/base.pt.i18n @@ -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" diff --git a/apps/solver/equation.h b/apps/solver/equation.h index 4de2bbb84..3a079e836 100644 --- a/apps/solver/equation.h +++ b/apps/solver/equation.h @@ -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; diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp index 1347548b1..b9e3a7fd8 100644 --- a/apps/solver/equation_store.cpp +++ b/apps/solver/equation_store.cpp @@ -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 diff --git a/apps/solver/equation_store.h b/apps/solver/equation_store.h index 497e391c3..ffa1f4017 100644 --- a/apps/solver/equation_store.h +++ b/apps/solver/equation_store.h @@ -3,6 +3,7 @@ #include "equation.h" #include "../shared/expression_model_store.h" +#include #include 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]; diff --git a/apps/solver/solutions_controller.cpp b/apps/solver/solutions_controller.cpp index 0fd601115..bc28a6d47 100644 --- a/apps/solver/solutions_controller.cpp +++ b/apps/solver/solutions_controller.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include using namespace Poincare; @@ -155,17 +156,17 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, } else { EvenOddBufferTextCell * symbolCell = static_cast(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; diff --git a/poincare/test/properties.cpp b/poincare/test/properties.cpp index 6583d8b83..aee5fc0c2 100644 --- a/poincare/test/properties.cpp +++ b/poincare/test/properties.cpp @@ -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);