equation.cpp
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "equation.h"
using namespace Poincare;
namespace Solver {
Equation::Equation() :
Shared::ExpressionModel(),
m_standardForm(nullptr)
{
}
Equation& Equation::operator=(const Equation& other) {
Shared::ExpressionModel::operator=(other);
return *this;
}
Equation::~Equation() {
tidyStandardForm();
}
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();
if (m_standardForm) {
delete m_standardForm;
m_standardForm = nullptr;
}
}
Expression * Equation::standardForm(Context * context) const {
if (m_standardForm == nullptr) {
Expression * e = expression(context);
if (e->type() == Expression::Type::Equal) {
m_standardForm = static_cast<const Equal *>(e)->standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
} else if (e->type() == Expression::Type::Rational && static_cast<Rational *>(e)->isOne()) {
// The equality was reduced which means the equality was always true.
m_standardForm = new Rational(0);
} else {
// The equality has an undefined operand
assert(e->type() == Expression::Type::Undefined);
}
}
return m_standardForm;
}
void Equation::tidyStandardForm() {
if (m_standardForm) {
delete m_standardForm;
m_standardForm = nullptr;
}
}
}