From 300d595c9dff440f75639db87fe41fbfac1ce314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 10 Oct 2016 17:39:33 +0200 Subject: [PATCH] [apps/graph/values] Create a class Interval Change-Id: Ie05a9887c0f3d4146b9e90a139f57e6eec7981b1 --- apps/graph/Makefile | 1 + apps/graph/values/interval.cpp | 22 ++++++++++++++++++++++ apps/graph/values/interval.h | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 apps/graph/values/interval.cpp create mode 100644 apps/graph/values/interval.h diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 263d855d7..f83315e96 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -12,6 +12,7 @@ app_objs += $(addprefix apps/graph/,\ list/list_controller.o\ list/parameter_controller.o\ values/float_to_string.o\ + values/interval.o\ values/title_cell.o\ values/value_cell.o\ values/values_controller.o\ diff --git a/apps/graph/values/interval.cpp b/apps/graph/values/interval.cpp new file mode 100644 index 000000000..e30b26650 --- /dev/null +++ b/apps/graph/values/interval.cpp @@ -0,0 +1,22 @@ +#include "interval.h" +#include + +Graph::Interval::Interval(float start, float end, float step) : + m_start(start), + m_end(end), + m_step(step) +{ +} + +int Graph::Interval::numberOfElements() { + if (m_start > m_end) { + return 0; + } else { + return 1 + (m_end - m_start)/m_step; + } +} + +float Graph::Interval::element(int i) { + assert(i >= 0 && i < numberOfElements()); + return m_start + i*m_step; +} \ No newline at end of file diff --git a/apps/graph/values/interval.h b/apps/graph/values/interval.h new file mode 100644 index 000000000..68d3a0c77 --- /dev/null +++ b/apps/graph/values/interval.h @@ -0,0 +1,20 @@ +#ifndef GRAPH_VALUES_INTERVAL_H +#define GRAPH_VALUES_INTERVAL_H + +namespace Graph { + +class Interval { +public: + Interval(float start, float end, float step); + + int numberOfElements(); + float element(int i); +private: + float m_start; + float m_end; + float m_step; +}; + +} + +#endif