mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
#include "equation.h"
|
|
|
|
#include <poincare/equal.h>
|
|
#include <poincare/undefined.h>
|
|
#include <poincare/rational.h>
|
|
|
|
using namespace Poincare;
|
|
|
|
namespace Solver {
|
|
|
|
Equation::Equation() :
|
|
Shared::ExpressionModel(),
|
|
m_standardForm()
|
|
{
|
|
}
|
|
|
|
void Equation::setContent(const char * c) {
|
|
/* ExpressionModel::setContent takes care of tidying m_expression and m_layout. */
|
|
tidyStandardForm();
|
|
ExpressionModel::setContent(c);
|
|
}
|
|
|
|
void Equation::tidy() {
|
|
ExpressionModel::tidy();
|
|
tidyStandardForm();
|
|
}
|
|
|
|
Expression Equation::standardForm(Context * context) const {
|
|
if (m_standardForm.isUninitialized()) {
|
|
const Expression e = expression(context);
|
|
if (e.recursivelyMatches([](const Expression e, Context & context) { return e.type() == ExpressionNode::Type::Undefined || e.type() == ExpressionNode::Type::Infinity || Expression::IsMatrix(e, context); }, *context)) {
|
|
m_standardForm = Undefined();
|
|
return m_standardForm;
|
|
}
|
|
if (e.type() == ExpressionNode::Type::Equal) {
|
|
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
|
|
} else {
|
|
assert(e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne());
|
|
// The equality was reduced which means the equality was always true.
|
|
m_standardForm = Rational(0);
|
|
}
|
|
}
|
|
return m_standardForm;
|
|
}
|
|
|
|
void Equation::tidyStandardForm() {
|
|
// Free the pool of the m_standardForm
|
|
m_standardForm = Expression();
|
|
}
|
|
|
|
}
|