mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[solver] Avoid displaying 17 = 17 in solutions controller: test for
layout equality
This commit is contained in:
@@ -40,11 +40,6 @@ Poincare::ExpressionLayout * EquationStore::exactSolutionLayoutAtIndex(int i, bo
|
||||
}
|
||||
}
|
||||
|
||||
bool EquationStore::equalSignBetweenExactSolutionAtIndex(int i) {
|
||||
assert(m_type != Type::Monovariable && i >= 0 && (i < m_numberOfSolutions || (i == m_numberOfSolutions && m_type == Type::PolynomialMonovariable)));
|
||||
return m_exactSolutionEquality[i];
|
||||
}
|
||||
|
||||
double EquationStore::intervalBound(int index) const {
|
||||
assert(m_type == Type::Monovariable && index >= 0 && index < 2);
|
||||
return m_intervalApproximateSolutions[index];
|
||||
@@ -161,7 +156,16 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
m_exactSolutionExactLayouts[i] = exactSolutions[i]->createLayout();
|
||||
Expression * approximate = exactSolutions[i]->approximate<double>(*context);
|
||||
m_exactSolutionApproximateLayouts[i] = approximate->createLayout();
|
||||
m_exactSolutionEquality[i] = exactSolutions[i]->isEqualToItsApproximationLayout(approximate, Shared::ExpressionModel::k_expressionBufferSize, Preferences::sharedPreferences()->numberOfSignificantDigits(), *context);
|
||||
/* Check for identity between exact and approximate layouts */
|
||||
char exactBuffer[Shared::ExpressionModel::k_expressionBufferSize];
|
||||
char approximateBuffer[Shared::ExpressionModel::k_expressionBufferSize];
|
||||
m_exactSolutionExactLayouts[i]->writeTextInBuffer(exactBuffer, Shared::ExpressionModel::k_expressionBufferSize, Preferences::sharedPreferences()->numberOfSignificantDigits());
|
||||
m_exactSolutionApproximateLayouts[i]->writeTextInBuffer(approximateBuffer, Shared::ExpressionModel::k_expressionBufferSize, Preferences::sharedPreferences()->numberOfSignificantDigits());
|
||||
m_exactSolutionIdentity[i] = strcmp(exactBuffer, approximateBuffer) == 0;
|
||||
/* Check for equality between exact and approximate layouts */
|
||||
if (!m_exactSolutionIdentity[i]) {
|
||||
m_exactSolutionEquality[i] = exactSolutions[i]->isEqualToItsApproximationLayout(approximate, Shared::ExpressionModel::k_expressionBufferSize, Preferences::sharedPreferences()->numberOfSignificantDigits(), *context);
|
||||
}
|
||||
delete approximate;
|
||||
delete exactSolutions[i];
|
||||
}
|
||||
|
||||
@@ -38,7 +38,14 @@ public:
|
||||
return m_numberOfSolutions;
|
||||
}
|
||||
Poincare::ExpressionLayout * exactSolutionLayoutAtIndex(int i, bool exactLayout);
|
||||
bool equalSignBetweenExactSolutionAtIndex(int i);
|
||||
bool exactSolutionLayoutsAtIndexAreIdentical(int i) {
|
||||
assert(m_type != Type::Monovariable && i >= 0 && (i < m_numberOfSolutions || (i == m_numberOfSolutions && m_type == Type::PolynomialMonovariable)));
|
||||
return m_exactSolutionIdentity[i];
|
||||
}
|
||||
bool exactSolutionLayoutsAtIndexAreEqual(int i) {
|
||||
assert(m_type != Type::Monovariable && i >= 0 && (i < m_numberOfSolutions || (i == m_numberOfSolutions && m_type == Type::PolynomialMonovariable)));
|
||||
return m_exactSolutionEquality[i];
|
||||
}
|
||||
double intervalBound(int index) const;
|
||||
void setIntervalBound(int index, double value);
|
||||
double approximateSolutionAtIndex(int i);
|
||||
@@ -67,6 +74,7 @@ private:
|
||||
int m_numberOfSolutions;
|
||||
Poincare::ExpressionLayout * m_exactSolutionExactLayouts[k_maxNumberOfApproximateSolutions];
|
||||
Poincare::ExpressionLayout * m_exactSolutionApproximateLayouts[k_maxNumberOfExactSolutions];
|
||||
bool m_exactSolutionIdentity[k_maxNumberOfExactSolutions];
|
||||
bool m_exactSolutionEquality[k_maxNumberOfExactSolutions];
|
||||
double m_intervalApproximateSolutions[2];
|
||||
double m_approximateSolutions[k_maxNumberOfApproximateSolutions];
|
||||
|
||||
@@ -178,9 +178,12 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i,
|
||||
valueCell->setText(bufferValue);
|
||||
} else {
|
||||
Shared::ScrollableExactApproximateExpressionsCell * valueCell = static_cast<ScrollableExactApproximateExpressionsCell *>(cell);
|
||||
Poincare::ExpressionLayout * exactSolutionLayouts[2] = {m_equationStore->exactSolutionLayoutAtIndex(j, false), m_equationStore->exactSolutionLayoutAtIndex(j, true)};
|
||||
Poincare::ExpressionLayout * exactLayout = m_equationStore->exactSolutionLayoutsAtIndexAreIdentical(j) ? nullptr : m_equationStore->exactSolutionLayoutAtIndex(j, true);
|
||||
Poincare::ExpressionLayout * exactSolutionLayouts[2] = {m_equationStore->exactSolutionLayoutAtIndex(j, false), exactLayout};
|
||||
valueCell->setExpressions(exactSolutionLayouts);
|
||||
valueCell->setEqualMessage(m_equationStore->equalSignBetweenExactSolutionAtIndex(j) ? I18n::Message::Equal : I18n::Message::AlmostEqual);
|
||||
if (exactLayout) {
|
||||
valueCell->setEqualMessage(m_equationStore->exactSolutionLayoutsAtIndexAreEqual(j) ? I18n::Message::Equal : I18n::Message::AlmostEqual);
|
||||
}
|
||||
}
|
||||
}
|
||||
evenOddCell->reloadCell();
|
||||
|
||||
Reference in New Issue
Block a user