[solver] Fix Equation with new Poincare APi

This commit is contained in:
Émilie Feral
2018-09-06 14:06:21 +02:00
parent eeaea93468
commit f326f16ffb
4 changed files with 21 additions and 26 deletions

View File

@@ -6,7 +6,7 @@ namespace Solver {
Equation::Equation() :
Shared::ExpressionModel(),
m_standardForm(nullptr)
m_standardForm()
{
}
@@ -27,33 +27,28 @@ void Equation::setContent(const char * c) {
void Equation::tidy() {
ExpressionModel::tidy();
if (m_standardForm) {
delete m_standardForm;
m_standardForm = nullptr;
}
tidyStandardForm();
}
Expression * Equation::standardForm(Context * context) const {
if (m_standardForm == nullptr) {
Expression * e = expression(context);
if (e->type() == ExpressionNode::Type::Equal) {
m_standardForm = static_cast<const Equal *>(e)->standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
} else if (e->type() == ExpressionNode::Type::Rational && static_cast<Rational *>(e)->isOne()) {
Expression Equation::standardForm(Context * context) const {
if (m_standardForm.isUninitialized()) {
const Expression e = expression(context);
if (e.type() == ExpressionNode::Type::Equal) {
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
} else if (e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne()) {
// The equality was reduced which means the equality was always true.
m_standardForm = RationalReference(0);
m_standardForm = Rational(0);
} else {
// The equality has an undefined operand
assert(e->type() == ExpressionNode::Type::Undefined);
assert(e.type() == ExpressionNode::Type::Undefined);
}
}
return m_standardForm;
}
void Equation::tidyStandardForm() {
if (m_standardForm) {
delete m_standardForm;
m_standardForm = nullptr;
}
// Free the pool of the m_standardForm
m_standardForm = Expression();
}
}