[poincare/nth_root_layout] isSquareRoot

This commit is contained in:
Léa Saviot
2019-10-01 11:53:47 +02:00
parent a233b02623
commit 463b44f055
2 changed files with 19 additions and 10 deletions

View File

@@ -19,6 +19,8 @@ public:
m_hasIndex(hasIndex)
{}
bool isSquareRoot() const;
// Layout
Type type() const override { return Type::NthRootLayout; }

View File

@@ -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<NthRootLayoutNode *>(this))->indexLayout() != nullptr);
if ((const_cast<NthRootLayoutNode *>(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<NthRootLayoutNode *>(this))->indexLayout());
if ((const_cast<NthRootLayoutNode *>(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() {