From 041b643b15963e4f2bb726822beabb839fe46bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 6 Nov 2018 11:45:52 +0100 Subject: [PATCH] [apps/solver] Fix variable name computation problem --- apps/solver/solutions_controller.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/solver/solutions_controller.cpp b/apps/solver/solutions_controller.cpp index 2e183d1da..33ad70d58 100644 --- a/apps/solver/solutions_controller.cpp +++ b/apps/solver/solutions_controller.cpp @@ -147,7 +147,9 @@ int SolutionsController::numberOfColumns() { void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { if (i == 0) { + // Name of the variable or discriminant if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && j == m_equationStore->numberOfSolutions()) { + // Discriminant EvenOddExpressionCell * deltaCell = static_cast(cell); deltaCell->setLayout(m_delta2Layout); } else { @@ -156,10 +158,14 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, char bufferSymbol[Equation::k_maxVariableSize+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); break; default: - int length = strlcpy(bufferSymbol, m_equationStore->variableAtIndex(j), Equation::k_maxVariableSize); + /* 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); bufferSymbol[length++] = j+'0'; bufferSymbol[2] = 0; break; @@ -167,6 +173,7 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, symbolCell->setText(bufferSymbol); } } else { + // Value of the variable or discriminant if (m_equationStore->type() == EquationStore::Type::Monovariable) { EvenOddBufferTextCell * valueCell = static_cast(cell); char bufferValue[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];