diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 584691dc0..b1b95b951 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -65,10 +65,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in } int ValuesController::typeAtLocation(int i, int j) { - int plotTypeIndex = 0; - while (plotTypeIndex < CartesianFunction::k_numberOfPlotTypes && i >= m_numberOfColumnsForType[plotTypeIndex]) { - i -= m_numberOfColumnsForType[plotTypeIndex++]; - } + plotTypeAtColumn(&i); return Shared::ValuesController::typeAtLocation(i, j); } @@ -86,11 +83,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 < CartesianFunction::k_numberOfPlotTypes && i >= m_numberOfColumnsForType[plotTypeIndex]) { - i -= m_numberOfColumnsForType[plotTypeIndex++]; - } - CartesianFunction::PlotType plotType = static_cast(plotTypeIndex); + CartesianFunction::PlotType plotType = plotTypeAtColumn(&i); int index = 1; for (int k = 0; k < functionStore()->numberOfActiveFunctionsOfType(plotType); k++) { Ion::Storage::Record record = functionStore()->activeRecordOfTypeAtIndex(plotType, k); @@ -118,6 +111,15 @@ Shared::Interval * ValuesController::intervalAtColumn(int columnIndex) { return App::app()->interval(); } +CartesianFunction::PlotType ValuesController::plotTypeAtColumn(int * i) const { + int plotTypeIndex = 0; + while (plotTypeIndex < CartesianFunction::k_numberOfPlotTypes && *i >= m_numberOfColumnsForType[plotTypeIndex]) { + *i -= m_numberOfColumnsForType[plotTypeIndex++]; + } + assert(plotTypeIndex < CartesianFunction::k_numberOfPlotTypes); + return static_cast(plotTypeIndex); +} + int ValuesController::maxNumberOfCells() { return k_maxNumberOfCells; } diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index 2fe29afb8..6728f72da 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -38,6 +38,7 @@ private: Ion::Storage::Record recordAtColumn(int i, bool * isDerivative); int numberOfColumnsForRecord(Ion::Storage::Record record) const; Shared::Interval * intervalAtColumn(int columnIndex) override; + Shared::CartesianFunction::PlotType plotTypeAtColumn(int * i) const; int maxNumberOfCells() override; int maxNumberOfFunctions() override; double evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) override;