diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index 514562239..2cdc0ce09 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -1,6 +1,7 @@ #include "cartesian_function.h" #include "expression_model_store.h" #include "poincare_helpers.h" +#include #include #include #include @@ -123,15 +124,29 @@ void CartesianFunction::setPlotType(PlotType newPlotType) { if (newPlotType == currentPlotType) { return; } - /* Reset memoized layout. */ - Expression e = expressionClone(); + + recordData()->setPlotType(newPlotType); + + // Recompute the layouts m_model.tidy(); + + // Recompute the definition domain double tMin = newPlotType == PlotType::Cartesian ? -INFINITY : 0.0; double tMax = newPlotType == PlotType::Cartesian ? INFINITY : 2.0*M_PI; setTMin(tMin); setTMax(tMax); - recordData()->setPlotType(newPlotType); + + /* Recompute the unknowns. For instance, if the function was f(x) = xθ, it is + * stored as f(?) = ?θ. When switching to polar type, it should be stored as + * f(?) = ?? */ + constexpr int previousTextContentMaxSize = Constant::MaxSerializedExpressionSize; + char previousTextContent[previousTextContentMaxSize]; + m_model.text(this, previousTextContent, previousTextContentMaxSize, symbol()); + setContent(previousTextContent); + + // Handle parametric function switch if (currentPlotType == PlotType::Parametric) { + Expression e = expressionClone(); // Change [x(t) y(t)] to y(t) if (!e.isUninitialized() && e.type() == ExpressionNode::Type::Matrix @@ -146,6 +161,7 @@ void CartesianFunction::setPlotType(PlotType newPlotType) { } return; } else if (newPlotType == PlotType::Parametric) { + Expression e = expressionClone(); // Change y(t) to [t y(t)] Matrix newExpr = Matrix::Builder(); newExpr.addChildAtIndexInPlace(Symbol::Builder(UCodePointUnknownX), 0, 0); diff --git a/ion/include/ion/unicode/code_point.h b/ion/include/ion/unicode/code_point.h index 329aca844..52708cfed 100644 --- a/ion/include/ion/unicode/code_point.h +++ b/ion/include/ion/unicode/code_point.h @@ -18,8 +18,7 @@ private: static constexpr CodePoint UCodePointNull = 0x0; -/* 0x1 and 0x2 represent soh and stx. They are not used, so we can use them for - * another purpose */ +// 0x1 represents soh. It is not used, so we can use it for another purpose. static constexpr CodePoint UCodePointUnknownX = 0x1; static constexpr CodePoint UCodePointTabulation = 0x9;