diff --git a/apps/probability/law_curve_view.h b/apps/probability/law_curve_view.h index 3c6970aa6..b5b6217c7 100644 --- a/apps/probability/law_curve_view.h +++ b/apps/probability/law_curve_view.h @@ -18,7 +18,7 @@ public: protected: char * label(Axis axis, int index) const override; private: - char m_labels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_labels[k_maxNumberOfXLabels][k_labelBufferSize]; static float EvaluateAtAbscissa(float abscissa, void * model, void * context); Law * m_law; Calculation * m_calculation; diff --git a/apps/regression/graph_view.h b/apps/regression/graph_view.h index 511397fc6..c53f997b0 100644 --- a/apps/regression/graph_view.h +++ b/apps/regression/graph_view.h @@ -15,8 +15,8 @@ public: private: char * label(Axis axis, int index) const override; Store * m_store; - char m_xLabels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; - char m_yLabels[k_maxNumberOfYLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_xLabels[k_maxNumberOfXLabels][k_labelBufferSize]; + char m_yLabels[k_maxNumberOfYLabels][k_labelBufferSize]; Responder * m_controller; }; diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 563eeb13d..f539cd07d 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -131,18 +131,16 @@ float CurveView::floatToPixel(Axis axis, float f) const { } void CurveView::computeLabels(Axis axis) { - char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; float step = gridUnit(axis); for (int index = 0; index < numberOfLabels(axis); index++) { float labelValue = 2.0f*step*(std::ceil(min(axis)/(2.0f*step)))+index*2.0f*step; if (labelValue < step && labelValue > -step) { labelValue = 0.0f; } - PrintFloat::convertFloatToText(labelValue, buffer, - PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), + /* Label cannot hold more than k_labelBufferSize characters to prevent them + * from overprinting one another.*/ + PrintFloat::convertFloatToText(labelValue, label(axis, index), k_labelBufferSize, Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal); - //TODO: check for size of label? - strlcpy(label(axis, index), buffer, strlen(buffer)+1); } } diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index d92395614..8b741a902 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -41,6 +41,14 @@ protected: constexpr static KDCoordinate k_okVerticalMargin = 23; constexpr static KDCoordinate k_okHorizontalMargin = 10; constexpr static KDCoordinate k_labelGraduationLength = 6; + /* The labels are bounds by ±1E8 and ±1E-8 which in worse case can be written + * in 6 characters. + * To avoid overlapping labels, k_labelBufferSize should verify: + * k_labelBufferSize = Ion::Display::Width / ((CurveViewRange::k_maxNumberOfXGridUnits/2)*KDFont::SmallFont->glyphWidth) + * = 320/((18/2)*7) ~ 5. + * We take 6 creating small overlap in worse case but preventing from truncating + * labels (ie, "-1E-"). */ + constexpr static int k_labelBufferSize = 6; constexpr static int k_maxNumberOfXLabels = CurveViewRange::k_maxNumberOfXGridUnits; constexpr static int k_maxNumberOfYLabels = CurveViewRange::k_maxNumberOfYGridUnits; constexpr static int k_externRectMargin = 2; diff --git a/apps/shared/function_graph_view.h b/apps/shared/function_graph_view.h index d31f7c2a4..ebd780bd5 100644 --- a/apps/shared/function_graph_view.h +++ b/apps/shared/function_graph_view.h @@ -27,8 +27,8 @@ protected: bool m_shouldColorHighlighted; private: char * label(Axis axis, int index) const override; - char m_xLabels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; - char m_yLabels[k_maxNumberOfYLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_xLabels[k_maxNumberOfXLabels][k_labelBufferSize]; + char m_yLabels[k_maxNumberOfYLabels][k_labelBufferSize]; Poincare::Context * m_context; }; diff --git a/apps/shared/storage_function_graph_view.h b/apps/shared/storage_function_graph_view.h index 3c6e706be..40cc3e24e 100644 --- a/apps/shared/storage_function_graph_view.h +++ b/apps/shared/storage_function_graph_view.h @@ -27,8 +27,8 @@ protected: bool m_shouldColorHighlighted; private: char * label(Axis axis, int index) const override; - char m_xLabels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; - char m_yLabels[k_maxNumberOfYLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_xLabels[k_maxNumberOfXLabels][k_labelBufferSize]; + char m_yLabels[k_maxNumberOfYLabels][k_labelBufferSize]; Poincare::Context * m_context; }; diff --git a/apps/statistics/box_axis_view.h b/apps/statistics/box_axis_view.h index fc7d7cd0c..b22e0fc69 100644 --- a/apps/statistics/box_axis_view.h +++ b/apps/statistics/box_axis_view.h @@ -20,7 +20,7 @@ public: private: constexpr static KDCoordinate k_axisMargin = 3; char * label(Axis axis, int index) const override; - char m_labels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_labels[k_maxNumberOfXLabels][k_labelBufferSize]; BoxRange m_boxRange; }; diff --git a/apps/statistics/histogram_view.h b/apps/statistics/histogram_view.h index 67727c60c..1af1dad1f 100644 --- a/apps/statistics/histogram_view.h +++ b/apps/statistics/histogram_view.h @@ -24,7 +24,7 @@ private: char * label(Axis axis, int index) const override; HistogramController * m_controller; Store * m_store; - char m_labels[k_maxNumberOfXLabels][Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + char m_labels[k_maxNumberOfXLabels][k_labelBufferSize]; static float EvaluateHistogramAtAbscissa(float abscissa, void * model, void * context); float m_highlightedBarStart; float m_highlightedBarEnd;