From 538bb5e5d2538cbfe83f054344e09244f62b620a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 20 Sep 2019 14:30:36 +0200 Subject: [PATCH 1/2] [apps/graph] Do not take into account the sum/integral in XNT Otherwise, it is impossible to use theta inside a sum in a polar function Example: f(theta) = sum(n*theta,0,4) cannot be written --- apps/graph/app.h | 1 + apps/shared/text_field_delegate_app.cpp | 6 +++++- apps/shared/text_field_delegate_app.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/graph/app.h b/apps/graph/app.h index 7d8bcd854..e8679b037 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -42,6 +42,7 @@ public: Snapshot * snapshot() const { return static_cast(::App::snapshot()); } + bool XNTCanBeOverriden() const override { return false; } CodePoint XNT() override; NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override; CartesianFunctionStore * functionStore() override { return static_cast(Shared::FunctionApp::functionStore()); } diff --git a/apps/shared/text_field_delegate_app.cpp b/apps/shared/text_field_delegate_app.cpp index 16ffd32c3..1cd9e3a7a 100644 --- a/apps/shared/text_field_delegate_app.cpp +++ b/apps/shared/text_field_delegate_app.cpp @@ -68,7 +68,11 @@ bool TextFieldDelegateApp::fieldDidReceiveEvent(EditableField * field, Responder /* TODO decode here to encode again in handleEventWithText? */ constexpr int bufferSize = CodePoint::MaxCodePointCharLength+1; char buffer[bufferSize]; - size_t length = UTF8Decoder::CodePointToChars(field->XNTCodePoint(XNT()), buffer, bufferSize); + CodePoint xnt = XNT(); + if (XNTCanBeOverriden()) { + xnt = field->XNTCodePoint(xnt); + } + size_t length = UTF8Decoder::CodePointToChars(xnt, buffer, bufferSize); assert(length < bufferSize - 1); buffer[length] = 0; return field->handleEventWithText(buffer); diff --git a/apps/shared/text_field_delegate_app.h b/apps/shared/text_field_delegate_app.h index f59a9eba9..09cacc5d4 100644 --- a/apps/shared/text_field_delegate_app.h +++ b/apps/shared/text_field_delegate_app.h @@ -14,6 +14,7 @@ class TextFieldDelegateApp : public InputEventHandlerDelegateApp, public TextFie public: virtual ~TextFieldDelegateApp() = default; virtual Poincare::Context * localContext(); + virtual bool XNTCanBeOverriden() const { return true; } virtual CodePoint XNT() { return 'x'; } bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; virtual bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override; From 45b8c20059ed34f0eac1df7bdd2f672428b6d202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 20 Sep 2019 15:11:39 +0200 Subject: [PATCH 2/2] [poincare/layout] Fix XNT when cursor points outside of integrand Example: 3 sum(|4) and XNT event gives n n=1 3 |sum(4) and XNT event gives 0 n=1 --- poincare/include/poincare/integral_layout.h | 8 +++++--- poincare/include/poincare/layout_node.h | 4 ++-- poincare/include/poincare/sequence_layout.h | 8 +++++--- poincare/src/integral_layout.cpp | 4 ++++ poincare/src/sequence_layout.cpp | 3 +++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/poincare/include/poincare/integral_layout.h b/poincare/include/poincare/integral_layout.h index cbd03b1a0..188677460 100644 --- a/poincare/include/poincare/integral_layout.h +++ b/poincare/include/poincare/integral_layout.h @@ -25,7 +25,7 @@ public: void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); } - CodePoint XNTCodePoint() const override { return 'x'; } + CodePoint XNTCodePoint(int childIndex = -1) const override; // TreeNode size_t size() const override { return sizeof(IntegralLayoutNode); } @@ -42,6 +42,8 @@ protected: KDCoordinate computeBaseline() override; KDPoint positionOfChild(LayoutNode * child) override; private: + constexpr static int k_integrandLayoutIndex = 0; + constexpr static int k_differentialLayoutIndex = 1; constexpr static const KDFont * k_font = KDFont::LargeFont; constexpr static KDCoordinate k_boundHeightMargin = 8; constexpr static KDCoordinate k_boundWidthMargin = 5; @@ -50,8 +52,8 @@ private: constexpr static KDCoordinate k_integrandHeigthMargin = 2; constexpr static KDCoordinate k_lineThickness = 1; // int(f(x), x, a, b) - LayoutNode * integrandLayout() { return childAtIndex(0); } // f(x) - LayoutNode * differentialLayout() { return childAtIndex(1); } // dx + LayoutNode * integrandLayout() { return childAtIndex(k_integrandLayoutIndex); } // f(x) + LayoutNode * differentialLayout() { return childAtIndex(k_differentialLayoutIndex); } // dx LayoutNode * lowerBoundLayout() { return childAtIndex(2); } // a LayoutNode * upperBoundLayout() { return childAtIndex(3); } // b void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; diff --git a/poincare/include/poincare/layout_node.h b/poincare/include/poincare/layout_node.h index 3c82e2720..9075ede02 100644 --- a/poincare/include/poincare/layout_node.h +++ b/poincare/include/poincare/layout_node.h @@ -126,9 +126,9 @@ public: * is clearer with different names. */ virtual bool isEmpty() const { return false; } virtual bool hasUpperLeftIndex() const { return false; } - virtual CodePoint XNTCodePoint() const { + virtual CodePoint XNTCodePoint(int childIndex = -1) const { LayoutNode * p = parent(); - return p == nullptr ? UCodePointNull : p->XNTCodePoint(); + return p == nullptr ? UCodePointNull : p->XNTCodePoint(p->indexOfChild(this)); } virtual bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { return true; } diff --git a/poincare/include/poincare/sequence_layout.h b/poincare/include/poincare/sequence_layout.h index c301d120e..011cb8ea5 100644 --- a/poincare/include/poincare/sequence_layout.h +++ b/poincare/include/poincare/sequence_layout.h @@ -20,7 +20,7 @@ public: void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); } - CodePoint XNTCodePoint() const override { return 'n'; } + CodePoint XNTCodePoint(int childIndex = -1) const override; // TreeNode int numberOfChildren() const override { return 4; } @@ -39,12 +39,14 @@ protected: KDPoint positionOfChild(LayoutNode * child) override; int writeDerivedClassInBuffer(const char * operatorName, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const; - LayoutNode * argumentLayout() { return childAtIndex(0); } - LayoutNode * variableLayout() { return childAtIndex(1); } + LayoutNode * argumentLayout() { return childAtIndex(k_argumentLayoutIndex); } + LayoutNode * variableLayout() { return childAtIndex(k_variableLayoutIndex); } LayoutNode * lowerBoundLayout() { return childAtIndex(2); } LayoutNode * upperBoundLayout() { return childAtIndex(3); } void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; private: + static constexpr int k_argumentLayoutIndex = 0; + static constexpr int k_variableLayoutIndex = 1; KDCoordinate completeLowerBoundX(); KDCoordinate subscriptBaseline(); }; diff --git a/poincare/src/integral_layout.cpp b/poincare/src/integral_layout.cpp index 862b22ccd..8987329c4 100644 --- a/poincare/src/integral_layout.cpp +++ b/poincare/src/integral_layout.cpp @@ -205,6 +205,10 @@ int IntegralLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr return numberOfChar; } +CodePoint IntegralLayoutNode::XNTCodePoint(int childIndex) const { + return (childIndex == k_integrandLayoutIndex || childIndex == k_differentialLayoutIndex) ? CodePoint('x') : UCodePointNull; +} + KDSize IntegralLayoutNode::computeSize() { KDSize dSize = k_font->stringSize("d"); KDSize integrandSize = integrandLayout()->layoutSize(); diff --git a/poincare/src/sequence_layout.cpp b/poincare/src/sequence_layout.cpp index e754fb98a..ab9efca71 100644 --- a/poincare/src/sequence_layout.cpp +++ b/poincare/src/sequence_layout.cpp @@ -148,6 +148,9 @@ void SequenceLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { LayoutNode::deleteBeforeCursor(cursor); } +CodePoint SequenceLayoutNode::XNTCodePoint(int childIndex) const { + return (childIndex == k_argumentLayoutIndex || childIndex == k_variableLayoutIndex) ? CodePoint('n') : UCodePointNull; +} // Protected