From afb1d18d65af767cac392c9fa23e40f298e981b1 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Mon, 2 Mar 2020 18:00:19 +0100 Subject: [PATCH] [apps/shared/sum_graph_controller] Factor constexpr --- apps/shared/sum_graph_controller.cpp | 17 ++++++----------- apps/shared/sum_graph_controller.h | 2 ++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index 6f9797c97..ac5ce035e 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "poincare_helpers.h" #include @@ -178,10 +177,8 @@ void SumGraphController::LegendView::setLegendMessage(I18n::Message message, Ste } void SumGraphController::LegendView::setEditableZone(double d) { - constexpr int precision = Preferences::MediumNumberOfSignificantDigits; - constexpr int bufferSize = PrintFloat::charSizeForFloatsWithPrecision(precision); - char buffer[bufferSize]; - PoincareHelpers::ConvertFloatToTextWithDisplayMode(d, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal); + char buffer[k_valuesBufferSize]; + PoincareHelpers::ConvertFloatToTextWithDisplayMode(d, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal); m_editableZone.setText(buffer); } @@ -191,23 +188,21 @@ void SumGraphController::LegendView::setSumLayout(Step step, double start, doubl const CodePoint sigma[sigmaLength] = {' ', m_sumSymbol}; Poincare::Layout sumLayout = LayoutHelper::CodePointString(sigma, sigmaLength); if (step != Step::FirstParameter) { - constexpr int precision = Preferences::MediumNumberOfSignificantDigits; - constexpr int bufferSize = PrintFloat::charSizeForFloatsWithPrecision(precision); - char buffer[bufferSize]; + char buffer[k_valuesBufferSize]; Layout endLayout; if (step == Step::SecondParameter) { endLayout = EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, k_font, false); } else { - PoincareHelpers::ConvertFloatToTextWithDisplayMode(end, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal); + PoincareHelpers::ConvertFloatToTextWithDisplayMode(end, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal); endLayout = LayoutHelper::String(buffer, strlen(buffer), k_font); } - PoincareHelpers::ConvertFloatToTextWithDisplayMode(start, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal); + PoincareHelpers::ConvertFloatToTextWithDisplayMode(start, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal); sumLayout = CondensedSumLayout::Builder( sumLayout, LayoutHelper::String(buffer, strlen(buffer), k_font), endLayout); if (step == Step::Result) { - PoincareHelpers::ConvertFloatToText(result, buffer, bufferSize, precision); + PoincareHelpers::ConvertFloatToText(result, buffer, k_valuesBufferSize, k_valuesPrecision); sumLayout = HorizontalLayout::Builder( sumLayout, functionLayout, diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index 3119d9577..e876f23c8 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -58,6 +58,8 @@ private: void setSumLayout(Step step, double start, double end, double result, Poincare::Layout functionLayout); private: constexpr static size_t k_editableZoneBufferSize = Poincare::PrintFloat::k_maxFloatCharSize; + constexpr static int k_valuesPrecision = Poincare::Preferences::MediumNumberOfSignificantDigits; + constexpr static int k_valuesBufferSize = Poincare::PrintFloat::charSizeForFloatsWithPrecision(k_valuesPrecision); constexpr static KDCoordinate k_legendHeight = 35; constexpr static const KDFont * k_font = KDFont::SmallFont; static KDCoordinate editableZoneWidth() { return 12*k_font->glyphSize().width(); }