diff --git a/poincare/include/poincare/nth_root_layout.h b/poincare/include/poincare/nth_root_layout.h index 5eb5b97c0..2af308d5b 100644 --- a/poincare/include/poincare/nth_root_layout.h +++ b/poincare/include/poincare/nth_root_layout.h @@ -19,6 +19,8 @@ public: m_hasIndex(hasIndex) {} + bool isSquareRoot() const; + // Layout Type type() const override { return Type::NthRootLayout; } diff --git a/poincare/src/nth_root_layout.cpp b/poincare/src/nth_root_layout.cpp index ac4a9e147..b04f8168a 100644 --- a/poincare/src/nth_root_layout.cpp +++ b/poincare/src/nth_root_layout.cpp @@ -21,6 +21,17 @@ const uint8_t radixPixel[NthRootLayoutNode::k_leftRadixHeight][NthRootLayoutNode {0xFF, 0xFF, 0xFF, 0xFF, 0xCB} }; +bool NthRootLayoutNode::isSquareRoot() const { + if (!m_hasIndex) { + return true; + } + assert((const_cast(this))->indexLayout() != nullptr); + if ((const_cast(this))->indexLayout()->isEmpty()) { + return true; + } + return false; +} + void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { if (cursor->layoutNode() == radicandLayout() && cursor->position() == LayoutCursor::Position::Left) @@ -149,17 +160,13 @@ void NthRootLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { } int NthRootLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - if (m_hasIndex) { - assert((const_cast(this))->indexLayout()); - if ((const_cast(this))->indexLayout()->isEmpty()) { - // Case: root(x,empty): Write "'SquareRootSymbol'('radicandLayout')" - return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SquareRoot::s_functionHelper.name(), true, 0); - } - // Case: root(x,n) - return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, NthRoot::s_functionHelper.name(), true); + if (isSquareRoot()) { + /* Case: squareRoot(x) or root(x,empty): + * Write "SquareRootSymbol(radicandLayout) */ + return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SquareRoot::s_functionHelper.name(), true, 0); } - // Case: squareRoot(x) - return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SquareRoot::s_functionHelper.name(), true); + // Case: root(x,n) + return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, NthRoot::s_functionHelper.name(), true); } KDSize NthRootLayoutNode::computeSize() {