From 90befab6ce0d635130d43afba9443fc62a1e62bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 16 Nov 2018 16:39:29 +0100 Subject: [PATCH] [shared] Change name: StorageExpressionModel::expression --> expressionReduced --- apps/graph/graph/graph_controller.cpp | 2 +- apps/graph/graph/intersection_graph_controller.cpp | 2 +- apps/shared/storage_cartesian_function.cpp | 12 ++++++------ apps/shared/storage_expression_model.cpp | 5 +++-- apps/shared/storage_expression_model.h | 2 +- apps/shared/storage_function.cpp | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 0c2e5f3c4..605dea77f 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -42,7 +42,7 @@ float GraphController::interestingXRange() { TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); - float fRange = f->expression(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); + float fRange = f->expressionReduced(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange)) { characteristicRange = fRange > characteristicRange ? fRange : characteristicRange; } diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index c5d5cae8a..fb0a81e23 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -41,7 +41,7 @@ Poincare::Expression::Coordinate2D IntersectionGraphController::computeNewPointO for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(i); if (record != m_record) { - Poincare::Expression e = functionStore()->modelForRecord(record)->expression(context); + Poincare::Expression e = functionStore()->modelForRecord(record)->expressionReduced(context); Poincare::Expression::Coordinate2D intersection = functionStore()->modelForRecord(m_record)->nextIntersectionFrom(start, step, max, context, e); if ((std::isnan(result.abscissa) || std::fabs(intersection.abscissa-start) < std::fabs(result.abscissa-start)) && !std::isnan(intersection.abscissa)) { m_intersectedRecord = record; diff --git a/apps/shared/storage_cartesian_function.cpp b/apps/shared/storage_cartesian_function.cpp index 088930577..33a785ca3 100644 --- a/apps/shared/storage_cartesian_function.cpp +++ b/apps/shared/storage_cartesian_function.cpp @@ -85,7 +85,7 @@ void StorageCartesianFunction::setDisplayDerivative(bool display) { } double StorageCartesianFunction::approximateDerivative(double x, Poincare::Context * context) const { - Poincare::Derivative derivative = Poincare::Derivative::Builder(expression(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float(x)); // derivative takes ownership of Poincare::Float(x) and the clone of expression + Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float(x)); // derivative takes ownership of Poincare::Float(x) and the clone of expression /* TODO: when we approximate derivative, we might want to simplify the * derivative here. However, we might want to do it once for all x (to avoid * lagging in the derivative table. */ @@ -94,7 +94,7 @@ double StorageCartesianFunction::approximateDerivative(double x, Poincare::Conte double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const { // TODO: this does not work yet because integral does not understand UnknownX - Poincare::Integral integral = Poincare::Integral::Builder(expression(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float(start), Poincare::Float(end)); // Integral takes ownership of args + Poincare::Integral integral = Poincare::Integral::Builder(expressionReduced(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float(start), Poincare::Float(end)); // Integral takes ownership of args /* TODO: when we approximate integral, we might want to simplify the integral * here. However, we might want to do it once for all x (to avoid lagging in * the derivative table. */ @@ -103,22 +103,22 @@ double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poin Expression::Coordinate2D StorageCartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; - return expression(context).nextMinimum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); + return expressionReduced(context).nextMinimum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); } Expression::Coordinate2D StorageCartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; - return expression(context).nextMaximum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); + return expressionReduced(context).nextMaximum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); } double StorageCartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; - return expression(context).nextRoot(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); + return expressionReduced(context).nextRoot(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit()); } Expression::Coordinate2D StorageCartesianFunction::nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, Expression e) const { const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; - return expression(context).nextIntersection(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit(), e); + return expressionReduced(context).nextIntersection(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit(), e); } StorageCartesianFunction::CartesianFunctionRecordData * StorageCartesianFunction::recordData() const { diff --git a/apps/shared/storage_expression_model.cpp b/apps/shared/storage_expression_model.cpp index a4db02a7d..28a9a9c87 100644 --- a/apps/shared/storage_expression_model.cpp +++ b/apps/shared/storage_expression_model.cpp @@ -30,12 +30,12 @@ void StorageExpressionModel::text(char * buffer, size_t bufferSize) const { bool StorageExpressionModel::isCircularlyDefined(Poincare::Context * context) const { if (m_circular == -1) { - m_circular = Expression::ExpressionWithoutSymbols(expression(context), *context).isUninitialized(); + m_circular = Expression::ExpressionWithoutSymbols(expressionReduced(context), *context).isUninitialized(); } return m_circular; } -Expression StorageExpressionModel::expression(Poincare::Context * context) const { +Expression StorageExpressionModel::expressionReduced(Poincare::Context * context) const { if (m_expression.isUninitialized()) { assert(!isNull()); Ion::Storage::Record::Data recordData = value(); @@ -47,6 +47,7 @@ Expression StorageExpressionModel::expression(Poincare::Context * context) const Expression StorageExpressionModel::expressionWithSymbol() const { assert(!isNull()); Ion::Storage::Record::Data recordData = value(); + /* A new Expression has to be created at each call (because it might be tempered with after calling) */ return Expression::ExpressionFromAddress(expressionAddressForValue(recordData), expressionSizeForValue(recordData)); } diff --git a/apps/shared/storage_expression_model.h b/apps/shared/storage_expression_model.h index f85c203af..e647b84f2 100644 --- a/apps/shared/storage_expression_model.h +++ b/apps/shared/storage_expression_model.h @@ -15,7 +15,7 @@ class StorageExpressionModel : public Ion::Storage::Record { public: StorageExpressionModel(Ion::Storage::Record record); void text(char * buffer, size_t bufferSize) const; - Poincare::Expression expression(Poincare::Context * context) const; + Poincare::Expression expressionReduced(Poincare::Context * context) const; Poincare::Expression expressionWithSymbol() const; Poincare::Layout layout(); /* TODO This comment will be true when Sequence inherits from this class diff --git a/apps/shared/storage_function.cpp b/apps/shared/storage_function.cpp index f701cb434..4af8a475f 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/storage_function.cpp @@ -73,7 +73,7 @@ T StorageFunction::templatedApproximateAtAbscissa(T x, Poincare::Context * conte return NAN; } const char unknownX[2] = {Poincare::Symbol::UnknownX, 0}; - return expression(context).approximateWithValueForSymbol(unknownX, x, *context, Preferences::sharedPreferences()->angleUnit()); + return expressionReduced(context).approximateWithValueForSymbol(unknownX, x, *context, Preferences::sharedPreferences()->angleUnit()); } StorageFunction::FunctionRecordData * StorageFunction::recordData() const {