From 908eaa4a438ba018b8f2bb1c5805744fccfa01d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 3 Sep 2019 09:56:05 +0200 Subject: [PATCH] [apps/shared] CartesianFunction: when changing the plot type, handle the case of uninitialized expression --- apps/shared/cartesian_function.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index 5fb0cc53e..cb82cfb4f 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -3,6 +3,8 @@ #include "poincare_helpers.h" #include #include +#include +#include #include #include #include @@ -122,7 +124,8 @@ void CartesianFunction::setPlotType(PlotType newPlotType) { recordData()->setPlotType(newPlotType); if (currentPlotType == PlotType::Parametric) { // Change [x(t) y(t)] to y(t) - if (e.type() == ExpressionNode::Type::Matrix + if (!e.isUninitialized() + && e.type() == ExpressionNode::Type::Matrix && static_cast(e).numberOfRows() == 2 && static_cast(e).numberOfColumns() == 1) { @@ -137,6 +140,8 @@ void CartesianFunction::setPlotType(PlotType newPlotType) { // Change y(t) to [t y(t)] Matrix newExpr = Matrix::Builder(); newExpr.addChildAtIndexInPlace(Symbol::Builder(UCodePointUnknownX), 0, 0); + // if y(t) was not uninitialized, insert [t 2t] to set an example + e = e.isUninitialized() ? Multiplication::Builder(Rational::Builder(2), Symbol::Builder(UCodePointUnknownX)) : e; newExpr.addChildAtIndexInPlace(e, newExpr.numberOfChildren(), newExpr.numberOfChildren()); newExpr.setDimensions(2, 1); setExpressionContent(newExpr);