From 7265c369d352c425fb17078719ee7f229ac9e4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 3 Sep 2019 15:39:45 +0200 Subject: [PATCH] [apps/graph] Replace magic number --- apps/graph/values/values_controller.cpp | 8 ++++---- apps/graph/values/values_controller.h | 2 +- apps/shared/cartesian_function.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 0a037f950..951ba53ca 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -56,7 +56,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in int ValuesController::typeAtLocation(int i, int j) { int plotTypeIndex = 0; - while (plotTypeIndex < 3 && i >= m_numberOfColumnsForType[plotTypeIndex]) { + while (plotTypeIndex < CartesianFunction::k_numberOfPlotTypes && i >= m_numberOfColumnsForType[plotTypeIndex]) { i -= m_numberOfColumnsForType[plotTypeIndex++]; } return Shared::ValuesController::typeAtLocation(i, j); @@ -77,7 +77,7 @@ Ion::Storage::Record ValuesController::recordAtColumn(int i) { Ion::Storage::Record ValuesController::recordAtColumn(int i, bool * isDerivative) { assert(typeAtLocation(i, 0) == k_functionTitleCellType); int plotTypeIndex = 0; - while (plotTypeIndex < 3 && i >= m_numberOfColumnsForType[plotTypeIndex]) { + while (plotTypeIndex < CartesianFunction::k_numberOfPlotTypes && i >= m_numberOfColumnsForType[plotTypeIndex]) { i -= m_numberOfColumnsForType[plotTypeIndex++]; } CartesianFunction::PlotType plotType = static_cast(plotTypeIndex); @@ -153,7 +153,7 @@ double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int colum } void ValuesController::updateNumberOfColumns() { - for (int plotTypeIndex = 0; plotTypeIndex < 3; plotTypeIndex++) { + for (int plotTypeIndex = 0; plotTypeIndex < CartesianFunction::k_numberOfPlotTypes; plotTypeIndex++) { m_numberOfColumnsForType[plotTypeIndex] = 0; } for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { @@ -163,7 +163,7 @@ void ValuesController::updateNumberOfColumns() { m_numberOfColumnsForType[plotTypeIndex] += numberOfColumnsForRecord(record); } m_numberOfColumns = 0; - for (int plotTypeIndex = 0; plotTypeIndex < 3; plotTypeIndex++) { + for (int plotTypeIndex = 0; plotTypeIndex < CartesianFunction::k_numberOfPlotTypes; plotTypeIndex++) { m_numberOfColumnsForType[plotTypeIndex] += (m_numberOfColumnsForType[plotTypeIndex] > 0); m_numberOfColumns += m_numberOfColumnsForType[plotTypeIndex]; } diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index 4c93e894d..14876da49 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -42,7 +42,7 @@ private: ViewController * functionParameterController() override; I18n::Message valuesParameterControllerPageTitle() const override; - int m_numberOfColumnsForType[3]; + int m_numberOfColumnsForType[Shared::CartesianFunction::k_numberOfPlotTypes]; Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; FunctionParameterController m_functionParameterController; diff --git a/apps/shared/cartesian_function.h b/apps/shared/cartesian_function.h index 553d1825a..be4c834b3 100644 --- a/apps/shared/cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -19,6 +19,7 @@ public: CodePoint symbol() const override; Poincare::Expression expressionReduced(Poincare::Context * context) const override; + static constexpr int k_numberOfPlotTypes = 3; enum class PlotType { Cartesian = 0, Polar = 1,