From ce09b44942cc0118c6f3f8a5068b41d46a03da31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 17 Nov 2016 15:27:24 +0100 Subject: [PATCH] [apps/graph/graph] create a class for the model axis interval Change-Id: I7da8441c282ba44e67855ea494c79ebb8c762a2f --- apps/constant.h | 1 - apps/graph/Makefile | 1 + apps/graph/graph/axis_interval.cpp | 92 ++++++++++++++++++++++++++++++ apps/graph/graph/axis_interval.h | 40 +++++++++++++ liba/include/float.h | 6 ++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 apps/graph/graph/axis_interval.cpp create mode 100644 apps/graph/graph/axis_interval.h create mode 100644 liba/include/float.h diff --git a/apps/constant.h b/apps/constant.h index cd0ee182e..f6f79bb36 100644 --- a/apps/constant.h +++ b/apps/constant.h @@ -6,7 +6,6 @@ public: constexpr static int FloatBufferSizeInScientificMode = 14; constexpr static int NumberOfDigitsInMantissaInScientificMode = 7; constexpr static int NumberOfDigitsInMantissaForDerivativeNumberInScientificMode = 3; - }; #endif diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 3060ae503..37033163c 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -5,6 +5,7 @@ app_objs += $(addprefix apps/graph/,\ function.o\ function_store.o\ function_title_cell.o\ + graph/axis_interval.o\ graph/cursor_view.o\ graph/graph_controller.o\ graph/graph_view.o\ diff --git a/apps/graph/graph/axis_interval.cpp b/apps/graph/graph/axis_interval.cpp new file mode 100644 index 000000000..8a292a85b --- /dev/null +++ b/apps/graph/graph/axis_interval.cpp @@ -0,0 +1,92 @@ +#include "axis_interval.h" +#include "../../constant.h" +#include +#include +#include +#include + +namespace Graph { + +AxisInterval::AxisInterval(FunctionStore * functionStore) : + m_xMin(-10.0f), + m_xMax(10.0f), + m_yMin(-10.0f), + m_yMax(10.0f), + m_yAuto(true), + m_functionStore(functionStore), + m_evaluateContext(nullptr) +{ +} + +float AxisInterval::xMin() { + return m_xMin; +} + +float AxisInterval::xMax() { + return m_xMax; +} + +float AxisInterval::yMin() { + return m_yMin; +} + +float AxisInterval::yMax() { + return m_yMax; +} + +bool AxisInterval::yAuto() { + return m_yAuto; +} + +void AxisInterval::setXMin(float xMin) { + m_xMin = xMin; + computeYaxes(); +} + +void AxisInterval::setXMax(float xMax) { + m_xMax = xMax; + computeYaxes(); +} + +void AxisInterval::setYMin(float yMin) { + m_yMin = yMin; +} + +void AxisInterval::setYMax(float yMax) { + m_yMax = yMax; +} + +void AxisInterval::setYAuto(bool yAuto) { + m_yAuto = yAuto; + computeYaxes(); +} + +void AxisInterval::computeYaxes() { + if (!m_yAuto) { + return; + } + if (m_functionStore->numberOfActiveFunctions() > 0) { + float min = FLT_MAX; + float max = -FLT_MAX; + float step = (m_xMax - m_xMin)/Ion::Display::Width; + for (int i=0; inumberOfActiveFunctions(); i++) { + Function * f = m_functionStore->activeFunctionAtIndex(i); + float y = 0.0f; + for (float x = m_xMin; x <= m_xMax; x += step) { + y = f->evaluateAtAbscissa(x, m_evaluateContext); + if (!isnan(y) && !isinf(y)) { + min = min < y ? min : y; + max = max > y ? max : y; + } + } + } + m_yMin = min; + m_yMax = max; + } +} + +void AxisInterval::setContext(Context * context) { + m_evaluateContext = (EvaluateContext *)context; +} + +} diff --git a/apps/graph/graph/axis_interval.h b/apps/graph/graph/axis_interval.h new file mode 100644 index 000000000..2f5cfea42 --- /dev/null +++ b/apps/graph/graph/axis_interval.h @@ -0,0 +1,40 @@ +#ifndef GRAPH_GRAPH_AXIS_INTERVAL_H +#define GRAPH_GRAPH_AXIS_INTERVAL_H + +#include "../function_store.h" +#include "../evaluate_context.h" + +namespace Graph { + +class AxisInterval { +public: + AxisInterval(FunctionStore * functionStore); + float xMin(); + float xMax(); + float yMin(); + float yMax(); + bool yAuto(); + void setXMin(float f); + void setXMax(float f); + void setYMin(float f); + void setYMax(float f); + void setYAuto(bool yAuto); + /* Need to be public to be called when a function is added to the function + * store. */ + void computeYaxes(); + void setContext(Context * context); +private: + float m_xMin; + float m_xMax; + float m_yMin; + float m_yMax; + bool m_yAuto; + //float xScale; + //float yScale; + FunctionStore * m_functionStore; + EvaluateContext * m_evaluateContext; +}; + +} + +#endif diff --git a/liba/include/float.h b/liba/include/float.h new file mode 100644 index 000000000..9b486b820 --- /dev/null +++ b/liba/include/float.h @@ -0,0 +1,6 @@ +#ifndef LIBA_FLOAT_H +#define LIBA_FLOAT_H + +#define FLT_MAX 1E+37 + +#endif