[poincare] Add Parentheses around conjugate expression to easen reading:

conj(2+i)*2 --> (conj(2+i))*2
This commit is contained in:
Émilie Feral
2019-07-26 16:51:36 +02:00
parent 5900dcae0e
commit c08d7a4733
3 changed files with 9 additions and 0 deletions

View File

@@ -35,6 +35,9 @@ bool AdditionNode::childNeedsUserParentheses(const Expression & child) const {
&& child.node() != childAtIndex(0)) {
return true;
}
if (child.type() == Type::Conjugate) {
return childNeedsUserParentheses(child.childAtIndex(0));
}
return false;
}

View File

@@ -75,6 +75,9 @@ bool MultiplicationNode::childNeedsUserParentheses(const Expression & child) con
}
return true;
}
if (child.type() == Type::Conjugate) {
return childNeedsUserParentheses(child.childAtIndex(0));
}
Type types[] = {Type::Subtraction, Type::Addition};
return child.isOfType(types, 2);
}

View File

@@ -30,6 +30,9 @@ bool SubtractionNode::childNeedsUserParentheses(const Expression & child) const
if (child.isNumber() && static_cast<const Number &>(child).sign() == Sign::Negative) {
return true;
}
if (child.type() == Type::Conjugate) {
return childNeedsUserParentheses(child.childAtIndex(0));
}
Type types[] = {Type::Subtraction, Type::Opposite, Type::Addition};
return child.isOfType(types, 3);
}