diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index b18230288..72f888434 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -142,7 +142,7 @@ void Addition::factorizeChildren(Expression * e1, Expression * e2, Context & con } const Rational Addition::RationalFactor(Expression * e) { - if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) { // TODO: change integer for Rational + if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) { return *(static_cast(e->operand(0))); } return Rational(Integer(1)); diff --git a/poincare/src/dynamic_hierarchy.cpp b/poincare/src/dynamic_hierarchy.cpp index 8545169d3..0ae9b32a6 100644 --- a/poincare/src/dynamic_hierarchy.cpp +++ b/poincare/src/dynamic_hierarchy.cpp @@ -84,6 +84,36 @@ void DynamicHierarchy::removeOperand(const Expression * e, bool deleteAfterRemov } } + + + +void DynamicHierarchy::sortOperands(ExpressionOrder order) { + for (int i = numberOfOperands()-1; i > 0; i--) { + bool isSorted = true; + for (int j = 0; j < numberOfOperands()-1; j++) { + if (order(operand(j), operand(j+1)) > 0) { + swapOperands(j, j+1); + isSorted = false; + } + } + if (isSorted) { + return; + } + } +} + +Expression * DynamicHierarchy::squashUnaryHierarchy() { + if (numberOfOperands() == 1) { + assert(parent() != nullptr); + Expression * o = editableOperand(0); + replaceWith(o, true); + return o; + } + return this; +} + +// Private + void DynamicHierarchy::removeOperandAtIndex(int i, bool deleteAfterRemoval) { if (deleteAfterRemoval) { delete m_operands[i]; @@ -130,29 +160,4 @@ int DynamicHierarchy::simplificationOrderGreaterType(const Expression * e) const return 0; } -void DynamicHierarchy::sortOperands(ExpressionOrder order) { - for (int i = numberOfOperands()-1; i > 0; i--) { - bool isSorted = true; - for (int j = 0; j < numberOfOperands()-1; j++) { - if (order(operand(j), operand(j+1)) > 0) { - swapOperands(j, j+1); - isSorted = false; - } - } - if (isSorted) { - return; - } - } -} - -Expression * DynamicHierarchy::squashUnaryHierarchy() { - if (numberOfOperands() == 1) { - assert(parent() != nullptr); - Expression * o = editableOperand(0); - replaceWith(o, true); - return o; - } - return this; -} - }