mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Remove ExceptionNodes and UninitializedNodes
This commit is contained in:
@@ -69,7 +69,6 @@ objs += $(addprefix poincare/src/,\
|
||||
float.o\
|
||||
floor.o\
|
||||
frac_part.o\
|
||||
ghost_node.o\
|
||||
global_context.o\
|
||||
great_common_divisor.o\
|
||||
hyperbolic_arc_cosine.o\
|
||||
@@ -125,10 +124,6 @@ objs += $(addprefix poincare/src/,\
|
||||
tree_by_reference.o\
|
||||
trigonometry.o\
|
||||
undefined.o\
|
||||
uninitialized_evaluation_node.o\
|
||||
uninitialized_expression_node.o\
|
||||
uninitialized_ghost_node.o\
|
||||
uninitialized_layout_node.o\
|
||||
variable_context.o\
|
||||
)
|
||||
|
||||
|
||||
@@ -31,15 +31,12 @@ public:
|
||||
virtual Expression complexToExpression(Preferences::ComplexFormat complexFormat) const = 0;
|
||||
virtual std::complex<T> trace() const = 0;
|
||||
virtual std::complex<T> determinant() const = 0;
|
||||
|
||||
// TreeNode
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Evaluation : public TreeByReference {
|
||||
public:
|
||||
Evaluation();
|
||||
Evaluation() : TreeByReference() {}
|
||||
template<class U> explicit operator U() const {
|
||||
// See Expression::operator T() for explanations on this operator
|
||||
// TODO add assertions to ensure that we cast only to evaluation subclasses
|
||||
@@ -47,7 +44,7 @@ public:
|
||||
return *reinterpret_cast<U *>(const_cast<Evaluation<T> *>(this));
|
||||
}
|
||||
EvaluationNode<T> * node() const {
|
||||
assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost());
|
||||
assert(!TreeByReference::node()->isGhost());
|
||||
return static_cast<EvaluationNode<T> *>(TreeByReference::node());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef POINCARE_EXCEPTION_EVALUATION_NODE_H
|
||||
#define POINCARE_EXCEPTION_EVALUATION_NODE_H
|
||||
|
||||
#include <poincare/exception_node.h>
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/undefined.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template <template<typename> class T, class U>
|
||||
class ExceptionEvaluationNode : public ExceptionNode<T<U> > {
|
||||
public:
|
||||
// EvaluationNode
|
||||
typename EvaluationNode<U>::Type type() const override { return EvaluationNode<U>::Type::Exception; }
|
||||
bool isUndefined() const override { return true; }
|
||||
U toScalar() const override { return NAN; }
|
||||
Expression complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const override { return Undefined(); }
|
||||
std::complex<U> trace() const override { return std::complex<U>(NAN); }
|
||||
std::complex<U> determinant() const override { return std::complex<U>(NAN); }
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(ExceptionEvaluationNode<T, U>); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "ExceptionEvaluation"; }
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef POINCARE_EXCEPTION_EXPRESSION_NODE_H
|
||||
#define POINCARE_EXCEPTION_EXPRESSION_NODE_H
|
||||
|
||||
#include <poincare/exception_node.h>
|
||||
#include <poincare/expression_node.h>
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/char_layout_node.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template <typename T>
|
||||
class ExceptionExpressionNode : public ExceptionNode<T> {
|
||||
public:
|
||||
// ExpressionNode
|
||||
void setChildrenInPlace(Expression other) override {}
|
||||
ExpressionNode::Sign sign() const override { return ExpressionNode::Sign::Unknown; }
|
||||
Expression setSign(ExpressionNode::Sign s, Context & context, Preferences::AngleUnit angleUnit) override { return Expression(this).clone(); }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
|
||||
Evaluation<float> approximate(ExpressionNode::SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return Complex<float>::Undefined(); }
|
||||
Evaluation<double> approximate(ExpressionNode::DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return Complex<double>::Undefined(); }
|
||||
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override {
|
||||
if (bufferSize == 0) {
|
||||
return -1;
|
||||
}
|
||||
return PrintFloat::convertFloatToText<float>(NAN, buffer, bufferSize, numberOfSignificantDigits, floatDisplayMode);
|
||||
}
|
||||
|
||||
LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { assert(false); return CharLayoutRef('a'); } //TODO ?
|
||||
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override { return Expression(this).clone(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
#ifndef POINCARE_EXCEPTION_LAYOUT_NODE_H
|
||||
#define POINCARE_EXCEPTION_LAYOUT_NODE_H
|
||||
|
||||
#include <poincare/exception_node.h>
|
||||
#include <poincare/layout_node.h>
|
||||
#include <poincare/layout_reference.h>
|
||||
#include <poincare/layout_cursor.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template <typename T>
|
||||
class ExceptionLayoutNode : public ExceptionNode<T> {
|
||||
public:
|
||||
// LayoutNode
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override {
|
||||
assert(false);
|
||||
return 0;
|
||||
/*
|
||||
int descriptionLength = strlen(description()) + 1;
|
||||
return strlcpy(buffer, description(), bufferSize < descriptionLength ? bufferSize : descriptionLength);
|
||||
*/
|
||||
}
|
||||
|
||||
// Rendering
|
||||
void invalidAllSizesPositionsAndBaselines() override {}
|
||||
|
||||
// Tree navigation
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override {}
|
||||
void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override {}
|
||||
void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override {}
|
||||
void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override {}
|
||||
LayoutCursor equivalentCursor(LayoutCursor * cursor) override { return LayoutCursor(); }
|
||||
|
||||
// Tree modification
|
||||
|
||||
// Collapse
|
||||
bool shouldCollapseSiblingsOnLeft() const override { return false; }
|
||||
bool shouldCollapseSiblingsOnRight() const override { return false; }
|
||||
int leftCollapsingAbsorbingChildIndex() const override { assert(false); return 0; }
|
||||
int rightCollapsingAbsorbingChildIndex() const override { assert(false); return 0; }
|
||||
void didCollapseSiblings(LayoutCursor * cursor) override {}
|
||||
|
||||
//User input
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override {}
|
||||
|
||||
// Other
|
||||
LayoutNode * layoutToPointWhenInserting() override { return this; }
|
||||
bool hasText() const override { return false; }
|
||||
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override { return false; }
|
||||
bool canBeOmittedMultiplicationLeftFactor() const override { return false; }
|
||||
bool canBeOmittedMultiplicationRightFactor() const override { return false; }
|
||||
bool mustHaveLeftSibling() const override { return false; }
|
||||
bool isVerticalOffset() const override { return false; }
|
||||
bool isHorizontal() const override { return false; }
|
||||
bool isLeftParenthesis() const override { return false; }
|
||||
bool isRightParenthesis() const override { return false; }
|
||||
bool isLeftBracket() const override { return false; }
|
||||
bool isRightBracket() const override { return false; }
|
||||
bool isEmpty() const override { return false; }
|
||||
bool isMatrix() const override { return false; }
|
||||
bool hasUpperLeftIndex() const override { return false; }
|
||||
|
||||
bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) override { return false; }
|
||||
bool willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) override { return false; }
|
||||
void willAddSiblingToEmptyChildAtIndex(int childIndex) override {}
|
||||
bool willReplaceChild(LayoutNode * oldChild, LayoutNode * newChild, LayoutCursor * cursor, bool force) override { return false; }
|
||||
void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) override {}
|
||||
bool willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force) override { return false; }
|
||||
void didRemoveChildAtIndex(int index, LayoutCursor * cursor, bool force) override {}
|
||||
|
||||
// TreeNode
|
||||
void incrementNumberOfChildren(int increment = 1) override {}
|
||||
void decrementNumberOfChildren(int decrement = 1) override {}
|
||||
void eraseNumberOfChildren() override {}
|
||||
size_t size() const override { return sizeof(ExceptionLayoutNode<T>); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "ExceptionLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// LayoutNode
|
||||
void moveCursorVertically(LayoutNode::VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override {}
|
||||
KDSize computeSize() override { return KDSizeZero; }
|
||||
KDCoordinate computeBaseline() override { return 0; }
|
||||
KDPoint positionOfChild(LayoutNode * child) override {
|
||||
assert(false);
|
||||
return KDPointZero;
|
||||
}
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef POINCARE_EXCEPTION_NODE_H
|
||||
#define POINCARE_EXCEPTION_NODE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template <typename T>
|
||||
class ExceptionNode : public T {
|
||||
public:
|
||||
using T::T;
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(ExceptionNode<T>); }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -86,7 +86,7 @@ template<typename T>
|
||||
public:
|
||||
static bool isExpression() { return true; }
|
||||
/* Constructor & Destructor */
|
||||
Expression();
|
||||
Expression() : TreeByReference() {}
|
||||
virtual ~Expression() = default;
|
||||
Expression clone() const { TreeByReference c = TreeByReference::clone(); return static_cast<Expression&>(c); }
|
||||
static Expression parse(char const * string);
|
||||
|
||||
@@ -155,8 +155,6 @@ public:
|
||||
ExpressionNode * childAtIndex(int i) const override { return static_cast<ExpressionNode *>(TreeNode::childAtIndex(i)); }
|
||||
virtual void setChildrenInPlace(Expression other);
|
||||
|
||||
// TreeNode
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
protected:
|
||||
/* Hierarchy */
|
||||
ExpressionNode * parent() const override { return static_cast<ExpressionNode *>(TreeNode::parent()); }
|
||||
|
||||
@@ -18,8 +18,6 @@ public:
|
||||
|
||||
// Ghost
|
||||
bool isGhost() const override { return true; }
|
||||
// Uninitialized
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ public:
|
||||
void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override;
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
LayoutNode * layoutToPointWhenInserting() override {
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
return lowerBoundLayout();
|
||||
}
|
||||
LayoutNode * layoutToPointWhenInserting() override { return lowerBoundLayout(); }
|
||||
char XNTChar() const override { return 'x'; }
|
||||
|
||||
// TreeNode
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
virtual bool hasUpperLeftIndex() const { return false; }
|
||||
virtual char XNTChar() const {
|
||||
LayoutNode * p = parent();
|
||||
return p->isUninitialized() ? Ion::Charset::Empty : p->XNTChar();
|
||||
return p == nullptr ? Ion::Charset::Empty : p->XNTChar();
|
||||
}
|
||||
|
||||
// TODO: put private
|
||||
@@ -114,9 +114,6 @@ public:
|
||||
virtual bool willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force);
|
||||
virtual void didRemoveChildAtIndex(int index, LayoutCursor * cursor, bool force) {}
|
||||
|
||||
// TreeNode
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
|
||||
protected:
|
||||
// Tree navigation
|
||||
virtual void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited);
|
||||
|
||||
@@ -18,8 +18,7 @@ public:
|
||||
using TreeByReference::operator==;
|
||||
using TreeByReference::operator!=;
|
||||
|
||||
LayoutReference();
|
||||
|
||||
LayoutReference() : TreeByReference() {}
|
||||
LayoutReference(const LayoutNode * node) :
|
||||
TreeByReference(node) {}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
KDSize adjustedIndexSize();
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
LayoutNode * radicandLayout() { return childAtIndex(0); }
|
||||
LayoutNode * indexLayout() { return m_hasIndex ? childAtIndex(1) : static_cast<LayoutNode *>(uninitializedStaticNode()); }
|
||||
LayoutNode * indexLayout() { return m_hasIndex ? childAtIndex(1) : nullptr; }
|
||||
bool m_hasIndex;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,10 +20,7 @@ public:
|
||||
void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
|
||||
void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override;
|
||||
LayoutNode * layoutToPointWhenInserting() override {
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
return lowerBoundLayout();
|
||||
}
|
||||
LayoutNode * layoutToPointWhenInserting() override { return lowerBoundLayout(); }
|
||||
char XNTChar() const override { return 'n'; }
|
||||
|
||||
// TreeNode
|
||||
|
||||
@@ -41,11 +41,11 @@ public:
|
||||
TreeByReference clone() const;
|
||||
|
||||
int identifier() const { return m_identifier; }
|
||||
TreeNode * node() const { return TreePool::sharedPool()->node(m_identifier); }
|
||||
TreeNode * node() const { assert(m_identifier != TreePool::NoNodeIdentifier); return TreePool::sharedPool()->node(m_identifier); }
|
||||
int nodeRetainCount() const { return node()->retainCount(); }
|
||||
|
||||
bool isGhost() const { return node()->isGhost(); }
|
||||
bool isUninitialized() const { return node()->isUninitialized(); }
|
||||
bool isUninitialized() const { return m_identifier == TreePool::NoNodeIdentifier; }
|
||||
bool isStatic() const { return node()->isStatic(); }
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ protected:
|
||||
assert(node != nullptr);
|
||||
setIdentifierAndRetain(node->identifier());
|
||||
}
|
||||
TreeByReference(int nodeIndentifier = -1) : m_identifier(nodeIndentifier) {}
|
||||
TreeByReference(int nodeIndentifier = TreePool::NoNodeIdentifier) : m_identifier(nodeIndentifier) {}
|
||||
void setIdentifierAndRetain(int newId) {
|
||||
m_identifier = newId;
|
||||
assert(node() != nullptr);
|
||||
|
||||
@@ -32,10 +32,6 @@ public:
|
||||
int identifier() const { return m_identifier; }
|
||||
int retainCount() const { return m_referenceCounter; }
|
||||
|
||||
// Uninitialized node
|
||||
virtual bool isUninitialized() const { return false; }
|
||||
virtual TreeNode * uninitializedStaticNode() const = 0;
|
||||
|
||||
// Ghost
|
||||
virtual bool isGhost() const { return false; }
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef POINCARE_UNINITIALIZED_EVALUATION_NODE_H
|
||||
#define POINCARE_UNINITIALIZED_EVALUATION_NODE_H
|
||||
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/exception_evaluation_node.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* All UninitializedExpressions should be caught so its node methods are
|
||||
* asserted false. */
|
||||
|
||||
template<typename T>
|
||||
class UninitializedEvaluationNode : public ExceptionEvaluationNode<EvaluationNode, T> {
|
||||
public:
|
||||
static UninitializedEvaluationNode<T> * UninitializedEvaluationStaticNode();
|
||||
// TreeNode
|
||||
bool isUninitialized() const override { return true; }
|
||||
size_t size() const override { return sizeof(UninitializedEvaluationNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedEvaluation";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifndef POINCARE_UNINITIALIZED_EXPRESSION_NODE_H
|
||||
#define POINCARE_UNINITIALIZED_EXPRESSION_NODE_H
|
||||
|
||||
#include <poincare/exception_expression_node.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* All UninitializedExpressions should be caught so its node methods are
|
||||
* asserted false. */
|
||||
|
||||
class UninitializedExpressionNode : public ExceptionExpressionNode<ExpressionNode> {
|
||||
public:
|
||||
static UninitializedExpressionNode * UninitializedExpressionStaticNode();
|
||||
static int UninitializedExpressionStaticNodeIdentifier() { return UninitializedExpressionStaticNode()->identifier(); }
|
||||
|
||||
// ExpressionNode
|
||||
void setChildrenInPlace(Expression other) override { assert(false); return ExceptionExpressionNode<ExpressionNode>::setChildrenInPlace(other); }
|
||||
ExpressionNode::Sign sign() const override { assert(false); return ExceptionExpressionNode<ExpressionNode>::sign(); }
|
||||
Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override { assert(false); return ExceptionExpressionNode<ExpressionNode>::setSign(s, context, angleUnit); }
|
||||
|
||||
ExpressionNode::Type type() const override { assert(false); return ExpressionNode::Type::Uninitialized; }
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override {
|
||||
assert(false);
|
||||
return ExceptionExpressionNode<ExpressionNode>::serialize(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits);
|
||||
}
|
||||
LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { assert(false); return ExceptionExpressionNode<ExpressionNode>::createLayout(floatDisplayMode, numberOfSignificantDigits); }
|
||||
|
||||
// TreeNode
|
||||
bool isUninitialized() const override { return true; }
|
||||
size_t size() const override { return sizeof(UninitializedExpressionNode); }
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override { assert(false); return ExceptionExpressionNode<ExpressionNode>::denominator(context, angleUnit); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedExpression";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef POINCARE_UNINITIALIZED_GHOST_NODE_H
|
||||
#define POINCARE_UNINITIALIZED_GHOST_NODE_H
|
||||
|
||||
#include <poincare/exception_node.h>
|
||||
#include <poincare/ghost_node.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class UninitializedGhostNode : public ExceptionNode<GhostNode> {
|
||||
public:
|
||||
static UninitializedGhostNode * UninitializedGhostStaticNode();
|
||||
|
||||
// TreeNode
|
||||
bool isUninitialized() const override { return true; }
|
||||
size_t size() const override { return sizeof(UninitializedGhostNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedGhost";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,85 +0,0 @@
|
||||
#ifndef POINCARE_UNINITIALIZED_LAYOUT_NODE_H
|
||||
#define POINCARE_UNINITIALIZED_LAYOUT_NODE_H
|
||||
|
||||
#include <poincare/exception_layout_node.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* All UninitializedExpressions should be caught so its node methods are
|
||||
* asserted false. */
|
||||
|
||||
class UninitializedLayoutNode : public ExceptionLayoutNode<LayoutNode> {
|
||||
public:
|
||||
static UninitializedLayoutNode * UninitializedLayoutStaticNode();
|
||||
|
||||
// LayoutNode
|
||||
// Rendering
|
||||
void invalidAllSizesPositionsAndBaselines() override { assert(false); ExceptionLayoutNode<LayoutNode>::invalidAllSizesPositionsAndBaselines(); }
|
||||
|
||||
// Tree navigation
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); ExceptionLayoutNode<LayoutNode>::moveCursorLeft(cursor, shouldRecomputeLayout); }
|
||||
void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); ExceptionLayoutNode<LayoutNode>::moveCursorRight(cursor, shouldRecomputeLayout); }
|
||||
void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override { assert(false); ExceptionLayoutNode<LayoutNode>::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); }
|
||||
void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override { assert(false); ExceptionLayoutNode<LayoutNode>::moveCursorDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); }
|
||||
LayoutCursor equivalentCursor(LayoutCursor * cursor) override { assert(false); return ExceptionLayoutNode<LayoutNode>::equivalentCursor(cursor); }
|
||||
|
||||
// Tree modification
|
||||
|
||||
// Collapse
|
||||
bool shouldCollapseSiblingsOnLeft() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::shouldCollapseSiblingsOnLeft(); }
|
||||
bool shouldCollapseSiblingsOnRight() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::shouldCollapseSiblingsOnRight(); }
|
||||
void didCollapseSiblings(LayoutCursor * cursor) override { assert(false); ExceptionLayoutNode<LayoutNode>::didCollapseSiblings(cursor);}
|
||||
|
||||
//User input
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override { assert(false); ExceptionLayoutNode<LayoutNode>::deleteBeforeCursor(cursor);}
|
||||
|
||||
// Other
|
||||
LayoutNode * layoutToPointWhenInserting() override { assert(false); return ExceptionLayoutNode<LayoutNode>::layoutToPointWhenInserting(); }
|
||||
bool hasText() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::hasText(); }
|
||||
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isCollapsable(numberOfOpenParenthesis, goingLeft); }
|
||||
bool canBeOmittedMultiplicationLeftFactor() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::canBeOmittedMultiplicationLeftFactor(); }
|
||||
bool canBeOmittedMultiplicationRightFactor() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::canBeOmittedMultiplicationRightFactor(); }
|
||||
bool mustHaveLeftSibling() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::mustHaveLeftSibling(); }
|
||||
bool isVerticalOffset() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isVerticalOffset(); }
|
||||
bool isHorizontal() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isHorizontal(); }
|
||||
bool isLeftParenthesis() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isLeftParenthesis(); }
|
||||
bool isRightParenthesis() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isRightParenthesis(); }
|
||||
bool isLeftBracket() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isLeftBracket(); }
|
||||
bool isRightBracket() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isRightBracket(); }
|
||||
bool isEmpty() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isEmpty(); }
|
||||
bool isMatrix() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::isMatrix(); }
|
||||
bool hasUpperLeftIndex() const override { assert(false); return ExceptionLayoutNode<LayoutNode>::hasUpperLeftIndex(); }
|
||||
|
||||
bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) override { assert(false); return ExceptionLayoutNode<LayoutNode>::willAddChildAtIndex(l, index, currentNumberOfChildren, cursor); }
|
||||
bool willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) override { assert(false); return ExceptionLayoutNode<LayoutNode>::willAddSibling(cursor, sibling, moveCursor); }
|
||||
void willAddSiblingToEmptyChildAtIndex(int childIndex) override { assert(false); return ExceptionLayoutNode<LayoutNode>::willAddSiblingToEmptyChildAtIndex(childIndex); }
|
||||
bool willReplaceChild(LayoutNode * oldChild, LayoutNode * newChild, LayoutCursor * cursor, bool force) override { assert(false); return ExceptionLayoutNode<LayoutNode>::willReplaceChild(oldChild, newChild, cursor, force); }
|
||||
void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) override { assert(false); return ExceptionLayoutNode<LayoutNode>::didReplaceChildAtIndex(index, cursor, force); }
|
||||
bool willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force) override { assert(false); return ExceptionLayoutNode<LayoutNode>::willRemoveChild(l, cursor, force); }
|
||||
void didRemoveChildAtIndex(int index, LayoutCursor * cursor, bool force) override { assert(false); return ExceptionLayoutNode<LayoutNode>::didRemoveChildAtIndex(index, cursor, force); }
|
||||
|
||||
// TreeNode
|
||||
bool isUninitialized() const override { return true; }
|
||||
size_t size() const override { return sizeof(UninitializedLayoutNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// LayoutNode
|
||||
void moveCursorVertically(LayoutNode::VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override {
|
||||
assert(false);
|
||||
return ExceptionLayoutNode<LayoutNode>::moveCursorVertically(direction, cursor, shouldRecomputeLayout, equivalentPositionVisited);
|
||||
}
|
||||
KDCoordinate computeBaseline() override { assert(false); return ExceptionLayoutNode<LayoutNode>::computeBaseline(); }
|
||||
|
||||
private:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override { assert(false); ExceptionLayoutNode<LayoutNode>::render(ctx, p, expressionColor, backgroundColor); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,14 +21,13 @@ void BinomialCoefficientLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool *
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Go to the kLayout.
|
||||
assert(!kLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(kLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Left. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -46,14 +45,13 @@ void BinomialCoefficientLayoutNode::moveCursorRight(LayoutCursor * cursor, bool
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Go Left of the nLayout.
|
||||
assert(!nLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(nLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ void BracketLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecom
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
// Case: Left. Ask the parent.
|
||||
LayoutNode * parentLayout = parent();
|
||||
if (!parentLayout->isUninitialized()) {
|
||||
if (parentLayout != nullptr) {
|
||||
parentLayout->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ void BracketLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
// Case: Right. Ask the parent.
|
||||
LayoutNode * parentLayout = parent();
|
||||
if (!parentLayout->isUninitialized()) {
|
||||
if (parentLayout != nullptr) {
|
||||
parentLayout->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ void BracketLayoutNode::invalidAllSizesPositionsAndBaselines() {
|
||||
|
||||
KDCoordinate BracketLayoutNode::computeBaseline() {
|
||||
LayoutNode * parentLayout = parent();
|
||||
assert(!parentLayout->isUninitialized());
|
||||
assert(parentLayout != nullptr);
|
||||
int idxInParent = parentLayout->indexOfChild(this);
|
||||
int numberOfSiblings = parentLayout->numberOfChildren();
|
||||
if (((isLeftParenthesis() || isLeftBracket()) && idxInParent == numberOfSiblings - 1)
|
||||
@@ -99,7 +99,7 @@ KDCoordinate BracketLayoutNode::childHeight() {
|
||||
|
||||
KDCoordinate BracketLayoutNode::computeChildHeight() {
|
||||
LayoutNode * parentLayout = parent();
|
||||
assert(!parentLayout->isUninitialized());
|
||||
assert(parentLayout != nullptr);
|
||||
KDCoordinate result = Metric::MinimalBracketAndParenthesisHeight;
|
||||
int idxInParent = parentLayout->indexOfChild(this);
|
||||
int numberOfSiblings = parentLayout->numberOfChildren();
|
||||
|
||||
@@ -23,8 +23,7 @@ void BracketPairLayoutNode::RenderWithChildSize(KDSize childSize, KDContext * ct
|
||||
}
|
||||
|
||||
void BracketPairLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!childLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == childLayout()
|
||||
if (cursor->layoutNode() == childLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left of the operand. Go Left of the brackets.
|
||||
@@ -34,21 +33,19 @@ void BracketPairLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldR
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right of the brackets. Go Right of the operand.
|
||||
assert(!childLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(childLayout());
|
||||
return;
|
||||
}
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
// Case: Left of the brackets. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!childLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == childLayout()
|
||||
if (cursor->layoutNode() == childLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
// Case: Right of the operand. Go Right of the brackets.
|
||||
@@ -58,14 +55,13 @@ void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * should
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left of the brackets. Go Left of the operand.
|
||||
assert(!childLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(childLayout());
|
||||
return;
|
||||
}
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
// Case: Right of the brackets. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ void CharLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomput
|
||||
return;
|
||||
}
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ void CharLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecompu
|
||||
return;
|
||||
}
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@ namespace Poincare {
|
||||
|
||||
static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
|
||||
|
||||
|
||||
// TODO remove nullptr in the code?
|
||||
KDCoordinate CondensedSumLayoutNode::computeBaseline() {
|
||||
KDSize superscriptSize = superscriptLayout()->isUninitialized() ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
return baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->layoutSize().height()/2);
|
||||
}
|
||||
|
||||
KDSize CondensedSumLayoutNode::computeSize() {
|
||||
KDSize baseSize = baseLayout()->layoutSize();
|
||||
KDSize subscriptSize = subscriptLayout()->layoutSize();
|
||||
KDSize superscriptSize = superscriptLayout()->isUninitialized() ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
KDCoordinate sizeWidth = baseSize.width() + max(subscriptSize.width(), superscriptSize.width());
|
||||
KDCoordinate sizeHeight = max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height());
|
||||
return KDSize(sizeWidth, sizeHeight);
|
||||
@@ -24,7 +26,7 @@ KDPoint CondensedSumLayoutNode::positionOfChild(LayoutNode * child) {
|
||||
KDCoordinate x = 0;
|
||||
KDCoordinate y = 0;
|
||||
KDSize baseSize = baseLayout()->layoutSize();
|
||||
KDSize superscriptSize = superscriptLayout()->isUninitialized() ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
if (child == baseLayout()) {
|
||||
y = max(0, superscriptSize.height() - baseSize.height()/2);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!childLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == childLayout()
|
||||
if (cursor->layoutNode() == childLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left of the operand. Move Left.
|
||||
@@ -18,22 +17,20 @@ void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRec
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Go to the operand.
|
||||
assert(!childLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(childLayout());
|
||||
return;
|
||||
}
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
// Case: Left. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void ConjugateLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
// Case: Right of the operand. Move Right.
|
||||
if (!childLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == childLayout()
|
||||
if (cursor->layoutNode() == childLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
cursor->setLayoutNode(this);
|
||||
@@ -42,14 +39,13 @@ void ConjugateLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRe
|
||||
assert(cursor->layoutNode() == this);
|
||||
// Case: Left. Go to the operand.
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
assert(!childLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(childLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Poincare {
|
||||
void EmptyLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) {
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
return p->deleteBeforeCursor(cursor);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ void EmptyLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecompu
|
||||
assert(cursor->layoutNode() == this);
|
||||
// Ask the parent.
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
p->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ void EmptyLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomp
|
||||
assert(cursor->layoutNode() == this);
|
||||
// Ask the parent.
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
p->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling
|
||||
/* The parent is a MatrixLayout, and the current empty row or column is
|
||||
* being filled in, so add a new empty row or column. */
|
||||
LayoutNode * parentNode = parent();
|
||||
assert(!parentNode->isUninitialized());
|
||||
assert(parentNode != nullptr);
|
||||
parentNode->willAddSiblingToEmptyChildAtIndex(parentNode->indexOfChild(this));
|
||||
// WARNING: Do not use previous node pointers afterwards.
|
||||
}
|
||||
|
||||
@@ -1,26 +1,13 @@
|
||||
#include <poincare/evaluation.h>
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/uninitialized_evaluation_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template<typename T>
|
||||
TreeNode * EvaluationNode<T>::uninitializedStaticNode() const {
|
||||
return Evaluation<T>().node();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Evaluation<T>::Evaluation() : Evaluation<T>(UninitializedEvaluationNode<T>::UninitializedEvaluationStaticNode()) {}
|
||||
|
||||
template<typename T>
|
||||
Expression Evaluation<T>::complexToExpression(Preferences::ComplexFormat complexFormat) const {
|
||||
return node()->complexToExpression(complexFormat);
|
||||
}
|
||||
|
||||
template TreeNode * EvaluationNode<float>::uninitializedStaticNode() const;
|
||||
template TreeNode * EvaluationNode<double>::uninitializedStaticNode() const;
|
||||
template Evaluation<float>::Evaluation();
|
||||
template Evaluation<double>::Evaluation();
|
||||
template Expression Evaluation<float>::complexToExpression(Preferences::ComplexFormat) const;
|
||||
template Expression Evaluation<double>::complexToExpression(Preferences::ComplexFormat) const;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/uninitialized_expression_node.h>
|
||||
#include <poincare/variable_context.h>
|
||||
#include <ion.h>
|
||||
#include <cmath>
|
||||
@@ -21,7 +20,6 @@ namespace Poincare {
|
||||
#include <stdio.h>
|
||||
|
||||
/* Constructor & Destructor */
|
||||
Expression::Expression() : Expression(UninitializedExpressionNode::UninitializedExpressionStaticNodeIdentifier()) {}
|
||||
|
||||
Expression Expression::parse(char const * string) {
|
||||
if (string[0] == 0) {
|
||||
|
||||
@@ -109,10 +109,6 @@ void ExpressionNode::setChildrenInPlace(Expression other) {
|
||||
Expression(this).defaultSetChildrenInPlace(other);
|
||||
}
|
||||
|
||||
TreeNode * ExpressionNode::uninitializedStaticNode() const {
|
||||
return Expression().node();
|
||||
}
|
||||
|
||||
Expression ExpressionNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
return Expression();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ?
|
||||
|
||||
void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Left
|
||||
&& ((!numeratorLayout()->isUninitialized() && cursor->layoutNode() == numeratorLayout())
|
||||
|| (!denominatorLayout()->isUninitialized() && cursor->layoutNode() == denominatorLayout())))
|
||||
&& (cursor->layoutNode() == numeratorLayout()
|
||||
|| cursor->layoutNode() == denominatorLayout()))
|
||||
{
|
||||
// Case: Left of the numerator or the denominator. Go Left of the fraction.
|
||||
cursor->setLayoutNode(this);
|
||||
@@ -23,7 +23,6 @@ void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->layoutNode() == this);
|
||||
// Case: Right. Go to the denominator.
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
assert(!denominatorLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(denominatorLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
@@ -31,15 +30,15 @@ void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
// Case: Left. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void FractionLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Right
|
||||
&& ((!numeratorLayout()->isUninitialized() && cursor->layoutNode() == numeratorLayout())
|
||||
|| (!denominatorLayout()->isUninitialized() && cursor->layoutNode() == denominatorLayout())))
|
||||
&& (cursor->layoutNode() == numeratorLayout()
|
||||
|| cursor->layoutNode() == denominatorLayout()))
|
||||
{
|
||||
// Case: Right of the numerator or the denominator. Go Right of the fraction.
|
||||
cursor->setLayoutNode(this);
|
||||
@@ -48,28 +47,25 @@ void FractionLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Go to the numerator.
|
||||
assert(!numeratorLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(numeratorLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void FractionLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!denominatorLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(denominatorLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(denominatorLayout(), true)) {
|
||||
// If the cursor is inside denominator, move it to the numerator.
|
||||
assert(!numeratorLayout()->isUninitialized());
|
||||
numeratorLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
if (cursor->layoutNode() == this) {
|
||||
// If the cursor is Left or Right, move it to the numerator.
|
||||
assert(!numeratorLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(numeratorLayout());
|
||||
return;
|
||||
}
|
||||
@@ -77,15 +73,13 @@ void FractionLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp
|
||||
}
|
||||
|
||||
void FractionLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!numeratorLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(numeratorLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(numeratorLayout(), true)) {
|
||||
// If the cursor is inside numerator, move it to the denominator.
|
||||
assert(!denominatorLayout()->isUninitialized());
|
||||
denominatorLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
if (cursor->layoutNode() == this){
|
||||
// If the cursor is Left or Right, move it to the denominator.
|
||||
assert(!denominatorLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(denominatorLayout());
|
||||
return;
|
||||
}
|
||||
@@ -135,7 +129,7 @@ int FractionLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
|
||||
|
||||
int idxInParent = -1;
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
idxInParent = p->indexOfChild(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <poincare/ghost_node.h>
|
||||
#include <poincare/uninitialized_ghost_node.h>
|
||||
#include <poincare/tree_pool.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
TreeNode * GhostNode::uninitializedStaticNode() const {
|
||||
return UninitializedGhostNode::UninitializedGhostStaticNode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ void GridLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomput
|
||||
// Case: Left. Ask the parent.
|
||||
assert(cursor->layoutNode() == this);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ void GridLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecompu
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->layoutNode() == this);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRe
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
return;
|
||||
@@ -37,7 +37,7 @@ void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRe
|
||||
assert(childIndex >= 0);
|
||||
if (childIndex == 0) {
|
||||
// Case: the child is the leftmost. Ask the parent.
|
||||
if (!parent()->isUninitialized()) {
|
||||
if (parent() != nullptr) {
|
||||
cursor->setLayoutNode(this);
|
||||
return cursor->moveLeft(shouldRecomputeLayout);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldR
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
return;
|
||||
@@ -66,7 +66,7 @@ void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldR
|
||||
if (childrenCount == 0) {
|
||||
// If there are no children, go Right and ask the parent
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
return;
|
||||
@@ -74,7 +74,6 @@ void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldR
|
||||
/* If there is at least one child, set the cursor to the first child and
|
||||
* move it Right */
|
||||
LayoutNode * firstChild = childAtIndex(0);
|
||||
assert(!firstChild->isUninitialized());
|
||||
cursor->setLayoutNode(firstChild);
|
||||
return firstChild->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
@@ -86,7 +85,7 @@ void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldR
|
||||
if (childIndex == numberOfChildren() - 1) {
|
||||
// Case: the child is the rightmost. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
cursor->setLayoutNode(this);
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
@@ -129,7 +128,7 @@ LayoutCursor HorizontalLayoutNode::equivalentCursor(LayoutCursor * cursor) {
|
||||
|
||||
void HorizontalLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) {
|
||||
LayoutNode * p = parent();
|
||||
if (p->isUninitialized()
|
||||
if (p == nullptr
|
||||
&& cursor->layoutNode() == this
|
||||
&& (cursor->position() == LayoutCursor::Position::Left
|
||||
|| numberOfChildren() == 0))
|
||||
@@ -242,7 +241,7 @@ bool HorizontalLayoutNode::willRemoveChild(LayoutNode * l, LayoutCursor * cursor
|
||||
if (!force && numberOfChildren() == 1) {
|
||||
assert(childAtIndex(0) == l);
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
LayoutRef(p).removeChild(HorizontalLayoutRef(this), cursor);
|
||||
// WARNING: Do not call "this" afterwards
|
||||
return false;
|
||||
@@ -288,14 +287,14 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode *
|
||||
/* The old layout was the only horizontal layout child, so if this has a
|
||||
* a parent, replace this with the new empty layout. */
|
||||
LayoutNode * p = parent();
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
thisRef.replaceWith(newChild, cursor);
|
||||
// WARNING: do not call "this" afterwards
|
||||
return false;
|
||||
}
|
||||
/* This is the main horizontal layout, the old child is its only child and
|
||||
* the new child is Empty: remove the old child and delete the new child. */
|
||||
assert(p->isUninitialized());
|
||||
assert(p == nullptr);
|
||||
thisRef.removeChild(oldChild, nullptr);
|
||||
// WARNING: do not call "this" afterwards
|
||||
if (cursor != nullptr) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include <poincare/init.h>
|
||||
#include <poincare/tree_pool.h>
|
||||
#include <poincare/uninitialized_expression_node.h>
|
||||
#include <poincare/uninitialized_ghost_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -9,10 +7,6 @@ void init() {
|
||||
// Create and register the shared static pool
|
||||
static TreePool pool;
|
||||
TreePool::RegisterPool(&pool);
|
||||
|
||||
// Register static nodes
|
||||
pool.registerStaticNode(UninitializedExpressionNode::UninitializedExpressionStaticNode());
|
||||
pool.registerStaticNode(UninitializedGhostNode::UninitializedGhostStaticNode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,19 +25,17 @@ const uint8_t bottomSymbolPixel[IntegralLayoutNode::k_symbolHeight][IntegralLayo
|
||||
|
||||
void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Left
|
||||
&& ((!upperBoundLayout()->isUninitialized() && cursor->layoutNode() == upperBoundLayout())
|
||||
|| (!lowerBoundLayout()->isUninitialized() && cursor->layoutNode() == lowerBoundLayout())))
|
||||
&& (cursor->layoutNode() == upperBoundLayout()
|
||||
|| cursor->layoutNode() == lowerBoundLayout()))
|
||||
{
|
||||
// Case: Left the upper or lower bound. Go Left of the integral.
|
||||
cursor->setLayoutNode(this);
|
||||
return;
|
||||
}
|
||||
if (!integrandLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == integrandLayout()
|
||||
if (cursor->layoutNode() == integrandLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left the integrand. Go Right of the lower bound.
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(lowerBoundLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
@@ -45,7 +43,6 @@ void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right of the integral. Go to the integrand.
|
||||
assert(!integrandLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(integrandLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
@@ -53,24 +50,22 @@ void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
// Case: Left of the brackets. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Right &&
|
||||
((!upperBoundLayout()->isUninitialized() && cursor->layoutNode() == upperBoundLayout())
|
||||
|| (!lowerBoundLayout()->isUninitialized() && cursor->layoutNode() == lowerBoundLayout())))
|
||||
(cursor->layoutNode() == upperBoundLayout()
|
||||
|| cursor->layoutNode() == lowerBoundLayout()))
|
||||
{
|
||||
// Case: Right the upper or lower bound. Go Left of the integrand.
|
||||
assert(!integrandLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(integrandLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
}
|
||||
if (!integrandLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == integrandLayout()
|
||||
if (cursor->layoutNode() == integrandLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
// Case: Right the integrand. Go Right.
|
||||
@@ -81,7 +76,6 @@ void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left of the integral. Go to the upper bound.
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(upperBoundLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
@@ -89,23 +83,19 @@ void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void IntegralLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!lowerBoundLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true)) {
|
||||
// If the cursor is inside the lower bound, move it to the upper bound.
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
if (!integrandLayout()->isUninitialized()
|
||||
&& cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left)))
|
||||
{
|
||||
if (cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left))) {
|
||||
// If the cursor is Left of the integrand, move it to the upper bound.
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
@@ -113,17 +103,13 @@ void IntegralLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp
|
||||
}
|
||||
|
||||
void IntegralLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!upperBoundLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) {
|
||||
// If the cursor is inside the upper bound, move it to the lower bound.
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
// If the cursor is Left of the integrand, move it to the lower bound.
|
||||
if (!integrandLayout()->isUninitialized()
|
||||
&& cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left)))
|
||||
{
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
if (cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left))) {
|
||||
lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ void LayoutNode::draw(KDContext * ctx, KDPoint p, KDColor expressionColor, KDCol
|
||||
|
||||
KDPoint LayoutNode::origin() {
|
||||
LayoutNode * p = parent();
|
||||
if (p->isUninitialized()) {
|
||||
if (p == nullptr) {
|
||||
return absoluteOrigin();
|
||||
} else {
|
||||
return KDPoint(absoluteOrigin().x() - p->absoluteOrigin().x(),
|
||||
@@ -29,7 +29,7 @@ KDPoint LayoutNode::origin() {
|
||||
KDPoint LayoutNode::absoluteOrigin() {
|
||||
LayoutNode * p = parent();
|
||||
if (!m_positioned) {
|
||||
if (!p->isUninitialized()) {
|
||||
if (p != nullptr) {
|
||||
m_frame.setOrigin(p->absoluteOrigin().translatedBy(p->positionOfChild(this)));
|
||||
} else {
|
||||
m_frame.setOrigin(KDPointZero);
|
||||
@@ -83,7 +83,7 @@ void LayoutNode::moveCursorDownInDescendants(LayoutCursor * cursor, bool * shoul
|
||||
|
||||
LayoutCursor LayoutNode::equivalentCursor(LayoutCursor * cursor) {
|
||||
// Only HorizontalLayout may have no parent, and it overloads this method
|
||||
assert(!parent()->isUninitialized());
|
||||
assert(parent() != nullptr);
|
||||
return (cursor->layoutReference().node() == this) ? parent()->equivalentCursor(cursor) : LayoutCursor();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ void LayoutNode::deleteBeforeCursor(LayoutCursor * cursor) {
|
||||
assert(cursor->layoutNode() == this);
|
||||
LayoutNode * p = parent();
|
||||
// Case: this is the pointed layout.
|
||||
if (p->isUninitialized()) {
|
||||
if (p == nullptr) {
|
||||
// Case: No parent. Return.
|
||||
return;
|
||||
}
|
||||
@@ -142,12 +142,6 @@ bool LayoutNode::canBeOmittedMultiplicationRightFactor() const {
|
||||
return isCollapsable(&numberOfOpenParentheses, false) && !isVerticalOffset();
|
||||
}
|
||||
|
||||
// TreeNode
|
||||
|
||||
TreeNode * LayoutNode::uninitializedStaticNode() const {
|
||||
return LayoutReference().node();
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
@@ -165,7 +159,7 @@ void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor
|
||||
}
|
||||
}
|
||||
LayoutNode * p = parent();
|
||||
if (p->isUninitialized()) {
|
||||
if (p == nullptr) {
|
||||
cursor->setLayoutReference(LayoutReference());
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +171,7 @@ void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor
|
||||
}
|
||||
|
||||
void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
LayoutNode * childResult = static_cast<LayoutNode *>(uninitializedStaticNode());
|
||||
LayoutNode * childResult = nullptr;
|
||||
LayoutNode ** childResultPtr = &childResult;
|
||||
LayoutCursor::Position resultPosition = LayoutCursor::Position::Left;
|
||||
/* The distance between the cursor and its next position cannot be greater
|
||||
@@ -188,7 +182,7 @@ void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction,
|
||||
|
||||
// If there is a valid result
|
||||
LayoutRef resultRef(childResult);
|
||||
if (!(*childResultPtr)->isUninitialized()) {
|
||||
if ((*childResultPtr) != nullptr) {
|
||||
*shouldRecomputeLayout = childResult->addGreySquaresToAllMatrixAncestors();
|
||||
// WARNING: Do not use "this" afterwards
|
||||
}
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
#include <poincare/horizontal_layout_node.h>
|
||||
#include <poincare/layout_node.h>
|
||||
#include <poincare/layout_cursor.h>
|
||||
#include <poincare/uninitialized_layout_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
LayoutReference::LayoutReference() : LayoutReference(UninitializedLayoutNode::UninitializedLayoutStaticNode()) {}
|
||||
|
||||
// Cursor
|
||||
LayoutCursor LayoutReference::cursor() const {
|
||||
return LayoutCursor(const_cast<LayoutReference *>(this)->node());
|
||||
|
||||
@@ -49,7 +49,6 @@ void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomp
|
||||
addGreySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
LayoutNode * lastChild = childAtIndex((m_numberOfColumns-1)*(m_numberOfRows-1));
|
||||
assert(!lastChild->isUninitialized());
|
||||
cursor->setLayoutNode(lastChild);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@ const uint8_t radixPixel[NthRootLayoutNode::k_leftRadixHeight][NthRootLayoutNode
|
||||
};
|
||||
|
||||
void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!radicandLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == radicandLayout()
|
||||
if (cursor->layoutNode() == radicandLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left of the radicand. Go the index if any, ir go Left of the root.
|
||||
if (!indexLayout()->isUninitialized()) {
|
||||
if (indexLayout() != nullptr) {
|
||||
cursor->setLayoutNode(indexLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
} else {
|
||||
@@ -33,7 +32,7 @@ void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecom
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!indexLayout()->isUninitialized()
|
||||
if (indexLayout() != nullptr
|
||||
&& cursor->layoutNode() == indexLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
@@ -44,33 +43,30 @@ void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecom
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Go Right of the radicand.
|
||||
assert(!radicandLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(radicandLayout());
|
||||
return;
|
||||
}
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
// Case: Left. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!radicandLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == radicandLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
if (cursor->layoutNode() == radicandLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
// Case: Right of the radicand. Go the Right of the root.
|
||||
cursor->setLayoutNode(this);
|
||||
return;
|
||||
}
|
||||
if (!indexLayout()->isUninitialized()
|
||||
if (indexLayout() != nullptr
|
||||
&& cursor->layoutNode() == indexLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
// Case: Right of the index. Go Left of the integrand.
|
||||
assert(!radicandLayout()->isUninitialized());
|
||||
assert(radicandLayout() != nullptr);
|
||||
cursor->setLayoutNode(radicandLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
@@ -78,10 +74,9 @@ void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Go to the index if there is one, else go to the radicand.
|
||||
if (!indexLayout()->isUninitialized()) {
|
||||
if (indexLayout() != nullptr) {
|
||||
cursor->setLayoutNode(indexLayout());
|
||||
} else {
|
||||
assert(!radicandLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(radicandLayout());
|
||||
}
|
||||
return;
|
||||
@@ -89,14 +84,13 @@ void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
// Case: Right. Ask the parent.
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!indexLayout()->isUninitialized()
|
||||
&& !radicandLayout()->isUninitialized()
|
||||
if (indexLayout() != nullptr
|
||||
&& cursor->isEquivalentTo(LayoutCursor(radicandLayout(), LayoutCursor::Position::Left)))
|
||||
{
|
||||
// If the cursor is Left of the radicand, move it to the index.
|
||||
@@ -104,7 +98,7 @@ void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecompu
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
}
|
||||
if (!indexLayout()->isUninitialized()
|
||||
if (indexLayout() != nullptr
|
||||
&& cursor->layoutNode() == this
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
@@ -117,12 +111,11 @@ void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecompu
|
||||
}
|
||||
|
||||
void NthRootLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!indexLayout()->isUninitialized()
|
||||
if (indexLayout() != nullptr
|
||||
&& cursor->layoutNode()->hasAncestor(indexLayout(), true))
|
||||
{
|
||||
if (cursor->isEquivalentTo(LayoutCursor(indexLayout(), LayoutCursor::Position::Right))) {
|
||||
// If the cursor is Right of the index, move it to the radicand.
|
||||
assert(!radicandLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(radicandLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
@@ -204,7 +197,7 @@ KDSize NthRootLayoutNode::computeSize() {
|
||||
}
|
||||
|
||||
KDCoordinate NthRootLayoutNode::computeBaseline() {
|
||||
if (!indexLayout()->isUninitialized()) {
|
||||
if (indexLayout() != nullptr) {
|
||||
return max(
|
||||
radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin,
|
||||
indexLayout()->layoutSize().height() + k_indexHeight);
|
||||
@@ -220,7 +213,7 @@ KDPoint NthRootLayoutNode::positionOfChild(LayoutNode * child) {
|
||||
if (child == radicandLayout()) {
|
||||
x = indexSize.width() + 2*k_widthMargin + k_radixLineThickness;
|
||||
y = baseline() - radicandLayout()->baseline();
|
||||
} else if (!indexLayout()->isUninitialized() && child == indexLayout()) {
|
||||
} else if (indexLayout() != nullptr && child == indexLayout()) {
|
||||
x = 0;
|
||||
y = baseline() - indexSize.height() - k_indexHeight;
|
||||
} else {
|
||||
@@ -230,7 +223,7 @@ KDPoint NthRootLayoutNode::positionOfChild(LayoutNode * child) {
|
||||
}
|
||||
|
||||
KDSize NthRootLayoutNode::adjustedIndexSize() {
|
||||
return indexLayout()->isUninitialized() ?
|
||||
return indexLayout() == nullptr ?
|
||||
KDSize(k_leftRadixWidth, 0) :
|
||||
KDSize(max(k_leftRadixWidth, indexLayout()->layoutSize().width()), indexLayout()->layoutSize().height());
|
||||
}
|
||||
|
||||
@@ -13,19 +13,17 @@ constexpr char SequenceLayoutNode::k_nEquals[];
|
||||
|
||||
void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Left
|
||||
&& ((!lowerBoundLayout()->isUninitialized() && cursor->layoutNode() == lowerBoundLayout())
|
||||
|| (!upperBoundLayout()->isUninitialized() && cursor->layoutNode() == upperBoundLayout())))
|
||||
&& (cursor->layoutNode() == lowerBoundLayout()
|
||||
|| cursor->layoutNode() == upperBoundLayout()))
|
||||
{
|
||||
// Case: Left of the bounds. Go Left of the sequence.
|
||||
cursor->setLayoutNode(this);
|
||||
return;
|
||||
}
|
||||
if (cursor->position() == LayoutCursor::Position::Left
|
||||
&& !argumentLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == argumentLayout())
|
||||
{
|
||||
// Case: Left of the argument. Go Right of the lower bound.
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(lowerBoundLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
@@ -33,7 +31,6 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Go to the argument and move Left.
|
||||
assert(!argumentLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(argumentLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
@@ -41,24 +38,22 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
// Case: Left. Ask the parent.
|
||||
LayoutNode * parentLayout = parent();
|
||||
if (!parentLayout->isUninitialized()) {
|
||||
if (parentLayout != nullptr) {
|
||||
parentLayout->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (cursor->position() == LayoutCursor::Position::Right
|
||||
&& ((!lowerBoundLayout()->isUninitialized() && cursor->layoutNode() == lowerBoundLayout())
|
||||
|| (!upperBoundLayout()->isUninitialized() && cursor->layoutNode() == upperBoundLayout())))
|
||||
&& (cursor->layoutNode() == lowerBoundLayout()
|
||||
|| cursor->layoutNode() == upperBoundLayout()))
|
||||
{
|
||||
// Case: Right of the bounds. Go Left of the argument.
|
||||
assert(!argumentLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(argumentLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
}
|
||||
if (cursor->position() == LayoutCursor::Position::Right
|
||||
&& !argumentLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == argumentLayout())
|
||||
{
|
||||
// Case: Right of the argument. Go Right.
|
||||
@@ -68,30 +63,25 @@ void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Go to the upper bound
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(upperBoundLayout());
|
||||
return;
|
||||
}
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
// Case: Right. Ask the parent
|
||||
LayoutNode * parentLayout = parent();
|
||||
if (!parentLayout->isUninitialized()) {
|
||||
if (parentLayout != nullptr) {
|
||||
parentLayout->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!lowerBoundLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true)) {
|
||||
// If the cursor is inside the lower bound, move it to the upper bound
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
if (!argumentLayout()->isUninitialized()
|
||||
&& cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left)))
|
||||
{
|
||||
if (cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left))) {
|
||||
// If the cursor is Left of the argument, move it to the upper bound
|
||||
assert(!upperBoundLayout()->isUninitialized());
|
||||
upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
@@ -99,17 +89,13 @@ void SequenceLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp
|
||||
}
|
||||
|
||||
void SequenceLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
if (!upperBoundLayout()->isUninitialized() && cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) {
|
||||
if (cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) {
|
||||
// If the cursor is inside the upper bound, move it to the lower bound
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
// If the cursor is Left of the argument, move it to the lower bound
|
||||
if (!argumentLayout()->isUninitialized()
|
||||
&& cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left)))
|
||||
{
|
||||
assert(!lowerBoundLayout()->isUninitialized());
|
||||
if (cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left))) {
|
||||
lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void TreeNode::rename(int identifier, bool unregisterPreviousIdentifier) {
|
||||
|
||||
TreeNode * TreeNode::parent() const {
|
||||
if (m_parentIdentifier == TreePool::NoNodeIdentifier) {
|
||||
return uninitializedStaticNode();
|
||||
return nullptr;
|
||||
}
|
||||
return TreePool::sharedPool()->node(m_parentIdentifier);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ TreeNode * TreeNode::parent() const {
|
||||
TreeNode * TreeNode::root() {
|
||||
TreeNode * result = this;
|
||||
TreeNode * resultParent = result->parent();
|
||||
while(!resultParent->isUninitialized()) {
|
||||
while(resultParent != nullptr) {
|
||||
result = resultParent;
|
||||
resultParent = result->parent();
|
||||
}
|
||||
@@ -93,7 +93,7 @@ int TreeNode::indexOfChild(const TreeNode * child) const {
|
||||
|
||||
int TreeNode::indexInParent() const {
|
||||
TreeNode * p = parent();
|
||||
if (p->isUninitialized()) {
|
||||
if (p == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
return p->indexOfChild(this);
|
||||
@@ -122,7 +122,7 @@ bool TreeNode::hasAncestor(const TreeNode * node, bool includeSelf) const {
|
||||
|
||||
bool TreeNode::hasSibling(const TreeNode * e) const {
|
||||
TreeNode * p = parent();
|
||||
if (p->isUninitialized()) {
|
||||
if (p == nullptr) {
|
||||
return false;
|
||||
}
|
||||
for (TreeNode * childNode : p->directChildren()) {
|
||||
|
||||
@@ -205,11 +205,11 @@ void TreePool::freePoolFromNode(TreeNode * firstNodeToDiscard) {
|
||||
if (firstNodeToDiscard < last()) {
|
||||
// There should be no tree that continues into the pool zone to discard
|
||||
#if POINCARE_TREE_LOG
|
||||
if (!firstNodeToDiscard->parent()->isUninitialized()) {
|
||||
if (!firstNodeToDiscard->parent() == nullptr) {
|
||||
log();
|
||||
}
|
||||
#endif
|
||||
assert(firstNodeToDiscard->parent()->isUninitialized());
|
||||
assert(firstNodeToDiscard->parent() == nullptr);
|
||||
}
|
||||
TreeNode * currentNode = firstNodeToDiscard;
|
||||
TreeNode * lastNode = last();
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include <poincare/uninitialized_evaluation_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
template<typename T>
|
||||
UninitializedEvaluationNode<T> * UninitializedEvaluationNode<T>::UninitializedEvaluationStaticNode() {
|
||||
static UninitializedEvaluationNode<T> exception;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&exception);
|
||||
return &exception;
|
||||
}
|
||||
|
||||
template UninitializedEvaluationNode<float> * UninitializedEvaluationNode<float>::UninitializedEvaluationStaticNode();
|
||||
template UninitializedEvaluationNode<double> * UninitializedEvaluationNode<double>::UninitializedEvaluationStaticNode();
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <poincare/uninitialized_expression_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
UninitializedExpressionNode * UninitializedExpressionNode::UninitializedExpressionStaticNode() {
|
||||
static UninitializedExpressionNode exception;
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <poincare/uninitialized_ghost_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
UninitializedGhostNode * UninitializedGhostNode::UninitializedGhostStaticNode() {
|
||||
static UninitializedGhostNode exception;
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <poincare/uninitialized_layout_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
UninitializedLayoutNode * UninitializedLayoutNode::UninitializedLayoutStaticNode() {
|
||||
static UninitializedLayoutNode exception;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&exception);
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!indiceLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == indiceLayout()
|
||||
if (cursor->layoutNode() == indiceLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left of the indice. Go Left.
|
||||
@@ -21,21 +20,20 @@ void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shou
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
// Case: Right. Go to the indice.
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
assert(indiceLayout() != nullptr);
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Left. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorLeft(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
void VerticalOffsetLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (!indiceLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == indiceLayout()
|
||||
if (cursor->layoutNode() == indiceLayout()
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
// Case: Right of the indice. Go Right.
|
||||
@@ -45,14 +43,13 @@ void VerticalOffsetLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * sho
|
||||
assert(cursor->layoutNode() == this);
|
||||
if (cursor->position() == LayoutCursor::Position::Left) {
|
||||
// Case: Left. Go to the indice.
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
return;
|
||||
}
|
||||
// Case: Right. Ask the parent.
|
||||
assert(cursor->position() == LayoutCursor::Position::Right);
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
parentNode->moveCursorRight(cursor, shouldRecomputeLayout);
|
||||
}
|
||||
}
|
||||
@@ -62,14 +59,12 @@ void VerticalOffsetLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * should
|
||||
// Case: Superscript.
|
||||
if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Right))) {
|
||||
// Case: Right. Move to the indice.
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
}
|
||||
if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Left))) {
|
||||
// Case: Left. Move to the indice.
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
@@ -78,7 +73,6 @@ void VerticalOffsetLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * should
|
||||
/* Case: Subscript, Left or Right of the indice. Put the cursor at the same
|
||||
* position, pointing this. */
|
||||
if (m_type == Type::Subscript
|
||||
&& !indiceLayout()->isUninitialized()
|
||||
&& (cursor->isEquivalentTo(LayoutCursor(indiceLayout(), LayoutCursor::Position::Left))
|
||||
|| cursor->isEquivalentTo(LayoutCursor(indiceLayout(), LayoutCursor::Position::Right))))
|
||||
{
|
||||
@@ -93,14 +87,12 @@ void VerticalOffsetLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shou
|
||||
// Case: Subscript.
|
||||
if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Right))) {
|
||||
// Case: Right. Move to the indice.
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
}
|
||||
// Case: Left. Move to the indice.
|
||||
if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Left))) {
|
||||
assert(!indiceLayout()->isUninitialized());
|
||||
cursor->setLayoutNode(indiceLayout());
|
||||
cursor->setPosition(LayoutCursor::Position::Left);
|
||||
return;
|
||||
@@ -109,7 +101,6 @@ void VerticalOffsetLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shou
|
||||
/* Case: Superscript, Left or Right of the indice. Put the cursor at the same
|
||||
* position, pointing this. */
|
||||
if (m_type == Type::Superscript
|
||||
&& !indiceLayout()->isUninitialized()
|
||||
&& cursor->layoutNode() == indiceLayout())
|
||||
{
|
||||
cursor->setLayoutNode(this);
|
||||
@@ -190,7 +181,7 @@ int VerticalOffsetLayoutNode::serialize(char * buffer, int bufferSize, Preferenc
|
||||
// Add a multiplication if omitted.
|
||||
int indexInParent = -1;
|
||||
LayoutNode * parentNode = parent();
|
||||
if (!parentNode->isUninitialized()) {
|
||||
if (parentNode != nullptr) {
|
||||
indexInParent = parentNode->indexOfChild(this);
|
||||
}
|
||||
if (indexInParent >= 0 && indexInParent < (parentNode->numberOfChildren() - 1) && parentNode->isHorizontal() && parentNode->childAtIndex(indexInParent + 1)->canBeOmittedMultiplicationRightFactor()) {
|
||||
@@ -206,7 +197,7 @@ KDSize VerticalOffsetLayoutNode::computeSize() {
|
||||
KDCoordinate width = indiceSize.width();
|
||||
if (m_type == Type::Superscript) {
|
||||
LayoutNode * parentNode = parent();
|
||||
assert(!parentNode->isUninitialized());
|
||||
assert(parentNode != nullptr);
|
||||
assert(parentNode->isHorizontal());
|
||||
int idxInParent = parentNode->indexOfChild(this);
|
||||
if (idxInParent < parentNode->numberOfChildren() - 1 && parentNode->childAtIndex(idxInParent + 1)->hasUpperLeftIndex()) {
|
||||
@@ -231,7 +222,6 @@ KDPoint VerticalOffsetLayoutNode::positionOfChild(LayoutNode * child) {
|
||||
return KDPointZero;
|
||||
}
|
||||
assert(m_type == Type::Subscript);
|
||||
assert(!baseLayout()->isUninitialized());
|
||||
return KDPoint(0, baseLayout()->layoutSize().height() - k_indiceHeight);
|
||||
}
|
||||
|
||||
@@ -274,7 +264,7 @@ bool VerticalOffsetLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode
|
||||
|
||||
LayoutNode * VerticalOffsetLayoutNode::baseLayout() {
|
||||
LayoutNode * parentNode = parent();
|
||||
assert(!parentNode->isUninitialized());
|
||||
assert(parentNode != nullptr);
|
||||
assert(parentNode->isHorizontal());
|
||||
int idxInParent = parentNode->indexOfChild(this);
|
||||
assert(idxInParent > 0);
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "blob_node.h"
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
TreeNode * BlobNode::uninitializedStaticNode() const {
|
||||
return UninitializedBlobNode::UninitializedBlobStaticNode();
|
||||
}
|
||||
|
||||
UninitializedBlobNode * UninitializedBlobNode::UninitializedBlobStaticNode() {
|
||||
static UninitializedBlobNode exception;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&exception);
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ namespace Poincare {
|
||||
|
||||
class BlobNode : public TreeNode {
|
||||
public:
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
virtual size_t size() const override { return sizeof(BlobNode); }
|
||||
int data() { return m_data; }
|
||||
void setData(int data) { m_data = data; }
|
||||
@@ -22,20 +21,6 @@ private:
|
||||
int m_data;
|
||||
};
|
||||
|
||||
class UninitializedBlobNode : public BlobNode {
|
||||
public:
|
||||
static UninitializedBlobNode * UninitializedBlobStaticNode();
|
||||
|
||||
size_t size() const override { return sizeof(UninitializedBlobNode); }
|
||||
bool isUninitialized() const override { return true; }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedBlob";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
class BlobByReference : public TreeByReference {
|
||||
public:
|
||||
BlobByReference(int data = 0) : TreeByReference(TreePool::sharedPool()->createTreeNode<BlobNode>()) {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "pair_node.h"
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
TreeNode * PairNode::uninitializedStaticNode() const {
|
||||
return UninitializedPairNode::UninitializedPairStaticNode();
|
||||
}
|
||||
|
||||
UninitializedPairNode * UninitializedPairNode::UninitializedPairStaticNode() {
|
||||
static UninitializedPairNode exception;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&exception);
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,6 @@ namespace Poincare {
|
||||
|
||||
class PairNode : public TreeNode {
|
||||
public:
|
||||
TreeNode * uninitializedStaticNode() const override;
|
||||
virtual size_t size() const override { return sizeof(PairNode); }
|
||||
virtual int numberOfChildren() const override { return 2; }
|
||||
#if POINCARE_TREE_LOG
|
||||
@@ -18,20 +17,6 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
class UninitializedPairNode : public PairNode {
|
||||
public:
|
||||
static UninitializedPairNode * UninitializedPairStaticNode();
|
||||
|
||||
size_t size() const override { return sizeof(UninitializedPairNode); }
|
||||
bool isUninitialized() const override { return true; }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
stream << "UninitializedPairNode";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
class PairByReference : public TreeByReference {
|
||||
public:
|
||||
PairByReference(TreeByReference t1, TreeByReference t2) : TreeByReference(TreePool::sharedPool()->createTreeNode<PairNode>()) {
|
||||
|
||||
Reference in New Issue
Block a user