From 25cd0d44f342692ba91d040ba7fad56ad347221a Mon Sep 17 00:00:00 2001 From: Joachim LF Date: Fri, 17 Jun 2022 13:09:45 +0200 Subject: [PATCH] [calculation/additional_outputs] Use input rather than output if possible, and open on tan --- apps/calculation/calculation.cpp | 7 +++++-- apps/calculation/calculation.h | 3 ++- apps/calculation/history_controller.cpp | 10 +++++----- poincare/include/poincare/expression.h | 2 +- poincare/src/expression.cpp | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index fb02fea6f..9c84f89c4 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -251,8 +251,11 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co * - > input: 2cos(2) - cos(2) * > output: cos(2) */ - if (input().isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit()) || o.isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit())) { - return AdditionalInformationType::Trigonometry; + if (i.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) { + return AdditionalInformationType::TrigonometryInput; + } + if (o.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) { + return AdditionalInformationType::TrigonometryOutput; } if (o.hasUnit()) { Expression unit; diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index 4c026cbc4..e607c5357 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -40,7 +40,8 @@ public: Integer, Rational, SecondDegree, - Trigonometry, + TrigonometryInput, + TrigonometryOutput, Unit, Matrix, Complex diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 9a8687309..24736d8a9 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -103,12 +103,12 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { vc = &m_complexController; } else if (additionalInfoType == Calculation::AdditionalInformationType::SecondDegree) { vc = &m_secondDegreeController; - } else if (additionalInfoType == Calculation::AdditionalInformationType::Trigonometry) { + } else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryInput) { vc = &m_trigonometryController; - // Find which of the input or output is the cosine/sine - ExpressionNode::Type t = e.type(); - e = t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine ? e : calculationAtIndex(focusRow)->input(); - } else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) { + e = calculationAtIndex(focusRow)->input(); + } else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryOutput) { + vc = &m_trigonometryController; + } else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) { vc = &m_integerController; } else if (additionalInfoType == Calculation::AdditionalInformationType::Rational) { vc = &m_rationalController; diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 4ac1ba707..784ef1b6d 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -159,7 +159,7 @@ public: bool isRationalOne() const; bool isRandom() const { return node()->isRandom(); } bool isParameteredExpression() const { return node()->isParameteredExpression(); } - bool isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; + bool isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; bool isBasedIntegerCappedBy(const char * integerString) const; bool isDivisionOfIntegers() const; bool hasDefinedComplexApproximation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 4c066e6c1..014fd2bef 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -260,9 +260,9 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex return !isMultivariablePolynomial; } -bool Expression::isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { +bool Expression::isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { ExpressionNode::Type t = type(); - if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine) { + if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine || t == ExpressionNode::Type::Tangent) { float r = childAtIndex(0).approximateToScalar(context, complexFormat, angleUnit); if (!std::isnan(r)) { return true;